From 1e9aeb9c61037ba844ed026030ac12a8e1b7e50b Mon Sep 17 00:00:00 2001 From: Olivier LDff Date: Mon, 13 Jan 2025 15:15:40 +0100 Subject: [PATCH 1/4] rerun: support web_viewer feature When web_viewer is compiled, the wasm webviewer first needs to be built If this doesn't exist, the build will fail. More information: https://github.com/rerun-io/rerun/issues/6028 The command is taken from https://github.com/rerun-io/rerun/blob/dd025f1384f9944d785d0fb75ca4ca1cd1792f17/pixi.toml#L198C72-L198C187 Note that cargoBuildFeatures reference what buildFeatures is set to in stdenv.mkDerivation, so that user can easily create an overlay to set cargoBuildFeatures to what he needs --- pkgs/by-name/re/rerun/package.nix | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/re/rerun/package.nix b/pkgs/by-name/re/rerun/package.nix index fccc14ce3ce3..7d44bbbdc4aa 100644 --- a/pkgs/by-name/re/rerun/package.nix +++ b/pkgs/by-name/re/rerun/package.nix @@ -3,14 +3,12 @@ stdenv, rustPlatform, fetchFromGitHub, - # nativeBuildInputs binaryen, lld, pkg-config, protobuf, rustfmt, - # buildInputs freetype, glib, @@ -19,9 +17,7 @@ openssl, vulkan-loader, wayland, - versionCheckHook, - # passthru nix-update-script, python3Packages, @@ -49,7 +45,28 @@ rustPlatform.buildRustPackage rec { cargoBuildFlags = [ "--package rerun-cli" ]; cargoTestFlags = [ "--package rerun-cli" ]; buildNoDefaultFeatures = true; - buildFeatures = [ "native_viewer" ]; + buildFeatures = [ + "native_viewer" + "web_viewer" + ]; + + # When web_viewer is compiled, the wasm webviewer first needs to be built + # If this doesn't exist, the build will fail. More information: https://github.com/rerun-io/rerun/issues/6028 + # The command is taken from https://github.com/rerun-io/rerun/blob/dd025f1384f9944d785d0fb75ca4ca1cd1792f17/pixi.toml#L198C72-L198C187 + # Note that cargoBuildFeatures reference what buildFeatures is set to in stdenv.mkDerivation, + # so that user can easily create an overlay to set cargoBuildFeatures to what he needs + configurePhase = '' + runHook preConfigure + + if [[ " $cargoBuildFeatures " == *" web_viewer "* ]]; then + echo "Building with web_viewer feature..." + cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --release -g + else + echo "web_viewer feature not enabled, skipping web viewer build." + fi + + runHook postConfigure + ''; nativeBuildInputs = [ (lib.getBin binaryen) # wasm-opt From da83b17f8bbb9ad80056ba3fca0e266d8682cf0f Mon Sep 17 00:00:00 2001 From: Olivier LDff Date: Fri, 24 Jan 2025 10:11:15 +0100 Subject: [PATCH 2/4] rerun: add nasm feature --- pkgs/by-name/re/rerun/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/re/rerun/package.nix b/pkgs/by-name/re/rerun/package.nix index 7d44bbbdc4aa..3fb91c67988f 100644 --- a/pkgs/by-name/re/rerun/package.nix +++ b/pkgs/by-name/re/rerun/package.nix @@ -9,6 +9,7 @@ pkg-config, protobuf, rustfmt, + nasm, # buildInputs freetype, glib, @@ -48,6 +49,7 @@ rustPlatform.buildRustPackage rec { buildFeatures = [ "native_viewer" "web_viewer" + "nasm" ]; # When web_viewer is compiled, the wasm webviewer first needs to be built @@ -77,6 +79,7 @@ rustPlatform.buildRustPackage rec { pkg-config protobuf rustfmt + nasm ]; buildInputs = [ From 4d0503e2af4219a0d5517462fcf15732d1cbc220 Mon Sep 17 00:00:00 2001 From: Olivier LDff Date: Fri, 24 Jan 2025 10:11:45 +0100 Subject: [PATCH 3/4] rerun: move wasm app build to `preBuild` hook instead of `configurePhase` --- pkgs/by-name/re/rerun/package.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkgs/by-name/re/rerun/package.nix b/pkgs/by-name/re/rerun/package.nix index 3fb91c67988f..8e1e95c61977 100644 --- a/pkgs/by-name/re/rerun/package.nix +++ b/pkgs/by-name/re/rerun/package.nix @@ -57,17 +57,13 @@ rustPlatform.buildRustPackage rec { # The command is taken from https://github.com/rerun-io/rerun/blob/dd025f1384f9944d785d0fb75ca4ca1cd1792f17/pixi.toml#L198C72-L198C187 # Note that cargoBuildFeatures reference what buildFeatures is set to in stdenv.mkDerivation, # so that user can easily create an overlay to set cargoBuildFeatures to what he needs - configurePhase = '' - runHook preConfigure - + preBuild = '' if [[ " $cargoBuildFeatures " == *" web_viewer "* ]]; then echo "Building with web_viewer feature..." cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --release -g else echo "web_viewer feature not enabled, skipping web viewer build." fi - - runHook postConfigure ''; nativeBuildInputs = [ From 29b2f8e32a919b314f737213517d3fb105cf784c Mon Sep 17 00:00:00 2001 From: Olivier LDff Date: Sun, 26 Jan 2025 11:12:29 +0100 Subject: [PATCH 4/4] rerun: overwritable buildWebViewerFeatures without `analytics` --- pkgs/by-name/re/rerun/package.nix | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/re/rerun/package.nix b/pkgs/by-name/re/rerun/package.nix index 8e1e95c61977..2933760a63dc 100644 --- a/pkgs/by-name/re/rerun/package.nix +++ b/pkgs/by-name/re/rerun/package.nix @@ -22,6 +22,15 @@ # passthru nix-update-script, python3Packages, + # Expose features to the user for the wasm web viewer build + # So he can easily override them + # We omit the "analytics" feature because it is opt-out and not opt-in. + # More information can be found in there README: + # https://raw.githubusercontent.com/rerun-io/rerun/5a9794990c4903c088ad77174e65eb2573162d97/crates/utils/re_analytics/README.md + buildWebViewerFeatures ? [ + "grpc" + "map_view" + ], }: rustPlatform.buildRustPackage rec { @@ -52,6 +61,9 @@ rustPlatform.buildRustPackage rec { "nasm" ]; + # Forward as a bash environment variable to the preBuild hook + inherit buildWebViewerFeatures; + # When web_viewer is compiled, the wasm webviewer first needs to be built # If this doesn't exist, the build will fail. More information: https://github.com/rerun-io/rerun/issues/6028 # The command is taken from https://github.com/rerun-io/rerun/blob/dd025f1384f9944d785d0fb75ca4ca1cd1792f17/pixi.toml#L198C72-L198C187 @@ -59,8 +71,18 @@ rustPlatform.buildRustPackage rec { # so that user can easily create an overlay to set cargoBuildFeatures to what he needs preBuild = '' if [[ " $cargoBuildFeatures " == *" web_viewer "* ]]; then - echo "Building with web_viewer feature..." - cargo run -p re_dev_tools -- build-web-viewer --no-default-features --features analytics,grpc,map_view --release -g + # transform the environment variable that is a space separated list into a comma separated list + buildWebViewerFeatures=$(echo $buildWebViewerFeatures | tr ' ' ',') + # Create the features option only if there are features to pass + buildWebViewerFeaturesCargoOption="" + if [[ ! -z "$buildWebViewerFeatures" ]]; then + buildWebViewerFeaturesCargoOption="--features $buildWebViewerFeatures" + echo "Features passed to the web viewer build: $buildWebViewerFeatures" + else + echo "No features will be passed to the web viewer build" + fi + echo "Building the wasm web viewer for rerun's web_viewer feature" + cargo run -p re_dev_tools -- build-web-viewer --no-default-features $buildWebViewerFeaturesCargoOption --release -g else echo "web_viewer feature not enabled, skipping web viewer build." fi