diff options
author | Jan Tojnar <jtojnar@gmail.com> | 2020-03-24 01:51:13 +0100 |
---|---|---|
committer | Jan Tojnar <jtojnar@gmail.com> | 2020-03-24 01:51:13 +0100 |
commit | cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4 (patch) | |
tree | 6534f00bf85774daac26bb0d592f370ee9fb59b7 /pkgs/build-support | |
parent | 9fd82b3e7e99678dab327332bcffec4aad01d22b (diff) | |
parent | 0bfd0187dafe3f597355e6be16b7b9a5f4b90376 (diff) | |
download | nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar.gz nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar.bz2 nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar.lz nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar.xz nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.tar.zst nixlib-cbd504c0ae8eb3be7cbf0e28eee3d85c9d6b7ce4.zip |
Merge branch 'master' into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 4 | ||||
-rw-r--r-- | pkgs/build-support/emacs/setup-hook.sh | 30 | ||||
-rw-r--r-- | pkgs/build-support/ocaml/dune.nix | 6 | ||||
-rw-r--r-- | pkgs/build-support/rust/build-rust-crate/configure-crate.nix | 60 | ||||
-rw-r--r-- | pkgs/build-support/rust/build-rust-crate/lib.sh | 1 | ||||
-rw-r--r-- | pkgs/build-support/rust/build-rust-crate/test/default.nix | 30 | ||||
-rw-r--r-- | pkgs/build-support/rust/default.nix | 23 | ||||
-rw-r--r-- | pkgs/build-support/rust/fetchcargo.nix | 81 |
8 files changed, 109 insertions, 126 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 7ae1c87e993a..96d48ecbc79d 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -10,7 +10,7 @@ , cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell , nativeTools, noLibc ? false, nativeLibc, nativePrefix ? "" , propagateDoc ? cc != null && cc ? man -, extraPackages ? [], extraBuildCommands ? "" +, extraTools ? [], extraPackages ? [], extraBuildCommands ? "" , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , libcxx ? null @@ -214,7 +214,7 @@ stdenv.mkDerivation { ''; strictDeps = true; - propagatedBuildInputs = [ bintools ]; + propagatedBuildInputs = [ bintools ] ++ extraTools; depsTargetTargetPropagated = extraPackages; wrapperName = "CC_WRAPPER"; diff --git a/pkgs/build-support/emacs/setup-hook.sh b/pkgs/build-support/emacs/setup-hook.sh index b210511d670d..8f074e0b406c 100644 --- a/pkgs/build-support/emacs/setup-hook.sh +++ b/pkgs/build-support/emacs/setup-hook.sh @@ -1,13 +1,25 @@ addEmacsVars () { - if test -d $1/share/emacs/site-lisp; then - # it turns out, that the trailing : is actually required + for lispDir in \ + "$1/share/emacs/site-lisp" \ + "$1/share/emacs/site-lisp/"* \ + "$1/share/emacs/site-lisp/elpa/"*; do + # Add the path to the Emacs load path if it is a directory + # containing .el files and it has not already been added to the + # load path. + if [[ -d $lispDir && "$(echo "$lispDir"/*.el)" && ${EMACSLOADPATH-} != *"$lispDir":* ]] ; then + # It turns out, that the trailing : is actually required # see https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html - export EMACSLOADPATH="$1/share/emacs/site-lisp:${EMACSLOADPATH-}" - fi + export EMACSLOADPATH="$lispDir:${EMACSLOADPATH-}" + fi + done } -# If this is for a wrapper derivation, emacs and the dependencies are all -# run-time dependencies. If this is for precompiling packages into bytecode, -# emacs is a compile-time dependency of the package. -addEnvHooks "$hostOffset" addEmacsVars -addEnvHooks "$targetOffset" addEmacsVars +if [[ ! -v emacsHookDone ]]; then + emacsHookDone=1 + + # If this is for a wrapper derivation, emacs and the dependencies are all + # run-time dependencies. If this is for precompiling packages into bytecode, + # emacs is a compile-time dependency of the package. + addEnvHooks "$hostOffset" addEmacsVars + addEnvHooks "$targetOffset" addEmacsVars +fi diff --git a/pkgs/build-support/ocaml/dune.nix b/pkgs/build-support/ocaml/dune.nix index a0aac1447969..435bbe89c1c4 100644 --- a/pkgs/build-support/ocaml/dune.nix +++ b/pkgs/build-support/ocaml/dune.nix @@ -1,7 +1,9 @@ -{ stdenv, ocaml, findlib, dune, opaline }: +{ stdenv, ocaml, findlib, dune, dune_2, opaline }: { pname, version, buildInputs ? [], ... }@args: +let Dune = if args.useDune2 or false then dune_2 else dune; in + if args ? minimumOCamlVersion && ! stdenv.lib.versionAtLeast ocaml.version args.minimumOCamlVersion then throw "${pname}-${version} is not available for OCaml ${ocaml.version}" @@ -29,7 +31,7 @@ stdenv.mkDerivation ({ name = "ocaml${ocaml.version}-${pname}-${version}"; - buildInputs = [ ocaml dune findlib ] ++ buildInputs; + buildInputs = [ ocaml Dune findlib ] ++ buildInputs; meta = (args.meta or {}) // { platforms = args.meta.platforms or ocaml.meta.platforms; }; diff --git a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index 013b99a77b4b..61c39c6b21c0 100644 --- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -56,32 +56,63 @@ in '' i=$1 ln -s -f $i/lib/*.rlib $2 #*/ ln -s -f $i/lib/*.so $i/lib/*.dylib $2 #*/ - if [ -e "$i/lib/link" ]; then - cat $i/lib/link >> target/link - cat $i/lib/link >> target/link.final - fi if [ -e $i/env ]; then source $i/env fi } + # The following steps set up the dependencies of the crate. Two + # kinds of dependencies are distinguished: build dependencies + # (used by the build script) and crate dependencies. For each + # dependency we have to: + # + # - Make its Rust library available to rustc. This is done by + # symlinking all library dependencies into a directory that + # can be provided to rustc. + # - Accumulate linking flags. These flags are largely used for + # linking native libraries. + # + # The crate link flags are added to the `link` and `link.final` + # files. The `link` file is used for linkage in the current + # crate. The `link.final` file will be copied to the output and can + # be used by downstream crates to get the linker flags of this + # crate. + mkdir -p target/{deps,lib,build,buildDeps} chmod uga+w target -R echo ${extraLinkFlags} > target/link echo ${extraLinkFlags} > target/link.final + + # Prepare crate dependencies for i in ${completeDepsDir}; do symlink_dependency $i target/deps + if [ -e "$i/lib/link" ]; then + cat $i/lib/link >> target/link + cat $i/lib/link >> target/link.final + fi done + + # Prepare crate build dependencies that are used for the build script. for i in ${completeBuildDepsDir}; do - symlink_dependency $i target/buildDeps + symlink_dependency $i target/buildDeps + if [ -e "$i/lib/link" ]; then + cat $i/lib/link >> target/link.build + fi done - if [[ -e target/link ]]; then - sort -u target/link > target/link.sorted - mv target/link.sorted target/link - sort -u target/link.final > target/link.final.sorted - mv target/link.final.sorted target/link.final - tr '\n' ' ' < target/link > target/link_ + + # Remove duplicate linker flags from the build dependencies. + if [[ -e target/link.build ]]; then + sort -uo target/link.build target/link.build fi + + # Remove duplicate linker flags from the dependencies. + sort -uo target/link target/link + tr '\n' ' ' < target/link > target/link_ + + # Remove duplicate linker flags from the that are written + # to the derivation's output. + sort -uo target/link.final target/link.final + EXTRA_BUILD="" BUILD_OUT_DIR="" export CARGO_PKG_NAME=${crateName} @@ -120,15 +151,14 @@ in '' elif [[ -e "build.rs" ]]; then BUILD="build.rs" fi + + # Compile and run the build script, when available. if [[ ! -z "$BUILD" ]] ; then echo_build_heading "$BUILD" ${libName} mkdir -p target/build/${crateName} EXTRA_BUILD_FLAGS="" - if [ -e target/link_ ]; then - EXTRA_BUILD_FLAGS=$(cat target/link_) - fi if [ -e target/link.build ]; then - EXTRA_BUILD_FLAGS="$EXTRA_BUILD_FLAGS $(cat target/link.build)" + EXTRA_BUILD_FLAGS="$EXTRA_BUILD_FLAGS $(tr '\n' ' ' < target/link.build)" fi noisily rustc --crate-name build_script_build $BUILD --crate-type bin ${rustcOpts} \ ${crateFeatures} --out-dir target/build/${crateName} --emit=dep-info,link \ diff --git a/pkgs/build-support/rust/build-rust-crate/lib.sh b/pkgs/build-support/rust/build-rust-crate/lib.sh index 0f08c133e557..5843ee98b0d5 100644 --- a/pkgs/build-support/rust/build-rust-crate/lib.sh +++ b/pkgs/build-support/rust/build-rust-crate/lib.sh @@ -79,6 +79,7 @@ build_bin_test_file() { build_bin_test "$derived_crate_name" "$file" } +# Add additional link options that were provided by the build script. setup_link_paths() { EXTRA_LIB="" if [[ -e target/link_ ]]; then 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 710045664686..f24583c41fcb 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -207,6 +207,36 @@ let }) ]; }; + buildScriptDeps = let + depCrate = boolVal: mkCrate { + crateName = "bar"; + src = mkFile "src/lib.rs" '' + pub const baz: bool = ${boolVal}; + ''; + }; + in { + crateName = "foo"; + src = symlinkJoin { + name = "build-script-and-main"; + paths = [ + (mkFile "src/main.rs" '' + extern crate bar; + #[cfg(test)] + #[test] + fn baz_false() { assert!(!bar::baz); } + fn main() { } + '') + (mkFile "build.rs" '' + extern crate bar; + fn main() { assert!(bar::baz); } + '') + ]; + }; + buildDependencies = [ (depCrate "true") ]; + dependencies = [ (depCrate "false") ]; + buildTests = true; + expectedTestOutputs = [ "test baz_false ... ok" ]; + }; # 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 = { diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index f42f951680f7..7cfd03a4e265 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,4 +1,4 @@ -{ stdenv, cacert, git, rust, cargo, rustc, fetchcargo, fetchCargoTarball, buildPackages, windows }: +{ stdenv, cacert, git, rust, cargo, rustc, fetchCargoTarball, buildPackages, windows }: { name ? "${args.pname}-${args.version}" , cargoSha256 ? "unset" @@ -14,7 +14,6 @@ , cargoUpdateHook ? "" , cargoDepsHook ? "" , cargoBuildFlags ? [] -, legacyCargoFetcher ? false , buildType ? "release" , meta ? {} , target ? null @@ -26,21 +25,17 @@ assert buildType == "release" || buildType == "debug"; let - cargoFetcher = if legacyCargoFetcher - then fetchcargo - else fetchCargoTarball; - cargoDeps = if cargoVendorDir == null - then cargoFetcher { + then fetchCargoTarball { inherit name src srcs sourceRoot unpackPhase cargoUpdateHook; patches = cargoPatches; sha256 = cargoSha256; } else null; - # If we're using the modern fetcher that always preserves the original Cargo.lock - # and have vendored deps, check them against the src attr for consistency. - validateCargoDeps = cargoSha256 != "unset" && !legacyCargoFetcher; + # If we have a cargoSha256 fixed-output derivation, validate it at build time + # against the src fixed-output derivation to check consistency. + validateCargoDeps = cargoSha256 != "unset"; # Some cargo builds include build hooks that modify their own vendor # dependencies. This copies the vendor directory into the build tree and makes @@ -50,8 +45,6 @@ let then ('' unpackFile "$cargoDeps" cargoDepsCopy=$(stripHash $cargoDeps) - '' + stdenv.lib.optionalString legacyCargoFetcher '' - chmod -R +w "$cargoDepsCopy" '') else '' cargoDepsCopy="$sourceRoot/${cargoVendorDir}" @@ -65,13 +58,9 @@ let cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"; releaseDir = "target/${rustTarget}/${buildType}"; - # Fetcher implementation choice should not be part of the hash in final - # derivation; only the cargoSha256 input matters. - filteredArgs = builtins.removeAttrs args [ "legacyCargoFetcher" ]; - in -stdenv.mkDerivation (filteredArgs // { +stdenv.mkDerivation (args // { inherit cargoDeps; patchRegistryDeps = ./patch-registry-deps; diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix deleted file mode 100644 index 7a0ba38dce71..000000000000 --- a/pkgs/build-support/rust/fetchcargo.nix +++ /dev/null @@ -1,81 +0,0 @@ -{ stdenv, cacert, git, cargo, python3 }: -let cargo-vendor-normalise = stdenv.mkDerivation { - name = "cargo-vendor-normalise"; - src = ./cargo-vendor-normalise.py; - nativeBuildInputs = [ python3.pkgs.wrapPython ]; - dontUnpack = true; - installPhase = "install -D $src $out/bin/cargo-vendor-normalise"; - pythonPath = [ python3.pkgs.toml ]; - postFixup = "wrapPythonPrograms"; - doInstallCheck = true; - installCheckPhase = '' - # check that ./fetchcargo-default-config.toml is a fix point - reference=${./fetchcargo-default-config.toml} - < $reference $out/bin/cargo-vendor-normalise > test; - cmp test $reference - ''; - preferLocalBuild = true; -}; -in -{ name ? "cargo-deps" -, src ? null -, srcs ? [] -, patches ? [] -, sourceRoot -, sha256 -, cargoUpdateHook ? "" -, # whenever to also include the Cargo.lock in the output - copyLockfile ? false -, ... -} @ args: -stdenv.mkDerivation ({ - name = "${name}-vendor"; - nativeBuildInputs = [ cacert git cargo-vendor-normalise cargo ]; - - phases = "unpackPhase patchPhase installPhase"; - - installPhase = '' - if [[ ! -f Cargo.lock ]]; then - echo - echo "ERROR: The Cargo.lock file doesn't exist" - echo - echo "Cargo.lock is needed to make sure that cargoSha256 doesn't change" - echo "when the registry is updated." - echo - - exit 1 - fi - - # Keep the original around for copyLockfile - cp Cargo.lock Cargo.lock.orig - - export CARGO_HOME=$(mktemp -d cargo-home.XXX) - CARGO_CONFIG=$(mktemp cargo-config.XXXX) - - ${cargoUpdateHook} - - mkdir -p $out - cargo vendor $out | cargo-vendor-normalise > $CARGO_CONFIG - # fetchcargo used to never keep the config output by cargo vendor - # and instead hardcode the config in ./fetchcargo-default-config.toml. - # This broke on packages needing git dependencies, so now we keep the config. - # But not to break old cargoSha256, if the previous behavior was enough, - # we don't store the config. - if ! cmp $CARGO_CONFIG ${./fetchcargo-default-config.toml} > /dev/null; then - install -D $CARGO_CONFIG $out/.cargo/config; - fi; - - '' + stdenv.lib.optionalString copyLockfile '' - # add the Cargo.lock to allow hash invalidation - cp Cargo.lock.orig $out/Cargo.lock - ''; - - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - outputHash = sha256; - - impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars; - preferLocalBuild = true; -} // (builtins.removeAttrs args [ - "name" "sha256" "cargoUpdateHook" "copyLockfile" -])) |