tvl-depot/corp/tvixbolt/default.nix
Vincent Ambo 3aca3d3bba refactor(tvix): build Rust projects using crate2nix
Introduces granular dependency builds using crate2nix, bootstrapped
off the generated configuration from the newly introduced
workspace (see cl/7533).

This commit checks in the generated Cargo.nix file which can be
regenerated with a parameterless invocation of `crate2nix generate` in
`//tvix`. I tried generating this in IFD, but it turned out to be
harder than what seemed worthwhile for now.

In this setup, the various build targets for Rust projects end up
being attributes of the imported `Cargo.nix` file at the `tvix.crates`
attribute. These still lack configuration, however, which has been
fixed in the various `default.nix` files of individual projects.

Note that we (temporarily) lose the ability to build tvix-eval's
benchmarks in CI. I haven't figured out what magic incantation summons
them from the void again ...

The `eval-okay-readDir` tests from both test suites have been disabled
because they fail for unknown reasons when run in this new derivation.
Somebody will have to debug it!

Change-Id: I2014614ccb9c8951aedbd71df7966ca191a13695
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7538
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
2022-12-15 17:26:45 +00:00

74 lines
1.9 KiB
Nix

{ depot, lib, pkgs, ... }:
let
wasmRust = pkgs.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
cargoToml = with builtins; fromTOML (readFile ./Cargo.toml);
wasmBindgenMatch =
cargoToml.dependencies.wasm-bindgen == "= ${pkgs.wasm-bindgen-cli.version}";
assertWasmBindgen = assert (lib.assertMsg wasmBindgenMatch ''
Due to instability in the Rust WASM ecosystem, the trunk build
tool enforces that the Cargo-dependency version of `wasm-bindgen`
MUST match the version of the CLI supplied in the environment.
This can get out of sync when nixpkgs is updated. To resolve it,
wasm-bindgen must be bumped in the Cargo.toml file and cargo needs
to be run to resolve the dependencies.
Versions of `wasm-bindgen` in Cargo.toml:
Expected: '= ${pkgs.wasm-bindgen-cli.version}'
Actual: '${cargoToml.dependencies.wasm-bindgen}'
''); pkgs.wasm-bindgen-cli;
deps = [
pkgs.binaryen
pkgs.sass
pkgs.trunk
wasmRust
assertWasmBindgen
];
# Cargo.toml needs to be patched with the /nix/store source path of
# tvix-eval.
cargoTomlPatch = pkgs.writeText "tvix-eval-src.patch" ''
diff --git a/Cargo.toml b/Cargo.toml
index 75006bec18..6ca244bbb2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ rnix = "0.11.0"
wasm-bindgen = "= 0.2.83"
[dependencies.tvix-eval]
-path = "../../tvix/eval"
+path = "${depot.tvix.crates.workspaceMembers.tvix-eval.build.src}"
default-features = false
[dependencies.serde]
'';
in
pkgs.rustPlatform.buildRustPackage rec {
pname = "tvixbolt";
version = "canon";
src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
patches = [
cargoTomlPatch
];
buildPhase = ''
export PATH=${lib.makeBinPath deps}:$PATH
mkdir home
export HOME=$PWD/home
trunk build --release -d $out
'';
dontInstall = true;
}