Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

ci(nix): split Rust unit-test deps from crate builds with crane (CUA-3134) (#6392)

Francesco Bonaccicb49620c7878
diff --git a/.github/workflows/ci-nix-linux.yml b/.github/workflows/ci-nix-linux.yml
index b79dcc24db..3935e5f289 100644
--- a/.github/workflows/ci-nix-linux.yml
+++ b/.github/workflows/ci-nix-linux.yml
@@ -83,19 +83,27 @@ jobs:
cua-driver-policy-rego
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ # nix-quick-install-action leaves /nix owned by the runner user, which
+ # the store cache below needs in order to restore into it.
- name: Install Nix
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
+ uses: nixbuild/nix-quick-install-action@9f63be77f412a248c9d9a65a4c82cf066cdf8f0c # v35
with:
- extra_nix_config: |
+ nix_conf: |
experimental-features = nix-command flakes
- # Shares built store paths between workflow runs through the GitHub
- # Actions cache. Pull requests read main's entries but write only to
- # their own ref scope, so they cannot poison main.
- - name: Cache Nix store paths
- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
+ # Restores and saves the whole Nix store as ONE GitHub Actions cache
+ # entry per lane. The key covers only what decides the dependency build
+ # (flake, lockfiles, manifests, nix expressions), so source edits hit the
+ # exact key and rebuild only the workspace crates. A lockfile change
+ # falls back to the newest entry of the same lane and rebuilds the delta.
+ # magic-nix-cache pushed every derivation separately (about 970 for the
+ # vendored crates alone), tripped GitHub's cache rate limit (HTTP 418)
+ # and then served nothing. Pull requests read main's entries and write
+ # only to their own ref scope, so they cannot poison main.
+ - name: Cache Nix store
+ uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7
with:
- use-flakehub: disabled
- diagnostic-endpoint: ""
+ primary-key: nix-${{ runner.os }}-${{ matrix.name }}-${{ hashFiles('flake.nix', 'flake.lock', 'nix/**', 'libs/cua-driver/rust/Cargo.lock', 'libs/cua-driver/rust/**/Cargo.toml', 'libs/cua/Cargo.toml', 'libs/cua/crates/cua-telemetry/Cargo.toml') }}
+ restore-prefixes-first-match: nix-${{ runner.os }}-${{ matrix.name }}-
- name: Build ${{ matrix.name }}
env:
ATTRIBUTES: ${{ matrix.attributes }}
diff --git a/flake.lock b/flake.lock
index ece13ab181..3af18b3278 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,20 @@
{
"nodes": {
+ "crane": {
+ "locked": {
+ "lastModified": 1793669695,
+ "narHash": "sha256-9EtV4I6Ohw0tjidL31TMOKHhW/QGVG8NuGiemzIaNCs=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "788369ed71ed9d84ef72cb056e4d920050d5b32c",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
"flake-utils": {
"inputs": {
"systems": "systems"
@@ -36,6 +51,7 @@
},
"root": {
"inputs": {
+ "crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
diff --git a/flake.nix b/flake.nix
index e92b61f9f3..8efad5d0ed 100644
--- a/flake.nix
+++ b/flake.nix
@@ -4,6 +4,7 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
flake-utils.url = "github:numtide/flake-utils";
+ crane.url = "github:ipetkov/crane";
};
outputs =
@@ -11,6 +12,7 @@
self,
nixpkgs,
flake-utils,
+ crane,
...
}:
flake-utils.lib.eachSystem
@@ -22,6 +24,7 @@
system:
let
pkgs = import nixpkgs { inherit system; };
+ craneLib = crane.mkLib pkgs;
# cua-driver builds inside libs/: its crates reach the shared
# cua-telemetry crate in the libs/cua workspace (which inherits that
@@ -172,7 +175,7 @@
cua-compositor-build = cuaCompositorPackage;
cua-driver-build = cuaDriverPackage;
cua-driver-linux-rust-unit = import ./nix/cua-driver/tests/rust-unit.nix {
- inherit pkgs;
+ inherit pkgs craneLib;
src = rustTestSrc;
sourceSubdir = "cua-driver/rust";
};
diff --git a/nix/cua-driver/tests/rust-unit.nix b/nix/cua-driver/tests/rust-unit.nix
index b41556a2dd..03e58e6c4d 100644
--- a/nix/cua-driver/tests/rust-unit.nix
+++ b/nix/cua-driver/tests/rust-unit.nix
@@ -3,77 +3,102 @@
# This is intentionally separate from package.nix: the shipped daemon package
# must remain display-independent, while this check validates the Rust source
# and testkit in Nix's reproducible build environment.
+#
+# Built with crane in two derivations. `cargoArtifacts` compiles only the
+# third-party dependencies from a dummy source tree that holds nothing but
+# Cargo.toml and Cargo.lock files, so its store path changes only when a
+# manifest or the lockfile changes. The test derivation then reuses those
+# artifacts and compiles just the workspace crates, so a source edit no longer
+# rebuilds every dependency.
{
pkgs,
+ craneLib,
src,
sourceSubdir ? null,
...
}:
let
+ manifestDir = if sourceSubdir == null then "." else sourceSubdir;
rustSrc = if sourceSubdir == null then src else "${src}/${sourceSubdir}";
pythonClosure = pkgs.closureInfo {
rootPaths = [ pkgs.python3 ];
};
-in
-pkgs.rustPlatform.buildRustPackage {
- pname = "cua-driver-rust-unit-tests";
- version = (pkgs.lib.importTOML "${rustSrc}/Cargo.toml").workspace.package.version;
- inherit src;
- cargoLock.lockFile = "${rustSrc}/Cargo.lock";
- postUnpack = pkgs.lib.optionalString (sourceSubdir != null) ''
- sourceRoot="$sourceRoot/${sourceSubdir}"
- '';
- cargoTestFlags = [
- "-p"
+ testPackages = [
"cua-driver"
- "-p"
"cua-driver-e2e"
- "-p"
"cua-driver-core"
- "-p"
"cua-driver-testkit"
- "-p"
"platform-linux"
- "--all-targets"
];
+ cargoArgs = "--manifest-path ${manifestDir}/Cargo.toml ${
+ pkgs.lib.concatMapStringsSep " " (p: "-p ${p}") testPackages
+ } --all-targets";
- nativeBuildInputs = with pkgs; [
- pkg-config
- rustPlatform.bindgenHook
- clang
- python3
- ];
- # Transport tests launch an isolated D-Bus session instead of using the host bus.
- nativeCheckInputs = [ pkgs.dbus pkgs.xorg.xorgserver ];
- CUA_TEST_PYTHON = "${pkgs.python3}/bin/python3";
- CUA_TEST_PYTHON_DYNAMIC_LINKER = pkgs.stdenv.cc.bintools.dynamicLinker;
- CUA_TEST_GLIBC_STATIC_LIB = "${pkgs.glibc.static}/lib";
- preCheck = ''
- export CUA_TEST_PYTHON_READ_ROOTS="$(paste -sd: ${pythonClosure}/store-paths)"
- '';
- buildInputs = with pkgs; [
- libx11
- libxi
- libxtst
- libxext
- pipewire
- libei
- # platform-linux resolves niri and libei text against the XKB keymap.
- libxkbcommon
- ];
+ commonArgs = {
+ pname = "cua-driver-rust-unit-tests";
+ version = (pkgs.lib.importTOML "${rustSrc}/Cargo.toml").workspace.package.version;
+ inherit src;
+ strictDeps = true;
+ # Test binaries here are never debugged; skipping debuginfo cuts compile
+ # and link time. Dependencies and workspace share the setting so the
+ # dependency artifacts stay reusable.
+ CARGO_PROFILE_DEV_DEBUG = "0";
+ cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = "${rustSrc}/Cargo.lock"; };
+ nativeBuildInputs = with pkgs; [
+ pkg-config
+ rustPlatform.bindgenHook
+ clang
+ python3
+ ];
+ buildInputs = with pkgs; [
+ libx11
+ libxi
+ libxtst
+ libxext
+ pipewire
+ libei
+ # platform-linux resolves niri and libei text against the XKB keymap.
+ libxkbcommon
+ ];
+ };
- # The check phase compiles every test target itself and installPhase only
- # touches $out, so the build phase's separate release build of the
- # workspace (about 15 minutes) produced nothing this check uses.
- dontBuild = true;
+ # Compile the test targets of every dependency once. `cargo test --no-run`
+ # uses the same dev profile and feature set as the test run below, so the
+ # artifacts it saves are exactly the ones the next derivation reuses.
+ cargoArtifacts = craneLib.buildDepsOnly (
+ commonArgs
+ // {
+ buildPhaseCargoCommand = "cargo test --no-run ${cargoArgs}";
+ # Compile only; crane's default check phase would rerun a release build.
+ doCheck = false;
+ }
+ );
+in
+craneLib.mkCargoDerivation (
+ commonArgs
+ // {
+ inherit cargoArtifacts;
+ pnameSuffix = "";
+ doInstallCargoArtifacts = false;
+ doCheck = false;
- # Focus unit tests launch private Xvfb servers. The ignored desktop
- # matrix is run by the manual Linux e2e workflow and is not hidden in Nix.
- doCheck = true;
+ # Transport tests launch an isolated D-Bus session instead of using the host bus.
+ nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
+ pkgs.dbus
+ pkgs.xorg.xorgserver
+ ];
+ CUA_TEST_PYTHON = "${pkgs.python3}/bin/python3";
+ CUA_TEST_PYTHON_DYNAMIC_LINKER = pkgs.stdenv.cc.bintools.dynamicLinker;
+ CUA_TEST_GLIBC_STATIC_LIB = "${pkgs.glibc.static}/lib";
+ preBuild = ''
+ export CUA_TEST_PYTHON_READ_ROOTS="$(paste -sd: ${pythonClosure}/store-paths)"
+ '';
- installPhase = ''
- touch $out
- '';
-}
+ # Focus unit tests launch private Xvfb servers. The ignored desktop
+ # matrix is run by the manual Linux e2e workflow and is not hidden in Nix.
+ buildPhaseCargoCommand = "cargo test ${cargoArgs}";
+ installPhaseCommand = "touch $out";
+ }
+)