Skip to content

Commit

Permalink
feat(cli): add feature to disable downloads (#3465)
Browse files Browse the repository at this point in the history
* feat(cli): add feature to disable downloads

---------

Co-authored-by: Jonathan Kelley <[email protected]>
  • Loading branch information
CathalMullan and jkelleyrtp authored Jan 17, 2025
1 parent cd121f2 commit c7951b7
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 409 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" }

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

# when releasing dioxus, we want to enable wasm-opt
# and then also maybe developing it too.
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/build/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::prerender::pre_render_static_routes;
use super::templates::InfoPlistData;
use crate::wasm_bindgen::WasmBindgenBuilder;
use crate::wasm_bindgen::WasmBindgen;
use crate::{BuildRequest, Platform};
use crate::{Result, TraceSrc};
use anyhow::Context;
Expand Down Expand Up @@ -616,7 +616,7 @@ impl AppBundle {
.wasm_bindgen_version()
.expect("this should have been checked by tool verification");

WasmBindgenBuilder::new(bindgen_version)
WasmBindgen::new(&bindgen_version)
.input_path(&input_path)
.target("web")
.debug(keep_debug)
Expand All @@ -626,7 +626,6 @@ impl AppBundle {
.remove_producers_section(!keep_debug)
.out_name(&name)
.out_dir(&bindgen_outdir)
.build()
.run()
.await
.context("Failed to generate wasm-bindgen bindings")?;
Expand Down
45 changes: 24 additions & 21 deletions packages/cli/src/build/verify.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{wasm_bindgen::WasmBindgen, BuildRequest, Platform, Result, RustupShow};
use crate::{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 +14,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 +23,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 +36,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 +74,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 +115,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 +137,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(())
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/dioxus_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) struct DioxusCrate {
pub(crate) package: NodeId,
pub(crate) config: DioxusConfig,
pub(crate) target: Target,
pub(crate) settings: CliSettings,
pub(crate) settings: Arc<CliSettings>,
}

pub(crate) static PROFILE_WASM: &str = "wasm-dev";
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod filemap;
mod logging;
mod metadata;
mod platform;
mod rustup;
mod rustc;
mod serve;
mod settings;
mod wasm_bindgen;
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 c7951b7

Please sign in to comment.