feat(tvix): add CI targets for checking crate features powerset

Closes: https://b.tvl.fyi/issues/401

With this change all crate features (and their combinations) will be built and
tested in CI.

From now on, when adding/removing a Cargo feature for a crate,
you will want to add it to the features power set that gets tested in CI.
For each crate there's a default.nix with a `mkFeaturePowerset` invocation,
modify the list to include/remove the feature.
Note that you don't want to add "collection" features,
such as `fs` for tvix-[ca]store or `default`.

Change-Id: I966dde1413d057770787da3296cce9c1924570e0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11717
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Ilan Joselevich 2024-05-26 17:27:10 +03:00
parent c93849a3fc
commit 1b39d5868a
10 changed files with 112 additions and 47 deletions

View file

@ -104,6 +104,11 @@ Rust projects under `//tvix`, be sure to run
`mg run //tools:crate2nix-generate` in `//tvix` itself and commit the changes `mg run //tools:crate2nix-generate` in `//tvix` itself and commit the changes
to the generated `Cargo.nix` file. This only applies to the full TVL checkout. to the generated `Cargo.nix` file. This only applies to the full TVL checkout.
When adding/removing a Cargo feature for a crate, you will want to add it to the
features power set that gets tested in CI. For each crate there's a default.nix with a
`mkFeaturePowerset` invocation, modify the list to include/remove the feature.
Note that you don't want to add "collection" features, such as `fs` for tvix-[ca]store or `default`.
## License structure ## License structure
All code implemented for Tvix is licensed under the GPL-3.0, with the All code implemented for Tvix is licensed under the GPL-3.0, with the

View file

@ -1,5 +1,11 @@
{ depot, pkgs, ... }: { depot, lib, ... }:
depot.tvix.crates.workspaceMembers.tvix-build.build.override { (depot.tvix.crates.workspaceMembers.tvix-build.build.override {
runTests = true; runTests = true;
} }).overrideAttrs (old: rec {
meta.ci.targets = lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
passthru = depot.tvix.utils.mkFeaturePowerset {
inherit (old) crateName;
features = [ "tonic-reflection" ];
};
})

View file

@ -92,7 +92,7 @@ rstest_reuse = "0.6.0"
xattr = "1.3.1" xattr = "1.3.1"
[features] [features]
default = [] default = ["cloud"]
cloud = [ cloud = [
"dep:bigtable_rs", "dep:bigtable_rs",
"object_store/aws", "object_store/aws",

View file

@ -1,23 +1,28 @@
{ depot, pkgs, ... }: { depot, pkgs, lib, ... }:
(depot.tvix.crates.workspaceMembers.tvix-castore.build.override { (depot.tvix.crates.workspaceMembers.tvix-castore.build.override {
runTests = true; runTests = true;
testPreRun = '' testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt; export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt;
''; '';
}).overrideAttrs (old: rec {
# enable some optional features. meta.ci.targets = [ "integration-tests" ] ++ lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
features = [ "default" "cloud" ]; passthru = (depot.tvix.utils.mkFeaturePowerset {
}).overrideAttrs (_: { inherit (old) crateName;
meta.ci.targets = [ "integration-tests" ]; features = ([ "cloud" "fuse" "tonic-reflection" ]
passthru.integration-tests = depot.tvix.crates.workspaceMembers.tvix-castore.build.override { # virtiofs feature currently fails to build on Darwin
runTests = true; ++ lib.optional pkgs.stdenv.isLinux "virtiofs");
testPreRun = '' override.testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt; export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export PATH="$PATH:${pkgs.lib.makeBinPath [pkgs.cbtemulator pkgs.google-cloud-bigtable-tool]}"
''; '';
}) // {
# enable some optional features. integration-tests = depot.tvix.crates.workspaceMembers.${old.crateName}.build.override (old: {
features = [ "default" "cloud" "integration" ]; runTests = true;
testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt;
export PATH="$PATH:${pkgs.lib.makeBinPath [ pkgs.cbtemulator pkgs.google-cloud-bigtable-tool ]}"
'';
features = old.features ++ [ "integration" ];
});
}; };
}) })

View file

@ -293,4 +293,6 @@ in
"shell" "shell"
"rust-docs" "rust-docs"
]; ];
utils = import ./utils.nix { inherit lib depot; };
} }

View file

@ -1,9 +1,16 @@
# TODO: find a way to build the benchmarks via crate2nix # TODO: find a way to build the benchmarks via crate2nix
{ depot, pkgs, ... }: { depot, pkgs, lib, ... }:
depot.tvix.crates.workspaceMembers.tvix-eval.build.override { (depot.tvix.crates.workspaceMembers.tvix-eval.build.override {
runTests = true; runTests = true;
# Make C++ Nix available, to compare eval results against. # Make C++ Nix available, to compare eval results against.
testInputs = [ pkgs.nix ]; testInputs = [ pkgs.nix ];
} }).overrideAttrs (old: rec {
meta.ci.targets = lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
passthru = depot.tvix.utils.mkFeaturePowerset {
inherit (old) crateName;
features = [ "nix_tests" ];
override.testInputs = [ pkgs.nix ];
};
})

