nix: fix tests and reorganize flake outputs
Some checks failed
ci/woodpecker/pr/debug Pipeline failed
ci/woodpecker/push/debug Pipeline failed

This commit is contained in:
Alex 2025-02-02 19:52:41 +01:00
parent acc8d39fd6
commit 6ee5ab066a
5 changed files with 56 additions and 70 deletions

View file

@ -1,48 +1,28 @@
{ system ? builtins.currentSystem, git_version ? null, }: { system ? builtins.currentSystem, git_version ? "unknown", }:
with import ./nix/common.nix; with import ./nix/common.nix;
let let
pkgs = import pkgsSrc { }; pkgs = import nixpkgs { };
compile = import ./nix/compile.nix; compile = import ./nix/compile.nix;
build_debug_and_release = (target: { compileWith = args: compile ({
debug = (compile { inherit system git_version nixpkgs;
inherit system target git_version pkgsSrc cargo2nixOverlay; crane = flake.inputs.crane;
release = false; rust-overlay = flake.inputs.rust-overlay;
}).workspace.garage { compileMode = "build"; }; } // args);
release = (compile { build_release = target: (compile {
inherit system target git_version pkgsSrc cargo2nixOverlay; inherit target;
release = true; release = true;
}).workspace.garage { compileMode = "build"; }; }).garage;
});
test = (rustPkgs:
pkgs.symlinkJoin {
name = "garage-tests";
paths =
builtins.map (key: rustPkgs.workspace.${key} { compileMode = "test"; })
(builtins.attrNames rustPkgs.workspace);
});
in { in {
pkgs = { releasePackages = {
amd64 = build_debug_and_release "x86_64-unknown-linux-musl"; amd64 = build_release "x86_64-unknown-linux-musl";
i386 = build_debug_and_release "i686-unknown-linux-musl"; i386 = build_release "i686-unknown-linux-musl";
arm64 = build_debug_and_release "aarch64-unknown-linux-musl"; arm64 = build_release "aarch64-unknown-linux-musl";
arm = build_debug_and_release "armv6l-unknown-linux-musleabihf"; arm = build_release "armv6l-unknown-linux-musleabihf";
};
test = {
amd64 = test (compile {
inherit system git_version pkgsSrc cargo2nixOverlay;
target = "x86_64-unknown-linux-musl";
features = [
"garage/bundled-libs"
"garage/k2v"
"garage/lmdb"
"garage/sqlite"
];
});
}; };
flakePackages = flake.packages.${system};
} }

View file

@ -23,28 +23,27 @@
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in compileFor = target: release: (compile {
{
packages =
let
packageFor = target: release: (compile {
inherit system git_version target nixpkgs crane rust-overlay release; inherit system git_version target nixpkgs crane rust-overlay release;
}).garage; });
packageFor = target: release: (compileFor target release).garage;
in in
{ {
packages = {
# default = native release build # default = native release build
default = packageFor null true; default = packageFor null true;
# other = cross-compiled, statically-linked builds
# <arch> = cross-compiled, statically-linked release builds
amd64 = packageFor "x86_64-unknown-linux-musl" true; amd64 = packageFor "x86_64-unknown-linux-musl" true;
i386 = packageFor "i686-unknown-linux-musl" true; i386 = packageFor "i686-unknown-linux-musl" true;
arm64 = packageFor "aarch64-unknown-linux-musl" true; arm64 = packageFor "aarch64-unknown-linux-musl" true;
arm = packageFor "armv6l-unknown-linux-musl" true; arm = packageFor "armv6l-unknown-linux-musl" true;
# non-optimized packages
# dev = native dev build
dev = packageFor null false; dev = packageFor null false;
dev-amd64 = packageFor "x86_64-unknown-linux-musl" false;
dev-i386 = packageFor "i686-unknown-linux-musl" false; # test = cargo test
dev-arm64 = packageFor "aarch64-unknown-linux-musl" false; test = (compileFor null false).garage-test;
dev-arm = packageFor "armv6l-unknown-linux-musl" false;
}; };
# ---- developpment shell, for making native builds only ---- # ---- developpment shell, for making native builds only ----

View file

@ -10,9 +10,9 @@ let
flake = (import flake-compat { system = builtins.currentSystem; src = ../.; }); flake = (import flake-compat { system = builtins.currentSystem; src = ../.; });
in in
rec {
pkgsSrc = flake.defaultNix.inputs.nixpkgs; {
cargo2nix = flake.defaultNix.inputs.cargo2nix; flake = flake.defaultNix;
cargo2nixOverlay = cargo2nix.overlays.default; nixpkgs = flake.defaultNix.inputs.nixpkgs;
devShells = builtins.getAttr builtins.currentSystem flake.defaultNix.devShells; devShells = flake.defaultNix.devShells.${builtins.currentSystem};
} }

View file

@ -46,7 +46,7 @@ let
inherit (pkgs) lib stdenv; inherit (pkgs) lib stdenv;
toolchainFn = (p: p.rust-bin.stable."1.78.0".default.override { toolchainFn = (p: p.rust-bin.stable."1.78.0".default.override {
targets = lib.optional (target != null) [ rustTarget ]; targets = lib.optionals (target != null) [ rustTarget ];
extensions = [ extensions = [
"rust-src" "rust-src"
"rustfmt" "rustfmt"
@ -109,10 +109,10 @@ let
{ {
inherit src; inherit src;
pname = "garage"; pname = "garage";
version = git_version; version = "none";
strictDeps = true; strictDeps = true;
cargoExtraArgs = "--features ${featuresStr}"; cargoExtraArgs = "--locked --features ${featuresStr}";
nativeBuildInputs = with pkgs; ([ nativeBuildInputs = with pkgs; ([
pkg-config pkg-config
@ -123,8 +123,6 @@ let
mold mold
]); ]);
GIT_VERSION = git_version;
CARGO_PROFILE = if release then "release" else "dev"; CARGO_PROFILE = if release then "release" else "dev";
CARGO_BUILD_RUSTFLAGS = CARGO_BUILD_RUSTFLAGS =
lib.concatStringsSep lib.concatStringsSep
@ -161,11 +159,20 @@ in rec {
garage = craneLib.buildPackage (commonArgs // { garage = craneLib.buildPackage (commonArgs // {
cargoArtifacts = garage-deps; cargoArtifacts = garage-deps;
doCheck = false; doCheck = false;
version = git_version;
GIT_VERSION = git_version;
});
garage-test-deps = craneLib.buildDepsOnly (commonArgs // {
pname = "garage-test";
cargoArtifacts = garage;
cargoExtraArgs = "${commonArgs.cargoExtraArgs} --tests --workspace";
CARGO_PROFILE = "test";
}); });
garage-test = craneLib.cargoTest (commonArgs // { garage-test = craneLib.cargoTest (commonArgs // {
cargoTestExtraArgs = "--workspace"; cargoTestExtraArgs = "--workspace";
cargoArtifacts = garage; cargoArtifacts = garage-test-deps;
CARGO_PROFILE = "test"; CARGO_PROFILE = "test";
}); });
} }

View file

@ -3,7 +3,7 @@
with import ./nix/common.nix; with import ./nix/common.nix;
let let
pkgs = import pkgsSrc { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
winscp = (import ./nix/winscp.nix) pkgs; winscp = (import ./nix/winscp.nix) pkgs;