From 29a8575e3d5cad041e58643a58d6b1c79079b8e5 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Thu, 16 Jan 2020 12:51:47 +0100 Subject: [PATCH 1/2] buildRustCrate: remove one of the odd library filename cases It used to be the case (ref missing) that cargo did treat `src/$libName.rs` as an alternative to `src/lib.rs` when the latter wasn't present. Recently I failed to reproduce that with vanilla cargo and it started to cause pain with some crates of the form: some_crate/ `- src `- main.rs `- some_crate.rs We would build `src/some_crate.rs` and thing it is a library while that might not be the actual case. This crate is a valid `bin` crate not a `lib` crate as far as I can tell from the samples I took. I removed support for the previously required heuristic and commented out the test cases in case we will need them again. We could crawl in the Git history but chances are that the next person looking into this doesn't know about the history. --- .../rust/build-rust-crate/build-crate.nix | 3 --- .../rust/build-rust-crate/test/default.nix | 18 +++++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index 4e2e2af1aa77..dec49d24f524 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -55,9 +55,6 @@ elif [[ -e src/lib.rs ]]; then build_lib src/lib.rs ${lib.optionalString buildTests "build_lib_test src/lib.rs"} - elif [[ -e "src/$LIB_NAME.rs" ]]; then - build_lib src/$LIB_NAME.rs - ${lib.optionalString buildTests ''build_lib_test "src/$LIB_NAME.rs"''} fi diff --git a/pkgs/build-support/rust/build-rust-crate/test/default.nix b/pkgs/build-support/rust/build-rust-crate/test/default.nix index f0f1ed4d1ebf..aa20bd03b189 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -92,7 +92,17 @@ let cases = { libPath = { libPath = "src/my_lib.rs"; src = mkLib "src/my_lib.rs"; }; srcLib = { src = mkLib "src/lib.rs"; }; - customLibName = { libName = "test_lib"; src = mkLib "src/test_lib.rs"; }; + + # 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. + # This might be a regression or deprecated thing they finally removed… + # customLibName = { libName = "test_lib"; src = mkLib "src/test_lib.rs"; }; + # rustLibTestsCustomLibName = { + # libName = "test_lib"; + # src = mkTestFile "src/test_lib.rs" "foo"; + # buildTests = true; + # expectedTestOutputs = [ "test foo ... ok" ]; + # }; + customLibNameAndLibPath = { libName = "test_lib"; libPath = "src/best-lib.rs"; src = mkLib "src/best-lib.rs"; }; crateBinWithPath = { crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; src = mkBin "src/foobar.rs"; }; crateBinNoPath1 = { crateBin = [{ name = "my-binary2"; }]; src = mkBin "src/my_binary2.rs"; }; @@ -122,12 +132,6 @@ let buildTests = true; expectedTestOutputs = [ "test baz ... ok" ]; }; - rustLibTestsCustomLibName = { - libName = "test_lib"; - src = mkTestFile "src/test_lib.rs" "foo"; - buildTests = true; - expectedTestOutputs = [ "test foo ... ok" ]; - }; rustLibTestsCustomLibPath = { libPath = "src/test_path.rs"; src = mkTestFile "src/test_path.rs" "bar"; From 69c96adc53fb7edb909d3682e361f59469b834ef Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Thu, 16 Jan 2020 13:19:50 +0100 Subject: [PATCH 2/2] buildRustCrateTests: use releaseTools.aggregate Previously I did use `runCommand` to do the same. Using releaseTools.aggregate seems a lot saner and we might get nicer hydra output of the tests that are failing. --- .../rust/build-rust-crate/test/default.nix | 15 +++++++++------ pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/test/default.nix b/pkgs/build-support/rust/build-rust-crate/test/default.nix index aa20bd03b189..aefa279fc5e9 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -1,4 +1,4 @@ -{ lib, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage }: +{ lib, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage, releaseTools }: let mkCrate = args: let p = { @@ -211,9 +211,12 @@ let test -e ${pkg}/bin/brotli-decompressor && touch $out ''; }; - test = runCommand "run-buildRustCrate-tests" { - nativeBuildInputs = builtins.attrValues tests; - } " - touch $out - "; + test = releaseTools.aggregate { + name = "buildRustCrate-tests"; + meta = { + description = "Test cases for buildRustCrate"; + maintainers = [ lib.maintainers.andir ]; + }; + constituents = builtins.attrValues tests; + }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4acd88db2e38..6310d3b30e87 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8714,7 +8714,7 @@ in buildRustCrate = callPackage ../build-support/rust/build-rust-crate { }; buildRustCrateHelpers = callPackage ../build-support/rust/build-rust-crate/helpers.nix { }; - buildRustCrateTests = recurseIntoAttrs (callPackage ../build-support/rust/build-rust-crate/test { }).tests; + buildRustCrateTests = recurseIntoAttrs (callPackage ../build-support/rust/build-rust-crate/test { }); cratesIO = callPackage ../build-support/rust/crates-io.nix { }; cargo-web = callPackage ../development/tools/cargo-web {