diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support/rust')
5 files changed, 68 insertions, 39 deletions
diff --git a/nixpkgs/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/nixpkgs/pkgs/build-support/rust/build-rust-crate/build-crate.nix index 4e2e2af1aa7..dec49d24f52 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/nixpkgs/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/nixpkgs/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/nixpkgs/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index efc538f0fd6..c146ffef5ff 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -137,16 +137,7 @@ in '' CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\U\1/") grep -P "^cargo:(?!(rustc-|warning=|rerun-if-changed=|rerun-if-env-changed))" target/build/${crateName}.opt \ | sed -e "s/cargo:\([^=]*\)=\(.*\)/export DEP_$(echo $CRATENAME)_\U\1\E=\2/" > target/env - set -e - if [[ -n "$(ls target/build/${crateName}.out)" ]]; then - - if [[ -e "${libPath}" ]]; then - cp -r target/build/${crateName}.out/* $(dirname ${libPath}) #*/ - else - cp -r target/build/${crateName}.out/* src #*/ - fi - fi fi runHook postConfigure '' diff --git a/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix b/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix index 2885b2aef51..569b48d25ae 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix @@ -23,7 +23,7 @@ let lib.strings.replaceStrings ["-"] ["_"] crateRenames.${dep.crateName} else extern; - in (if lib.any (x: x == "lib") dep.crateType then + in (if lib.any (x: x == "lib" || x == "rlib") dep.crateType then " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}.rlib" else " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}") diff --git a/nixpkgs/pkgs/build-support/rust/build-rust-crate/test/default.nix b/nixpkgs/pkgs/build-support/rust/build-rust-crate/test/default.nix index f0f1ed4d1eb..6aad02992c1 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -1,17 +1,17 @@ -{ lib, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage }: +{ lib, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage, releaseTools }: let mkCrate = args: let - p = { - crateName = "nixtestcrate"; - version = "0.1.0"; - authors = [ "Test <test@example.com>" ]; - } // args; - in buildRustCrate p; + p = { + crateName = "nixtestcrate"; + version = "0.1.0"; + authors = [ "Test <test@example.com>" ]; + } // args; + in buildRustCrate p; - mkFile = destination: text: writeTextFile { - name = "src"; - destination = "/${destination}"; - inherit text; + mkFile = destination: text: writeTextFile { + name = "src"; + destination = "/${destination}"; + inherit text; }; mkBin = name: mkFile name '' @@ -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"; @@ -181,7 +185,41 @@ let "test tests_bar ... ok" ]; }; - + linkAgainstRlibCrate = { + crateName = "foo"; + src = mkFile "src/main.rs" '' + extern crate somerlib; + fn main() {} + ''; + dependencies = [ + (mkCrate { + crateName = "somerlib"; + type = [ "rlib" ]; + src = mkLib "src/lib.rs"; + }) + ]; + }; + # Regression test for https://github.com/NixOS/nixpkgs/issues/74071 + # Whenevever a build.rs file is generating files those should not be overlayed onto the actual source dir + buildRsOutDirOverlay = { + src = symlinkJoin { + name = "buildrs-out-dir-overlay"; + paths = [ + (mkLib "src/lib.rs") + (mkFile "build.rs" '' + use std::env; + use std::ffi::OsString; + use std::fs; + use std::path::Path; + fn main() { + let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR not set"); + let out_file = Path::new(&out_dir).join("lib.rs"); + fs::write(out_file, "invalid rust code!").expect("failed to write lib.rs"); + } + '') + ]; + }; + }; }; brotliCrates = (callPackage ./brotli-crates.nix {}); in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // { @@ -207,9 +245,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/nixpkgs/pkgs/build-support/rust/default.nix b/nixpkgs/pkgs/build-support/rust/default.nix index f9cf8f1f0c1..4089436c0e0 100644 --- a/nixpkgs/pkgs/build-support/rust/default.nix +++ b/nixpkgs/pkgs/build-support/rust/default.nix @@ -100,9 +100,9 @@ stdenv.mkDerivation (args // { '' + stdenv.lib.optionalString verifyCargoDeps '' if ! diff source/Cargo.lock $cargoDeps/Cargo.lock ; then echo - echo "ERROR: cargoSha256 is out of date." + echo "ERROR: cargoSha256 is out of date" echo - echo "Cargo.lock is not the same in $cargoDeps." + echo "Cargo.lock is not the same in $cargoDeps" echo echo "To fix the issue:" echo '1. Use "1111111111111111111111111111111111111111111111111111" as the cargoSha256 value' |