View file

@ -1,8 +1,17 @@
{ depot, pkgs, ... }: { depot, pkgs, lib, ... }:
(depot.tvix.crates.workspaceMembers.tvix-glue.build.override { (depot.tvix.crates.workspaceMembers.tvix-glue.build.override {
runTests = true; runTests = true;
testPreRun = '' testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt; export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt;
''; '';
}).overrideAttrs (old: rec {
meta.ci.targets = lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
passthru = depot.tvix.utils.mkFeaturePowerset {
inherit (old) crateName;
features = [ "nix_tests" ];
override.testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt;
'';
};
}) })

View file

@ -1,7 +1,11 @@
{ depot, ... }: { depot, lib, ... }:
depot.tvix.crates.workspaceMembers.nix-compat.build.override { (depot.tvix.crates.workspaceMembers.nix-compat.build.override {
runTests = true; runTests = true;
# make sure we also enable async here, so run the tests behind that feature flag. }).overrideAttrs (old: rec {
features = [ "default" "async" "wire" ]; meta.ci.targets = lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
} passthru = depot.tvix.utils.mkFeaturePowerset {
inherit (old) crateName;
features = [ "async" "wire" ];
};
})

View file

@ -1,4 +1,4 @@
{ depot, pkgs, ... }: { depot, pkgs, lib, ... }:
let let
mkImportCheck = p: expectedPath: { mkImportCheck = p: expectedPath: {
@ -22,31 +22,35 @@ let
}; };
in in
(depot.tvix.crates.workspaceMembers.tvix-store.build.override { (depot.tvix.crates.workspaceMembers.tvix-store.build.override (old: {
runTests = true; runTests = true;
testPreRun = '' testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
''; '';
features = old.features
# enable some optional features. # virtiofs feature currently fails to build on Darwin
features = [ "default" "cloud" ] ++ lib.optional pkgs.stdenv.isLinux "virtiofs";
# virtiofs feature currently fails to build on Darwin. })).overrideAttrs (old: rec {
++ pkgs.lib.optional pkgs.stdenv.isLinux "virtiofs"; meta.ci = {
}).overrideAttrs (_: { targets = [ "integration-tests" ] ++ lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru);
meta.ci.targets = [ "integration-tests" ]; extraSteps.import-docs = (mkImportCheck "tvix/store/docs" ./docs);
meta.ci.extraSteps = {
import-docs = (mkImportCheck "tvix/store/docs" ./docs);
}; };
passthru.integration-tests = depot.tvix.crates.workspaceMembers.tvix-store.build.override { passthru = (depot.tvix.utils.mkFeaturePowerset {
runTests = true; inherit (old) crateName;
testPreRun = '' features = ([ "cloud" "fuse" "otlp" "tonic-reflection" ]
# virtiofs feature currently fails to build on Darwin
++ lib.optional pkgs.stdenv.isLinux "virtiofs");
override.testPreRun = ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export PATH="$PATH:${pkgs.lib.makeBinPath [pkgs.cbtemulator pkgs.google-cloud-bigtable-tool]}"
''; '';
}) // {
# enable some optional features. integration-tests = depot.tvix.crates.workspaceMembers.${old.crateName}.build.override (old: {
features = [ "default" "cloud" "integration" ] runTests = true;
# virtiofs feature currently fails to build on Darwin. testPreRun = ''
++ pkgs.lib.optional pkgs.stdenv.isLinux "virtiofs"; export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt;
export PATH="$PATH:${pkgs.lib.makeBinPath [ pkgs.cbtemulator pkgs.google-cloud-bigtable-tool ]}"
'';
features = old.features ++ [ "integration" ];
});
}; };
}) })

23
tvix/utils.nix Normal file
View file

@ -0,0 +1,23 @@
{ lib, depot, ... }:
{
mkFeaturePowerset = { crateName, features, override ? { } }:
let
powerset = xs:
let
addElement = set: element:
set ++ map (e: [ element ] ++ e) set;
in
lib.foldl' addElement [ [ ] ] xs;
in
lib.listToAttrs (map
(featuresPowerset: {
name = if featuresPowerset != [ ] then "with-features-${lib.concatStringsSep "-" featuresPowerset}" else "no-features";
value = depot.tvix.crates.workspaceMembers.${crateName}.build.override (old: {
runTests = true;
features = featuresPowerset;
} // (if lib.isFunction override then override old else override)
);
})
(powerset features));
}