nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPackages,
4 buildRustCrate,
5 callPackage,
6 releaseTools,
7 runCommand,
8 runCommandCC,
9 stdenv,
10 symlinkJoin,
11 writeTextFile,
12 pkgsCross,
13}:
14
15let
16 mkCrate =
17 buildRustCrate: args:
18 let
19 p = {
20 crateName = "nixtestcrate";
21 version = "0.1.0";
22 authors = [ "Test <test@example.com>" ];
23 }
24 // args;
25 in
26 buildRustCrate p;
27 mkHostCrate = mkCrate buildRustCrate;
28
29 mkCargoToml =
30 {
31 name,
32 crateVersion ? "0.1.0",
33 path ? "Cargo.toml",
34 }:
35 mkFile path ''
36 [package]
37 name = ${builtins.toJSON name}
38 version = ${builtins.toJSON crateVersion}
39 '';
40
41 mkFile =
42 destination: text:
43 writeTextFile {
44 name = "src";
45 destination = "/${destination}";
46 inherit text;
47 };
48
49 mkBin =
50 name:
51 mkFile name ''
52 use std::env;
53 fn main() {
54 let name: String = env::args().nth(0).unwrap();
55 println!("executed {}", name);
56 }
57 '';
58
59 mkBinExtern =
60 name: extern:
61 mkFile name ''
62 extern crate ${extern};
63 fn main() {
64 assert_eq!(${extern}::test(), 23);
65 }
66 '';
67
68 mkTestFile =
69 name: functionName:
70 mkFile name ''
71 #[cfg(test)]
72 #[test]
73 fn ${functionName}() {
74 assert!(true);
75 }
76 '';
77 mkTestFileWithMain =
78 name: functionName:
79 mkFile name ''
80 #[cfg(test)]
81 #[test]
82 fn ${functionName}() {
83 assert!(true);
84 }
85
86 fn main() {}
87 '';
88
89 mkLib = name: mkFile name "pub fn test() -> i32 { return 23; }";
90
91 mkTest =
92 crateArgs:
93 let
94 crate = mkHostCrate (removeAttrs crateArgs [ "expectedTestOutput" ]);
95 hasTests = crateArgs.buildTests or false;
96 expectedTestOutputs = crateArgs.expectedTestOutputs or null;
97 binaries = map (v: lib.escapeShellArg v.name) (crateArgs.crateBin or [ ]);
98 isLib = crateArgs ? libName || crateArgs ? libPath;
99 crateName = crateArgs.crateName or "nixtestcrate";
100 libName = crateArgs.libName or crateName;
101
102 libTestBinary =
103 if !isLib then
104 null
105 else
106 mkHostCrate {
107 crateName = "run-test-${crateName}";
108 dependencies = [ crate ];
109 src = mkBinExtern "src/main.rs" libName;
110 };
111
112 in
113 assert expectedTestOutputs != null -> hasTests;
114 assert hasTests -> expectedTestOutputs != null;
115
116 runCommand "run-buildRustCrate-${crateName}-test"
117 {
118 nativeBuildInputs = [ crate ];
119 }
120 (
121 if !hasTests then
122 ''
123 ${lib.concatMapStringsSep "\n" (
124 binary:
125 # Can't actually run the binary when cross-compiling
126 (lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "type ") + binary
127 ) binaries}
128 ${lib.optionalString isLib ''
129 test -e ${crate}/lib/*.rlib || exit 1
130 ${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "test -x "} \
131 ${libTestBinary}/bin/run-test-${crateName}
132 ''}
133 touch $out
134 ''
135 else if stdenv.hostPlatform == stdenv.buildPlatform then
136 ''
137 for file in ${crate}/tests/*; do
138 $file 2>&1 >> $out
139 done
140 set -e
141 ${lib.concatMapStringsSep "\n" (
142 o: "grep '${o}' $out || { echo 'output \"${o}\" not found in:'; cat $out; exit 23; }"
143 ) expectedTestOutputs}
144 ''
145 else
146 ''
147 for file in ${crate}/tests/*; do
148 test -x "$file"
149 done
150 touch "$out"
151 ''
152 );
153
154 /*
155 Returns a derivation that asserts that the crate specified by `crateArgs`
156 has the specified files as output.
157
158 `name` is used as part of the derivation name that performs the checking.
159
160 `mkCrate` can be used to override the `mkCrate` call/implementation to use to
161 override the `buildRustCrate`, useful for cross compilation. Uses `mkHostCrate` by default.
162
163 `crateArgs` is passed to `mkCrate` to build the crate with `buildRustCrate`
164
165 `expectedFiles` contains a list of expected file paths in the output. E.g.
166 `[ "./bin/my_binary" ]`.
167
168 `output` specifies the name of the output to use. By default, the default
169 output is used but e.g. `output = "lib";` will cause the lib output
170 to be checked instead. You do not need to specify any directories.
171 */
172 assertOutputs =
173 {
174 name,
175 mkCrate ? mkHostCrate,
176 crateArgs,
177 expectedFiles,
178 output ? null,
179 }:
180 assert (builtins.isString name);
181 assert (builtins.isAttrs crateArgs);
182 assert (builtins.isList expectedFiles);
183
184 let
185 crate = mkCrate (removeAttrs crateArgs [ "expectedTestOutput" ]);
186 crateOutput = if output == null then crate else crate."${output}";
187 expectedFilesFile = writeTextFile {
188 name = "expected-files-${name}";
189 text =
190 let
191 sorted = builtins.sort (a: b: a < b) expectedFiles;
192 concatenated = builtins.concatStringsSep "\n" sorted;
193 in
194 "${concatenated}\n";
195 };
196 in
197 runCommand "assert-outputs-${name}"
198 {
199 }
200 (
201 ''
202 local actualFiles=$(mktemp)
203
204 cd "${crateOutput}"
205 find . -type f \
206 | sort \
207 ''
208 # sed out the hash because it differs per platform
209 + ''
210 | sed 's/-${crate.metadata}//g' \
211 > "$actualFiles"
212 diff -q ${expectedFilesFile} "$actualFiles" > /dev/null || {
213 echo -e "\033[0;1;31mERROR: Difference in expected output files in ${crateOutput} \033[0m" >&2
214 echo === Got:
215 sed -e 's/^/ /' $actualFiles
216 echo === Expected:
217 sed -e 's/^/ /' ${expectedFilesFile}
218 echo === Diff:
219 diff -u ${expectedFilesFile} $actualFiles |\
220 tail -n +3 |\
221 sed -e 's/^/ /'
222 exit 1
223 }
224 touch $out
225 ''
226 );
227
228in
229rec {
230
231 tests = lib.recurseIntoAttrs (
232 let
233 cases = rec {
234 libPath = {
235 libPath = "src/my_lib.rs";
236 src = mkLib "src/my_lib.rs";
237 };
238 srcLib = {
239 src = mkLib "src/lib.rs";
240 };
241
242 # This used to be supported by cargo but as of 1.40.0 I can't make it work like that with just cargo anymore.
243 # This might be a regression or deprecated thing they finally removed…
244 # customLibName = { libName = "test_lib"; src = mkLib "src/test_lib.rs"; };
245 # rustLibTestsCustomLibName = {
246 # libName = "test_lib";
247 # src = mkTestFile "src/test_lib.rs" "foo";
248 # buildTests = true;
249 # expectedTestOutputs = [ "test foo ... ok" ];
250 # };
251
252 customLibNameAndLibPath = {
253 libName = "test_lib";
254 libPath = "src/best-lib.rs";
255 src = mkLib "src/best-lib.rs";
256 };
257 crateBinWithPath = {
258 crateBin = [
259 {
260 name = "test_binary1";
261 path = "src/foobar.rs";
262 }
263 ];
264 src = mkBin "src/foobar.rs";
265 };
266 crateBinNoPath1 = {
267 crateBin = [ { name = "my-binary2"; } ];
268 src = mkBin "src/my_binary2.rs";
269 };
270 crateBinNoPath2 = {
271 crateBin = [
272 { name = "my-binary3"; }
273 { name = "my-binary4"; }
274 ];
275 src = symlinkJoin {
276 name = "buildRustCrateMultipleBinariesCase";
277 paths = [
278 (mkBin "src/bin/my_binary3.rs")
279 (mkBin "src/bin/my_binary4.rs")
280 ];
281 };
282 };
283 crateBinNoPath3 = {
284 crateBin = [ { name = "my-binary5"; } ];
285 src = mkBin "src/bin/main.rs";
286 };
287 crateBinNoPath4 = {
288 crateBin = [ { name = "my-binary6"; } ];
289 src = mkBin "src/main.rs";
290 };
291 crateBinRename1 = {
292 crateBin = [ { name = "my-binary-rename1"; } ];
293 src = mkBinExtern "src/main.rs" "foo_renamed";
294 dependencies = [
295 (mkHostCrate {
296 crateName = "foo";
297 src = mkLib "src/lib.rs";
298 })
299 ];
300 crateRenames = {
301 "foo" = "foo_renamed";
302 };
303 };
304 crateBinRename2 = {
305 crateBin = [ { name = "my-binary-rename2"; } ];
306 src = mkBinExtern "src/main.rs" "foo_renamed";
307 dependencies = [
308 (mkHostCrate {
309 crateName = "foo";
310 libName = "foolib";
311 src = mkLib "src/lib.rs";
312 })
313 ];
314 crateRenames = {
315 "foo" = "foo_renamed";
316 };
317 };
318 crateBinRenameMultiVersion =
319 let
320 crateWithVersion =
321 version:
322 mkHostCrate {
323 crateName = "my_lib";
324 inherit version;
325 src = mkFile "src/lib.rs" ''
326 pub const version: &str = "${version}";
327 '';
328 };
329 depCrate01 = crateWithVersion "0.1.2";
330 depCrate02 = crateWithVersion "0.2.1";
331 in
332 {
333 crateName = "my_bin";
334 src = symlinkJoin {
335 name = "my_bin_src";
336 paths = [
337 (mkFile "src/main.rs" ''
338 #[test]
339 fn my_lib_01() { assert_eq!(lib01::version, "0.1.2"); }
340
341 #[test]
342 fn my_lib_02() { assert_eq!(lib02::version, "0.2.1"); }
343
344 fn main() { }
345 '')
346 ];
347 };
348 dependencies = [
349 depCrate01
350 depCrate02
351 ];
352 crateRenames = {
353 "my_lib" = [
354 {
355 version = "0.1.2";
356 rename = "lib01";
357 }
358 {
359 version = "0.2.1";
360 rename = "lib02";
361 }
362 ];
363 };
364 buildTests = true;
365 expectedTestOutputs = [
366 "test my_lib_01 ... ok"
367 "test my_lib_02 ... ok"
368 ];
369 };
370 rustLibTestsDefault = {
371 src = mkTestFile "src/lib.rs" "baz";
372 buildTests = true;
373 expectedTestOutputs = [ "test baz ... ok" ];
374 };
375 rustLibTestsCustomLibPath = {
376 libPath = "src/test_path.rs";
377 src = mkTestFile "src/test_path.rs" "bar";
378 buildTests = true;
379 expectedTestOutputs = [ "test bar ... ok" ];
380 };
381 rustLibTestsCustomLibPathWithTests = {
382 libPath = "src/test_path.rs";
383 src = symlinkJoin {
384 name = "rust-lib-tests-custom-lib-path-with-tests-dir";
385 paths = [
386 (mkTestFile "src/test_path.rs" "bar")
387 (mkTestFile "tests/something.rs" "something")
388 ];
389 };
390 buildTests = true;
391 expectedTestOutputs = [
392 "test bar ... ok"
393 "test something ... ok"
394 ];
395 };
396 rustBinTestsCombined = {
397 src = symlinkJoin {
398 name = "rust-bin-tests-combined";
399 paths = [
400 (mkTestFileWithMain "src/main.rs" "src_main")
401 (mkTestFile "tests/foo.rs" "tests_foo")
402 (mkTestFile "tests/bar.rs" "tests_bar")
403 ];
404 };
405 buildTests = true;
406 expectedTestOutputs = [
407 "test src_main ... ok"
408 "test tests_foo ... ok"
409 "test tests_bar ... ok"
410 ];
411 };
412 rustBinTestsSubdirCombined = {
413 src = symlinkJoin {
414 name = "rust-bin-tests-subdir-combined";
415 paths = [
416 (mkTestFileWithMain "src/main.rs" "src_main")
417 (mkTestFile "tests/foo/main.rs" "tests_foo")
418 (mkTestFile "tests/bar/main.rs" "tests_bar")
419 ];
420 };
421 buildTests = true;
422 expectedTestOutputs = [
423 "test src_main ... ok"
424 "test tests_foo ... ok"
425 "test tests_bar ... ok"
426 ];
427 };
428 linkAgainstRlibCrate = {
429 crateName = "foo";
430 src = mkFile "src/main.rs" ''
431 extern crate somerlib;
432 fn main() {}
433 '';
434 dependencies = [
435 (mkHostCrate {
436 crateName = "somerlib";
437 type = [ "rlib" ];
438 src = mkLib "src/lib.rs";
439 })
440 ];
441 };
442 buildScriptDeps =
443 let
444 depCrate =
445 buildRustCrate: boolVal:
446 mkCrate buildRustCrate {
447 crateName = "bar";
448 src = mkFile "src/lib.rs" ''
449 pub const baz: bool = ${boolVal};
450 '';
451 };
452 in
453 {
454 crateName = "foo";
455 src = symlinkJoin {
456 name = "build-script-and-main";
457 paths = [
458 (mkFile "src/main.rs" ''
459 extern crate bar;
460 #[cfg(test)]
461 #[test]
462 fn baz_false() { assert!(!bar::baz); }
463 fn main() { }
464 '')
465 (mkFile "build.rs" ''
466 extern crate bar;
467 fn main() { assert!(bar::baz); }
468 '')
469 ];
470 };
471 buildDependencies = [ (depCrate buildPackages.buildRustCrate "true") ];
472 dependencies = [ (depCrate buildRustCrate "false") ];
473 buildTests = true;
474 expectedTestOutputs = [ "test baz_false ... ok" ];
475 };
476 buildScriptFeatureEnv = {
477 crateName = "build-script-feature-env";
478 features = [
479 "some-feature"
480 "crate/another_feature"
481 ];
482 src = symlinkJoin {
483 name = "build-script-feature-env";
484 paths = [
485 (mkFile "src/main.rs" ''
486 #[cfg(test)]
487 #[test]
488 fn feature_not_visible() {
489 assert!(std::env::var("CARGO_FEATURE_SOME_FEATURE").is_err());
490 assert!(option_env!("CARGO_FEATURE_SOME_FEATURE").is_none());
491 }
492 fn main() {}
493 '')
494 (mkFile "build.rs" ''
495 fn main() {
496 assert!(std::env::var("CARGO_FEATURE_SOME_FEATURE").is_ok());
497 assert!(option_env!("CARGO_FEATURE_SOME_FEATURE").is_none());
498 }
499 '')
500 ];
501 };
502 buildTests = true;
503 expectedTestOutputs = [ "test feature_not_visible ... ok" ];
504 };
505 # Regression test for https://github.com/NixOS/nixpkgs/pull/88054
506 # Build script output should be rewritten as valid env vars.
507 buildScriptIncludeDirDeps =
508 let
509 depCrate = mkHostCrate {
510 crateName = "bar";
511 src = symlinkJoin {
512 name = "build-script-and-include-dir-bar";
513 paths = [
514 (mkFile "src/lib.rs" ''
515 fn main() { }
516 '')
517 (mkFile "build.rs" ''
518 use std::path::PathBuf;
519 fn main() { println!("cargo:include-dir={}/src", std::env::current_dir().unwrap_or(PathBuf::from(".")).to_str().unwrap()); }
520 '')
521 ];
522 };
523 };
524 in
525 {
526 crateName = "foo";
527 src = symlinkJoin {
528 name = "build-script-and-include-dir-foo";
529 paths = [
530 (mkFile "src/main.rs" ''
531 fn main() { }
532 '')
533 (mkFile "build.rs" ''
534 fn main() { assert!(std::env::var_os("DEP_BAR_INCLUDE_DIR").is_some()); }
535 '')
536 ];
537 };
538 buildDependencies = [ depCrate ];
539 dependencies = [ depCrate ];
540 };
541 # Support new invocation prefix for build scripts `cargo::`
542 # https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
543 buildScriptInvocationPrefix =
544 let
545 depCrate =
546 buildRustCrate:
547 mkCrate buildRustCrate {
548 crateName = "bar";
549 src = mkFile "build.rs" ''
550 fn main() {
551 // Old invocation prefix
552 // We likely won't see be mixing these syntaxes in the same build script in the wild.
553 println!("cargo:key_old=value_old");
554
555 // New invocation prefix
556 println!("cargo::metadata=key=value");
557 println!("cargo::metadata=key_complex=complex(value)");
558 }
559 '';
560 };
561 in
562 {
563 crateName = "foo";
564 src = symlinkJoin {
565 name = "build-script-and-main-invocation-prefix";
566 paths = [
567 (mkFile "src/main.rs" ''
568 const BUILDFOO: &'static str = env!("BUILDFOO");
569
570 #[test]
571 fn build_foo_check() { assert!(BUILDFOO == "yes(check)"); }
572
573 fn main() { }
574 '')
575 (mkFile "build.rs" ''
576 use std::env;
577 fn main() {
578 assert!(env::var_os("DEP_BAR_KEY_OLD").expect("metadata key 'key_old' not set in dependency") == "value_old");
579 assert!(env::var_os("DEP_BAR_KEY").expect("metadata key 'key' not set in dependency") == "value");
580 assert!(env::var_os("DEP_BAR_KEY_COMPLEX").expect("metadata key 'key_complex' not set in dependency") == "complex(value)");
581
582 println!("cargo::rustc-env=BUILDFOO=yes(check)");
583 }
584 '')
585 ];
586 };
587 buildDependencies = [ (depCrate buildPackages.buildRustCrate) ];
588 dependencies = [ (depCrate buildRustCrate) ];
589 buildTests = true;
590 expectedTestOutputs = [ "test build_foo_check ... ok" ];
591 };
592 # Regression test for https://github.com/NixOS/nixpkgs/issues/74071
593 # Whenevever a build.rs file is generating files those should not be overlaid onto the actual source dir
594 buildRsOutDirOverlay = {
595 src = symlinkJoin {
596 name = "buildrs-out-dir-overlay";
597 paths = [
598 (mkLib "src/lib.rs")
599 (mkFile "build.rs" ''
600 use std::env;
601 use std::ffi::OsString;
602 use std::fs;
603 use std::path::Path;
604 fn main() {
605 let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR not set");
606 let out_file = Path::new(&out_dir).join("lib.rs");
607 fs::write(out_file, "invalid rust code!").expect("failed to write lib.rs");
608 }
609 '')
610 ];
611 };
612 };
613 # Regression test for https://github.com/NixOS/nixpkgs/pull/83379
614 # link flag order should be preserved
615 linkOrder = {
616 src = symlinkJoin {
617 name = "buildrs-out-dir-overlay";
618 paths = [
619 (mkFile "build.rs" ''
620 fn main() {
621 // in the other order, linkage will fail
622 println!("cargo:rustc-link-lib=b");
623 println!("cargo:rustc-link-lib=a");
624 }
625 '')
626 (mkFile "src/main.rs" ''
627 extern "C" {
628 fn hello_world();
629 }
630 fn main() {
631 unsafe {
632 hello_world();
633 }
634 }
635 '')
636 ];
637 };
638 buildInputs =
639 let
640 compile =
641 name: text:
642 let
643 src = writeTextFile {
644 name = "${name}-src.c";
645 inherit text;
646 };
647 in
648 runCommandCC name { } ''
649 mkdir -p $out/lib
650 # Note: On darwin (which defaults to clang) we have to add
651 # `-undefined dynamic_lookup` as otherwise the compilation fails.
652 $CC -shared \
653 ${lib.optionalString stdenv.hostPlatform.isDarwin "-undefined dynamic_lookup"} \
654 -o $out/lib/${name}${stdenv.hostPlatform.extensions.library} ${src}
655 '';
656 b = compile "libb" ''
657 #include <stdio.h>
658
659 void hello();
660
661 void hello_world() {
662 hello();
663 printf(" world!\n");
664 }
665 '';
666 a = compile "liba" ''
667 #include <stdio.h>
668
669 void hello() {
670 printf("hello");
671 }
672 '';
673 in
674 [
675 a
676 b
677 ];
678 };
679 rustCargoTomlInSubDir = {
680 # The "workspace_member" can be set to the sub directory with the crate to build.
681 # By default ".", meaning the top level directory is assumed.
682 # Using null will trigger a search.
683 workspace_member = null;
684 src = symlinkJoin {
685 name = "find-cargo-toml";
686 paths = [
687 (mkCargoToml { name = "ignoreMe"; })
688 (mkTestFileWithMain "src/main.rs" "ignore_main")
689
690 (mkCargoToml {
691 name = "rustCargoTomlInSubDir";
692 path = "subdir/Cargo.toml";
693 })
694 (mkTestFileWithMain "subdir/src/main.rs" "src_main")
695 (mkTestFile "subdir/tests/foo/main.rs" "tests_foo")
696 (mkTestFile "subdir/tests/bar/main.rs" "tests_bar")
697 ];
698 };
699 buildTests = true;
700 expectedTestOutputs = [
701 "test src_main ... ok"
702 "test tests_foo ... ok"
703 "test tests_bar ... ok"
704 ];
705 };
706
707 rustCargoTomlInTopDir =
708 let
709 withoutCargoTomlSearch = removeAttrs rustCargoTomlInSubDir [ "workspace_member" ];
710 in
711 withoutCargoTomlSearch
712 // {
713 expectedTestOutputs = [
714 "test ignore_main ... ok"
715 ];
716 };
717 procMacroInPrelude = {
718 procMacro = true;
719 edition = "2018";
720 src = symlinkJoin {
721 name = "proc-macro-in-prelude";
722 paths = [
723 (mkFile "src/lib.rs" ''
724 use proc_macro::TokenTree;
725 '')
726 ];
727 };
728 };
729 };
730 brotliCrates = (callPackage ./brotli-crates.nix { });
731 rcgenCrates = callPackage ./rcgen-crates.nix {
732 # Suppress deprecation warning
733 buildRustCrate = null;
734 };
735 tests = lib.mapAttrs (
736 key: value: mkTest (value // lib.optionalAttrs (!value ? crateName) { crateName = key; })
737 ) cases;
738 in
739 tests
740 // {
741
742 crateBinWithPathOutputs = assertOutputs {
743 name = "crateBinWithPath";
744 crateArgs = {
745 crateBin = [
746 {
747 name = "test_binary1";
748 path = "src/foobar.rs";
749 }
750 ];
751 src = mkBin "src/foobar.rs";
752 };
753 expectedFiles = [
754 "./bin/test_binary1"
755 ];
756 };
757
758 crateBinWithPathOutputsDebug = assertOutputs {
759 name = "crateBinWithPath";
760 crateArgs = {
761 release = false;
762 crateBin = [
763 {
764 name = "test_binary1";
765 path = "src/foobar.rs";
766 }
767 ];
768 src = mkBin "src/foobar.rs";
769 };
770 expectedFiles = [
771 "./bin/test_binary1"
772 ]
773 ++ lib.optionals stdenv.hostPlatform.isDarwin [
774 # On Darwin, the debug symbols are in a separate directory.
775 "./bin/test_binary1.dSYM/Contents/Info.plist"
776 "./bin/test_binary1.dSYM/Contents/Resources/DWARF/test_binary1"
777 "./bin/test_binary1.dSYM/Contents/Resources/Relocations/${stdenv.hostPlatform.rust.platform.arch}/test_binary1.yml"
778 ];
779 };
780
781 crateBinNoPath1Outputs = assertOutputs {
782 name = "crateBinNoPath1";
783 crateArgs = {
784 crateBin = [ { name = "my-binary2"; } ];
785 src = mkBin "src/my_binary2.rs";
786 };
787 expectedFiles = [
788 "./bin/my-binary2"
789 ];
790 };
791
792 crateLibOutputs = assertOutputs {
793 name = "crateLib";
794 output = "lib";
795 crateArgs = {
796 libName = "test_lib";
797 type = [ "rlib" ];
798 libPath = "src/lib.rs";
799 src = mkLib "src/lib.rs";
800 };
801 expectedFiles = [
802 "./nix-support/propagated-build-inputs"
803 "./lib/libtest_lib.rlib"
804 "./lib/link"
805 ];
806 };
807
808 crateLibOutputsDebug = assertOutputs {
809 name = "crateLib";
810 output = "lib";
811 crateArgs = {
812 release = false;
813 libName = "test_lib";
814 type = [ "rlib" ];
815 libPath = "src/lib.rs";
816 src = mkLib "src/lib.rs";
817 };
818 expectedFiles = [
819 "./nix-support/propagated-build-inputs"
820 "./lib/libtest_lib.rlib"
821 "./lib/link"
822 ];
823 };
824
825 crateLibOutputsWasm32 = assertOutputs {
826 name = "wasm32-crate-lib";
827 output = "lib";
828 mkCrate = mkCrate pkgsCross.wasm32-unknown-none.buildRustCrate;
829 crateArgs = {
830 libName = "test_lib";
831 type = [ "cdylib" ];
832 libPath = "src/lib.rs";
833 src = mkLib "src/lib.rs";
834 };
835 expectedFiles = [
836 "./nix-support/propagated-build-inputs"
837 "./lib/test_lib.wasm"
838 "./lib/link"
839 ];
840 };
841
842 crateWasm32BinHyphens = assertOutputs {
843 name = "wasm32-crate-bin-hyphens";
844 mkCrate = mkCrate pkgsCross.wasm32-unknown-none.buildRustCrate;
845 crateArgs = {
846 crateName = "wasm32-crate-bin-hyphens";
847 crateBin = [ { name = "wasm32-crate-bin-hyphens"; } ];
848 src = mkBin "src/main.rs";
849 };
850 expectedFiles = [
851 "./bin/wasm32-crate-bin-hyphens.wasm"
852 ];
853 };
854
855 brotliTest =
856 let
857 pkg = brotliCrates.brotli_2_5_0 { };
858 in
859 runCommand "run-brotli-test-cmd"
860 {
861 nativeBuildInputs = [ pkg ];
862 }
863 (
864 if stdenv.hostPlatform == stdenv.buildPlatform then
865 ''
866 ${pkg}/bin/brotli -c ${pkg}/bin/brotli > /dev/null && touch $out
867 ''
868 else
869 ''
870 test -x '${pkg}/bin/brotli' && touch $out
871 ''
872 );
873 allocNoStdLibTest =
874 let
875 pkg = brotliCrates.alloc_no_stdlib_1_3_0 { };
876 in
877 runCommand "run-alloc-no-stdlib-test-cmd"
878 {
879 nativeBuildInputs = [ pkg ];
880 }
881 ''
882 test -e ${pkg}/bin/example && touch $out
883 '';
884 brotliDecompressorTest =
885 let
886 pkg = brotliCrates.brotli_decompressor_1_3_1 { };
887 in
888 runCommand "run-brotli-decompressor-test-cmd"
889 {
890 nativeBuildInputs = [ pkg ];
891 }
892 ''
893 test -e ${pkg}/bin/brotli-decompressor && touch $out
894 '';
895
896 rcgenTest =
897 let
898 pkg = rcgenCrates.rootCrate.build;
899 in
900 runCommand "run-rcgen-test-cmd"
901 {
902 nativeBuildInputs = [ pkg ];
903 }
904 (
905 if stdenv.hostPlatform == stdenv.buildPlatform then
906 ''
907 ${pkg}/bin/rcgen && touch $out
908 ''
909 else
910 ''
911 test -x '${pkg}/bin/rcgen' && touch $out
912 ''
913 );
914 }
915 );
916 test = releaseTools.aggregate {
917 name = "buildRustCrate-tests";
918 meta = {
919 description = "Test cases for buildRustCrate";
920 maintainers = [ ];
921 };
922 constituents = builtins.attrValues (lib.filterAttrs (_: v: lib.isDerivation v) tests);
923 };
924}