tests.buildRustCrate: add crateLibOutputsWasm32

Added a cross compilation test for wasm32-unknown-unknown. This also
required using crate.metadata instead of using the regex to get rid of
the hash in the library filename. It also required adding a mkCrate
argument to assertOutputs so we can override the buildRustCrate used.
This commit is contained in:
Ilan Joselevich 2024-06-24 21:13:50 +03:00
parent cf5e2c2c9a
commit cc379b60f0
No known key found for this signature in database

View File

@ -8,6 +8,7 @@
, stdenv
, symlinkJoin
, writeTextFile
, pkgsCross
}:
let
@ -120,7 +121,10 @@ let
`name` is used as part of the derivation name that performs the checking.
`crateArgs` is passed to `mkHostCrate` to build the crate with `buildRustCrate`.
`mkCrate` can be used to override the `mkCrate` call/implementation to use to
override the `buildRustCrate`, useful for cross compilation. Uses `mkHostCrate` by default.
`crateArgs` is passed to `mkCrate` to build the crate with `buildRustCrate`
`expectedFiles` contains a list of expected file paths in the output. E.g.
`[ "./bin/my_binary" ]`.
@ -129,13 +133,13 @@ let
output is used but e.g. `output = "lib";` will cause the lib output
to be checked instead. You do not need to specify any directories.
*/
assertOutputs = { name, crateArgs, expectedFiles, output? null }:
assertOutputs = { name, mkCrate ? mkHostCrate, crateArgs, expectedFiles, output? null, }:
assert (builtins.isString name);
assert (builtins.isAttrs crateArgs);
assert (builtins.isList expectedFiles);
let
crate = mkHostCrate (builtins.removeAttrs crateArgs ["expectedTestOutput"]);
crate = mkCrate (builtins.removeAttrs crateArgs ["expectedTestOutput"]);
crateOutput = if output == null then crate else crate."${output}";
expectedFilesFile = writeTextFile {
name = "expected-files-${name}";
@ -155,7 +159,7 @@ let
''
# sed out the hash because it differs per platform
+ ''
| sed -E -e 's/-[0-9a-fA-F]{10}\.rlib/-HASH.rlib/g' \
| sed 's/-${crate.metadata}//g' \
> "$actualFiles"
diff -q ${expectedFilesFile} "$actualFiles" > /dev/null || {
echo -e "\033[0;1;31mERROR: Difference in expected output files in ${crateOutput} \033[0m" >&2
@ -604,7 +608,7 @@ let
};
expectedFiles = [
"./nix-support/propagated-build-inputs"
"./lib/libtest_lib-HASH.rlib"
"./lib/libtest_lib.rlib"
"./lib/link"
];
};
@ -621,7 +625,24 @@ let
};
expectedFiles = [
"./nix-support/propagated-build-inputs"
"./lib/libtest_lib-HASH.rlib"
"./lib/libtest_lib.rlib"
"./lib/link"
];
};
crateLibOutputsWasm32 = assertOutputs {
name = "wasm32-crate-lib";
output = "lib";
mkCrate = mkCrate pkgsCross.wasm32-unknown-none.buildRustCrate;
crateArgs = {
libName = "test_lib";
type = [ "cdylib" ];
libPath = "src/lib.rs";
src = mkLib "src/lib.rs";
};
expectedFiles = [
"./nix-support/propagated-build-inputs"
"./lib/test_lib.wasm"
"./lib/link"
];
};