buildDepsOnly builds the dependencies of the host and the tests once (keyed only on Cargo.toml/Cargo.lock); packages.default and checks.tests reuse them, so a change to our crates no longer recompiles every crate. checks.package builds the binary the host loop runs.
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||
crane.url = "github:ipetkov/crane";
|
||||
};
|
||||
|
||||
outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
|
||||
outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }:
|
||||
flake-utils.lib.eachSystem flake-utils.lib.allSystems (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
@@ -20,13 +21,28 @@
|
||||
targets = [ "wasm32-wasip2" ];
|
||||
extensions = [ "rust-src" ];
|
||||
};
|
||||
rustPlatform = pkgs.makeRustPlatform { cargo = rust; rustc = rust; };
|
||||
sausage = rustPlatform.buildRustPackage {
|
||||
# Crane builds the dependencies once (`cargoArtifacts`, keyed only on
|
||||
# Cargo.toml/Cargo.lock), so a change to our own crates rebuilds
|
||||
# just them.
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
|
||||
common = {
|
||||
pname = "sausage";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
cargoBuildFlags = [ "-p" "sausage" ];
|
||||
};
|
||||
# The test packages for `checks.tests`.
|
||||
testPackages = "-p sausage -p sausage-actor -p agent";
|
||||
cargoArtifacts = craneLib.buildDepsOnly (common // {
|
||||
doCheck = false;
|
||||
# The dependencies of the host binary and of the tests.
|
||||
buildPhaseCargoCommand = ''
|
||||
cargoWithProfile build --locked -p sausage
|
||||
cargoWithProfile test --locked --no-run ${testPackages}
|
||||
'';
|
||||
});
|
||||
sausage = craneLib.buildPackage (common // {
|
||||
inherit cargoArtifacts;
|
||||
cargoExtraArgs = "--locked -p sausage";
|
||||
doCheck = false;
|
||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||
# The `cargo` actor runs cargo at runtime. Build scripts need a C linker.
|
||||
@@ -34,7 +50,7 @@
|
||||
wrapProgram $out/bin/sausage --prefix PATH : ${pkgs.lib.makeBinPath [ rust pkgs.stdenv.cc ]}
|
||||
'';
|
||||
meta.mainProgram = "sausage";
|
||||
};
|
||||
});
|
||||
# `nix run .#loop -- <world>` runs the newest `sausage run <world>`
|
||||
# (without a folder: bare `sausage`, i.e. ./world, created if needed)
|
||||
# from the public repo, again and again: after a crash or a broker
|
||||
@@ -62,10 +78,12 @@
|
||||
# `nix flake check` runs every test of the host, the SDK, and the
|
||||
# agent. The tests build WASM actors with cargo, offline, from the
|
||||
# vendored crates of Cargo.lock.
|
||||
checks.tests = sausage.overrideAttrs (old: {
|
||||
pname = "sausage-tests";
|
||||
doCheck = true;
|
||||
cargoTestFlags = [ "-p" "sausage" "-p" "sausage-actor" "-p" "agent" ];
|
||||
# The binary the host loop runs (`nix run`), built from the same
|
||||
# cached dependencies as the tests.
|
||||
checks.package = sausage;
|
||||
checks.tests = craneLib.cargoTest (common // {
|
||||
inherit cargoArtifacts;
|
||||
cargoExtraArgs = "--locked ${testPackages}";
|
||||
preCheck = ''
|
||||
# Its own lock file pins crates that the vendored set may lack.
|
||||
rm -f cli/tests/actors/toolbox/Cargo.lock
|
||||
|
||||
Reference in New Issue
Block a user