Skip to content

Commit

Permalink
feat(cli): add feature to disable downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Jan 1, 2025
1 parent c2952a7 commit bcde22f
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 651 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
- name: Build all flake outputs
run: om ci
- name: Ensure devShell has all build deps
run: nix develop -c cargo build -p dioxus-cli
run: nix develop -c cargo build -p dioxus-cli --features no-downloads

playwright:
if: github.event.pull_request.draft == false
Expand Down
27 changes: 26 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ reqwest = { workspace = true, features = [
tower = { workspace = true }
once_cell = "1.19.0"

# path lookup
which = { version = "7.0.1", optional = true }

# plugin packages
open = "5.0.1"
cargo-generate = "=0.21.3"
Expand Down Expand Up @@ -128,6 +131,7 @@ default = []
plugin = []
tokio-console = ["dep:console-subscriber"]
bundle = []
no-downloads = ["dep:which"]

# when releasing dioxus, we want to enable wasm-opt
# and then also maybe developing it too.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/build/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::templates::InfoPlistData;
use crate::wasm_bindgen::WasmBindgenBuilder;
use crate::tools::wasm_bindgen::WasmBindgenBuilder;
use crate::{BuildRequest, Platform};
use crate::{Result, TraceSrc};
use anyhow::Context;
Expand Down
47 changes: 26 additions & 21 deletions packages/cli/src/build/verify.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{wasm_bindgen::WasmBindgen, BuildRequest, Platform, Result, RustupShow};
use crate::{
tools::wasm_bindgen::WasmBindgen, BuildRequest, Error, Platform, Result, RustcDetails,
};
use anyhow::{anyhow, Context};
use tokio::process::Command;

impl BuildRequest {
/// Install any tooling that might be required for this build.
/// Check for tooling that might be required for this build.
///
/// This should generally be only called on the first build since it takes time to verify the tooling
/// is in place, and we don't want to slow down subsequent builds.
Expand All @@ -15,7 +16,7 @@ impl BuildRequest {
.initialize_profiles()
.context("Failed to initialize profiles - dioxus can't build without them. You might need to initialize them yourself.")?;

let rustup = match RustupShow::from_cli().await {
let rustc = match RustcDetails::from_cli().await {
Ok(out) => out,
Err(err) => {
tracing::error!("Failed to verify tooling: {err}\ndx will proceed, but you might run into errors later.");
Expand All @@ -24,10 +25,10 @@ impl BuildRequest {
};

match self.build.platform() {
Platform::Web => self.verify_web_tooling(rustup).await?,
Platform::Ios => self.verify_ios_tooling(rustup).await?,
Platform::Android => self.verify_android_tooling(rustup).await?,
Platform::Linux => self.verify_linux_tooling(rustup).await?,
Platform::Web => self.verify_web_tooling(rustc).await?,
Platform::Ios => self.verify_ios_tooling(rustc).await?,
Platform::Android => self.verify_android_tooling(rustc).await?,
Platform::Linux => self.verify_linux_tooling(rustc).await?,
Platform::MacOS => {}
Platform::Windows => {}
Platform::Server => {}
Expand All @@ -37,29 +38,33 @@ impl BuildRequest {
Ok(())
}

pub(crate) async fn verify_web_tooling(&self, rustup: RustupShow) -> Result<()> {
// Rust wasm32 target
if !rustup.has_wasm32_unknown_unknown() {
pub(crate) async fn verify_web_tooling(&self, rustc: RustcDetails) -> Result<()> {
// Install target using rustup.
#[cfg(not(feature = "no-downloads"))]
if !rustc.has_wasm32_unknown_unknown() {
tracing::info!(
"Web platform requires wasm32-unknown-unknown to be installed. Installing..."
);
let _ = Command::new("rustup")

let _ = tokio::process::Command::new("rustup")
.args(["target", "add", "wasm32-unknown-unknown"])
.output()
.await?;
}

// Ensure target is installed.
if !rustc.has_wasm32_unknown_unknown() {
return Err(Error::Other(anyhow!(
"Missing target wasm32-unknown-unknown."
)));
}

// Wasm bindgen
let krate_bindgen_version = self.krate.wasm_bindgen_version().ok_or(anyhow!(
"failed to detect wasm-bindgen version, unable to proceed"
))?;

let is_installed = WasmBindgen::verify_install(&krate_bindgen_version).await?;
if !is_installed {
WasmBindgen::install(&krate_bindgen_version)
.await
.context("failed to install wasm-bindgen-cli")?;
}
WasmBindgen::verify_install(&krate_bindgen_version).await?;

Ok(())
}
Expand All @@ -71,7 +76,7 @@ impl BuildRequest {
/// We don't auto-install these yet since we're not doing an architecture check. We assume most users
/// are running on an Apple Silicon Mac, but it would be confusing if we installed these when we actually
/// should be installing the x86 versions.
pub(crate) async fn verify_ios_tooling(&self, _rustup: RustupShow) -> Result<()> {
pub(crate) async fn verify_ios_tooling(&self, _rustc: RustcDetails) -> Result<()> {
// open the simulator
// _ = tokio::process::Command::new("open")
// .arg("/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app")
Expand Down Expand Up @@ -112,7 +117,7 @@ impl BuildRequest {
///
/// will do its best to fill in the missing bits by exploring the sdk structure
/// IE will attempt to use the Java installed from android studio if possible.
pub(crate) async fn verify_android_tooling(&self, _rustup: RustupShow) -> Result<()> {
pub(crate) async fn verify_android_tooling(&self, _rustc: RustcDetails) -> Result<()> {
let result = self
.krate
.android_ndk()
Expand All @@ -134,7 +139,7 @@ impl BuildRequest {
///
/// Eventually, we want to check for the prereqs for wry/tao as outlined by tauri:
/// https://tauri.app/start/prerequisites/
pub(crate) async fn verify_linux_tooling(&self, _rustup: RustupShow) -> Result<()> {
pub(crate) async fn verify_linux_tooling(&self, _rustc: RustcDetails) -> Result<()> {
Ok(())
}
}
6 changes: 3 additions & 3 deletions packages/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ mod filemap;
mod logging;
mod metadata;
mod platform;
mod rustup;
mod rustc;
mod serve;
mod settings;
mod wasm_bindgen;
mod tools;

pub(crate) use build::*;
pub(crate) use cli::*;
Expand All @@ -29,7 +29,7 @@ pub(crate) use error::*;
pub(crate) use filemap::*;
pub(crate) use logging::*;
pub(crate) use platform::*;
pub(crate) use rustup::*;
pub(crate) use rustc::*;
pub(crate) use settings::*;

#[tokio::main]
Expand Down
31 changes: 31 additions & 0 deletions packages/cli/src/rustc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::Result;
use anyhow::Context;
use std::path::PathBuf;
use tokio::process::Command;

#[derive(Debug, Default)]
pub struct RustcDetails {
pub sysroot: PathBuf,
}

impl RustcDetails {
/// Find the current sysroot location using the CLI
pub async fn from_cli() -> Result<RustcDetails> {
let output = Command::new("rustc")
.args(["--print", "sysroot"])
.output()
.await?;

let stdout =
String::from_utf8(output.stdout).context("Failed to extract rustc sysroot output")?;

let sysroot = PathBuf::from(stdout.trim());
Ok(Self { sysroot })
}

pub fn has_wasm32_unknown_unknown(&self) -> bool {
self.sysroot
.join("lib/rustlib/wasm32-unknown-unknown")
.exists()
}
}
Loading

0 comments on commit bcde22f

Please sign in to comment.