diff --git a/flake.nix b/flake.nix index 05ade3d349c..a8dcd9ab5e4 100644 --- a/flake.nix +++ b/flake.nix @@ -30,20 +30,11 @@ # Note that `self.rev` is not set for builds with a dirty worktree, in which case we instead use `self.dirtyRev`. gitCommit = if (self ? rev) then self.rev else self.dirtyRev; - librusty_v8 = if pkgs.stdenv.isDarwin then - # Building on MacOS, we've seen errors building rusty_v8 with a local RUSTY_V8_ARCHIVE: - # https://github.com/clockworklabs/SpacetimeDB/pull/3422#issuecomment-3416972711 . - # For now, error on MacOS (darwin) targets. - builtins.abort '' - This flake doesn't work on MacOS due to some quirk of compiling rusty-v8 against a precompiled V8 archive. - If you can get a build working on MacOS under Nix, please submit a PR to https://github.com/clockworklabs/SpacetimeDB/pulls. - See https://github.com/clockworklabs/SpacetimeDB/pull/3422 for more details. - '' - # We fetch a precompiled v8 binary. - # The rusty_v8 build.rs normally tries to download v8 artifacts during compilation, - # but the Nix build sandbox doesn't give it network access. - # Instead, download the archive in a Nix-friendly way with a recorded sha. - else (pkgs.callPackage ./librusty_v8.nix {}); + # We fetch a precompiled v8 binary. + # The rusty_v8 build.rs normally tries to download v8 artifacts during compilation, + # but the Nix build sandbox doesn't give it network access. + # Instead, download the archive in a Nix-friendly way with a recorded sha. + librusty_v8 = pkgs.callPackage ./librusty_v8.nix {}; # The Rust toolchain that we actually build with. rustStable = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; @@ -85,6 +76,34 @@ # Include our precompiled V8. RUSTY_V8_ARCHIVE = librusty_v8; SPACETIMEDB_NIX_BUILD_GIT_COMMIT = gitCommit; + + # Workaround for https://github.com/clockworklabs/SpacetimeDB/issues/3882 + # (fixed for CI in https://github.com/clockworklabs/SpacetimeDB/pull/3921). + # The v8 crate's build.rs writes `librusty_v8.a` to + # `$CARGO_TARGET_DIR//gn_out/obj/`, which is outside the + # directories cargo and crane treat as authoritative artifacts. + # Mixed cargo invocations on the same target dir — including crane's + # buildDepsOnly -> buildPackage handoff — can leave that file missing + # while cargo still believes v8 is up to date, producing + # "could not find native static library `rusty_v8`" at link time. + # If the v8 build directory exists (so v8 has been built before) but + # the static lib is gone, clean and rebuild just the v8 crate. + preBuild = '' + for profile in release debug; do + target_dir="''${CARGO_TARGET_DIR:-target}" + lib="$target_dir/$profile/gn_out/obj/librusty_v8.a" + if compgen -G "$target_dir/$profile/build/v8-*" > /dev/null \ + && [ ! -f "$lib" ]; then + echo "librusty_v8.a missing at $lib; cleaning and rebuilding v8." + cargo clean -p v8 || true + if [ "$profile" = release ]; then + cargo build --release -p v8 + else + cargo build -p v8 + fi + fi + done + ''; }; # Build a separate derivation containing our dependencies, diff --git a/librusty_v8.nix b/librusty_v8.nix index 094e37ad6ba..8286f18b46f 100644 --- a/librusty_v8.nix +++ b/librusty_v8.nix @@ -30,6 +30,6 @@ in # copy the detected sha256 from the error message in here, then re-run. aarch64-linux = "0000000000000000000000000000000000000000000000000000"; x86_64-darwin = "0000000000000000000000000000000000000000000000000000"; - aarch64-darwin = "0000000000000000000000000000000000000000000000000000"; + aarch64-darwin = "sha256-yHa1eydVCrfYGgrZANbzgmmf25p7ui1VMas2A7BhG6k="; }; }