From 312f91c9034b368bdece8beab4f50005d58ffae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= Date: Tue, 3 Dec 2024 15:02:35 +0100 Subject: [PATCH] Fix web viewer feature flags (#8295) --- crates/build/re_dev_tools/src/build_web_viewer/lib.rs | 9 +++++++-- crates/build/re_dev_tools/src/build_web_viewer/mod.rs | 5 +++++ crates/viewer/re_viewer/Cargo.toml | 2 +- pixi.toml | 8 ++++---- rerun_js/web-viewer/build-wasm.mjs | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/build/re_dev_tools/src/build_web_viewer/lib.rs b/crates/build/re_dev_tools/src/build_web_viewer/lib.rs index 5014bb59fe01..3a0973bc56bc 100644 --- a/crates/build/re_dev_tools/src/build_web_viewer/lib.rs +++ b/crates/build/re_dev_tools/src/build_web_viewer/lib.rs @@ -74,6 +74,7 @@ pub fn build( debug_symbols: bool, target: Target, build_dir: &Utf8Path, + no_default_features: bool, features: &String, ) -> anyhow::Result<()> { std::env::set_current_dir(workspace_root())?; @@ -118,9 +119,13 @@ pub fn build( "--lib", "--target=wasm32-unknown-unknown", &format!("--target-dir={}", target_wasm_dir.as_str()), - "--no-default-features", - &format!("--features={features}"), ]); + if no_default_features { + cmd.arg("--no-default-features"); + } + if !features.is_empty() { + cmd.arg(&format!("--features={features}")); + } if profile == Profile::Release { cmd.arg("--release"); } diff --git a/crates/build/re_dev_tools/src/build_web_viewer/mod.rs b/crates/build/re_dev_tools/src/build_web_viewer/mod.rs index 1a1484c05e5f..614f09f04d2f 100644 --- a/crates/build/re_dev_tools/src/build_web_viewer/mod.rs +++ b/crates/build/re_dev_tools/src/build_web_viewer/mod.rs @@ -38,6 +38,10 @@ pub struct Args { /// comma-separated list of features to pass on to `re_viewer` #[argh(option, short = 'F', long = "features", default = "default_features()")] features: String, + + /// whether to exclude default features from `re_viewer` wasm build + #[argh(switch, long = "no-default-features")] + no_default_features: bool, } fn default_features() -> String { @@ -62,6 +66,7 @@ pub fn main(args: Args) -> anyhow::Result<()> { args.debug_symbols, args.target, &build_dir, + args.no_default_features, &args.features, ) } diff --git a/crates/viewer/re_viewer/Cargo.toml b/crates/viewer/re_viewer/Cargo.toml index c6783b229fb0..242e8d6a4c65 100644 --- a/crates/viewer/re_viewer/Cargo.toml +++ b/crates/viewer/re_viewer/Cargo.toml @@ -32,7 +32,7 @@ crate-type = ["cdylib", "rlib"] [features] -default = ["analytics"] +default = ["analytics", "map_view"] ## Enable telemetry using our analytics SDK. analytics = ["dep:re_analytics"] diff --git a/pixi.toml b/pixi.toml index 703dce9c25e3..93d423976d6e 100644 --- a/pixi.toml +++ b/pixi.toml @@ -175,13 +175,13 @@ rerun-web = { cmd = "cargo run --package rerun-cli --no-default-features --featu # # This installs the `wasm32-unknown-unknown` rust target if it's not already installed. # (this looks heavy but takes typically below 0.1s!) -rerun-build-web = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --features analytics,grpc --debug" +rerun-build-web = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --debug" # Compile the web-viewer wasm and the cli. # # This installs the `wasm32-unknown-unknown` rust target if it's not already installed. # (this looks heavy but takes typically below 0.1s!) -rerun-build-web-cli = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --features analytics,grpc --debug && cargo build --package rerun-cli --no-default-features --features web_viewer" +rerun-build-web-cli = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --debug && cargo build --package rerun-cli --no-default-features --features web_viewer" # Compile and run the web-viewer in release mode via rerun-cli. # @@ -189,7 +189,7 @@ rerun-build-web-cli = "rustup target add wasm32-unknown-unknown && cargo run -p # # This installs the `wasm32-unknown-unknown` rust target if it's not already installed. # (this looks heavy but takes typically below 0.1s!) -rerun-web-release = { cmd = "cargo run --package rerun-cli --no-default-features --features web_viewer --release -- --web-viewer", depends_on = [ +rerun-web-release = { cmd = "cargo run --package rerun-cli --no-default-features --features web_viewer,map_view,grpc --release -- --web-viewer", depends_on = [ "rerun-build-web-release", ] } @@ -197,7 +197,7 @@ rerun-web-release = { cmd = "cargo run --package rerun-cli --no-default-features # # This installs the `wasm32-unknown-unknown` rust target if it's not already installed. # (this looks heavy but takes typically below 0.1s!) -rerun-build-web-release = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --features analytics,grpc --release -g" +rerun-build-web-release = "rustup target add wasm32-unknown-unknown && cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --release -g" rs-check = { cmd = "rustup target add wasm32-unknown-unknown && python scripts/ci/rust_checks.py", depends_on = [ "rerun-build-web", # The checks require the web viewer wasm to be around. diff --git a/rerun_js/web-viewer/build-wasm.mjs b/rerun_js/web-viewer/build-wasm.mjs index 3e54e5020119..f82292d847f5 100644 --- a/rerun_js/web-viewer/build-wasm.mjs +++ b/rerun_js/web-viewer/build-wasm.mjs @@ -31,7 +31,8 @@ function buildWebViewer(mode) { "cargo run -p re_dev_tools -- build-web-viewer", modeFlags, "--target no-modules-base", - "--features grpc", + "--no-default-features", + "--features grpc,map_view", // no `analytics` "-o rerun_js/web-viewer", ].join(" "), );