diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support')
34 files changed, 154 insertions, 189 deletions
diff --git a/nixpkgs/pkgs/build-support/binary-cache/default.nix b/nixpkgs/pkgs/build-support/binary-cache/default.nix index 27f9ad962899..8c610c512276 100644 --- a/nixpkgs/pkgs/build-support/binary-cache/default.nix +++ b/nixpkgs/pkgs/build-support/binary-cache/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, buildPackages }: +{ lib, stdenv, coreutils, jq, python3, nix, xz }: # This function is for creating a flat-file binary cache, i.e. the kind created by # nix copy --to file:///some/path and usable as a substituter (with the file:// prefix). @@ -19,15 +19,10 @@ stdenv.mkDerivation { preferLocalBuild = true; - PATH = lib.makeBinPath (with buildPackages; [ coreutils jq python3 nix xz ]); + nativeBuildInputs = [ coreutils jq python3 nix xz ]; - builder = builtins.toFile "builder" '' - . .attrs.sh - - export out=''${outputs[out]} - - mkdir $out - mkdir $out/nar + buildCommand = '' + mkdir -p $out/nar python ${./make-binary-cache.py} diff --git a/nixpkgs/pkgs/build-support/binary-cache/make-binary-cache.py b/nixpkgs/pkgs/build-support/binary-cache/make-binary-cache.py index 16dd8a7e96bc..589d005562b1 100644 --- a/nixpkgs/pkgs/build-support/binary-cache/make-binary-cache.py +++ b/nixpkgs/pkgs/build-support/binary-cache/make-binary-cache.py @@ -3,7 +3,7 @@ import json import os import subprocess -with open(".attrs.json", "r") as f: +with open(os.environ["NIX_ATTRS_JSON_FILE"], "r") as f: closures = json.load(f)["closure"] os.chdir(os.environ["out"]) diff --git a/nixpkgs/pkgs/build-support/build-graalvm-native-image/default.nix b/nixpkgs/pkgs/build-support/build-graalvm-native-image/default.nix index e25a71405089..6a5e82427f7b 100644 --- a/nixpkgs/pkgs/build-support/build-graalvm-native-image/default.nix +++ b/nixpkgs/pkgs/build-support/build-graalvm-native-image/default.nix @@ -3,7 +3,6 @@ , glibcLocales # The GraalVM derivation to use , graalvmDrv -, name ? "${args.pname}-${args.version}" , executable ? args.pname # JAR used as input for GraalVM derivation, defaults to src , jar ? args.src @@ -15,13 +14,13 @@ "-H:Name=${executable}" "-march=compatibility" "--verbose" + "-J-Dsun.stdout.encoding=UTF-8" + "-J-Dsun.stderr.encoding=UTF-8" ] # Extra arguments to be passed to the native-image , extraNativeImageBuildArgs ? [ ] # XMX size of GraalVM during build , graalvmXmx ? "-J-Xmx6g" - # Locale to be used by GraalVM compiler -, LC_ALL ? "en_US.UTF-8" , meta ? { } , ... } @ args: @@ -41,7 +40,7 @@ let ]; in stdenv.mkDerivation ({ - inherit dontUnpack LC_ALL jar; + inherit dontUnpack jar; nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ graalvmDrv glibcLocales ]; diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/add-hardening.sh b/nixpkgs/pkgs/build-support/cc-wrapper/add-hardening.sh index 8d02b4e5124d..8cd63e460951 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/add-hardening.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/add-hardening.sh @@ -10,6 +10,13 @@ for flag in ${NIX_HARDENING_ENABLE_@suffixSalt@-}; do hardeningEnableMap["$flag"]=1 done +# fortify3 implies fortify enablement - make explicit before +# we filter unsupported flags because unsupporting fortify3 +# doesn't mean we should unsupport fortify too +if [[ -n "${hardeningEnableMap[fortify3]-}" ]]; then + hardeningEnableMap["fortify"]=1 +fi + # Remove unsupported flags. for flag in @hardening_unsupported_flags@; do unset -v "hardeningEnableMap[$flag]" @@ -19,7 +26,7 @@ for flag in @hardening_unsupported_flags@; do fi done -# make fortify and fortify3 mutually exclusive +# now make fortify and fortify3 mutually exclusive if [[ -n "${hardeningEnableMap[fortify3]-}" ]]; then unset -v "hardeningEnableMap['fortify']" fi diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 6c43f8cbfa6d..b8d170df01b7 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -246,7 +246,7 @@ if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then fi if (( "${NIX_CC_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then - responseFile=$(mktemp --tmpdir cc-params.XXXXXX) + responseFile=$(mktemp "${TMPDIR:-/tmp}/cc-params.XXXXXX") trap 'rm -f -- "$responseFile"' EXIT printf "%q\n" \ ${extraBefore+"${extraBefore[@]}"} \ diff --git a/nixpkgs/pkgs/build-support/closure-info.nix b/nixpkgs/pkgs/build-support/closure-info.nix index 6b3ff6fd62b0..f2aa4964d9a1 100644 --- a/nixpkgs/pkgs/build-support/closure-info.nix +++ b/nixpkgs/pkgs/build-support/closure-info.nix @@ -4,7 +4,7 @@ # "nix-store --load-db" and "nix-store --register-validity # --hash-given". -{ stdenv, buildPackages }: +{ stdenv, coreutils, jq }: { rootPaths }: @@ -19,18 +19,24 @@ stdenv.mkDerivation { preferLocalBuild = true; - PATH = "${buildPackages.coreutils}/bin:${buildPackages.jq}/bin"; + nativeBuildInputs = [ coreutils jq ]; - builder = builtins.toFile "builder" - '' - . .attrs.sh + empty = rootPaths == []; + buildCommand = + '' out=''${outputs[out]} mkdir $out - jq -r ".closure | map(.narSize) | add" < .attrs.json > $out/total-nar-size - jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration - jq -r .closure[].path < .attrs.json > $out/store-paths + if [[ -n "$empty" ]]; then + echo 0 > $out/total-nar-size + touch $out/registration $out/store-paths + else + jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size + jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration + jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths + fi + ''; } diff --git a/nixpkgs/pkgs/build-support/dart/build-dart-application/default.nix b/nixpkgs/pkgs/build-support/dart/build-dart-application/default.nix index 76328e5645f6..1a98f98fb8e6 100644 --- a/nixpkgs/pkgs/build-support/dart/build-dart-application/default.nix +++ b/nixpkgs/pkgs/build-support/dart/build-dart-application/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, callPackage, fetchDartDeps, runCommand, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }: +{ lib, stdenv, callPackage, fetchDartDeps, writeText, symlinkJoin, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }: { sdkSetupScript ? "" , pubGetScript ? "dart pub get" @@ -36,11 +36,15 @@ let dartDeps = (fetchDartDeps.override { - dart = runCommand "dart-fod" { nativeBuildInputs = [ makeWrapper ]; } '' - mkdir -p "$out/bin" - makeWrapper "${dart}/bin/dart" "$out/bin/dart" \ - --add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt" - ''; + dart = symlinkJoin { + name = "dart-fod"; + paths = [ dart ]; + nativeBuildInputs = [ makeWrapper ]; + postBuild = '' + wrapProgram "$out/bin/dart" \ + --add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt" + ''; + }; }) { buildDrvArgs = args; inherit sdkSetupScript pubGetScript vendorHash pubspecLockFile; diff --git a/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 686d89f8c11c..f8ed3a38890c 100644 --- a/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -158,6 +158,22 @@ stdenvNoCC.mkDerivation (args // { dotnet-sdk ]; + # Parse the version attr into a format acceptable for the Version msbuild property + # The actual version attr is saved in InformationalVersion, which accepts an arbitrary string + versionForDotnet = if !(lib.hasAttr "version" args) || args.version == null + then null else let + components = lib.pipe args.version [ + lib.splitVersion + (lib.filter (x: (lib.strings.match "[0-9]+" x) != null)) + (lib.filter (x: (lib.toInt x) < 65535)) # one version component in dotnet has to fit in 16 bits + ]; + in if (lib.length components) == 0 + then null + else lib.concatStringsSep "." ((lib.take 4 components) + ++ (if (lib.length components) < 4 + then lib.replicate (4 - (lib.length components)) "0" + else [ ])); + makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [ "--prefix LD_LIBRARY_PATH : ${dotnet-sdk.icu}/lib" ]; @@ -172,7 +188,7 @@ stdenvNoCC.mkDerivation (args // { passthru = { inherit nuget-source; - } // lib.optionalAttrs (nugetDepsFile != null) { + } // lib.optionalAttrs (!lib.isDerivation nugetDeps) { fetch-deps = let flags = dotnetFlags ++ dotnetRestoreFlags; diff --git a/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh index e9567b64cf2c..0acfeced9b16 100644 --- a/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh +++ b/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh @@ -24,8 +24,13 @@ dotnetBuildHook() { dotnetBuildFlags+=("-p:UseAppHost=true") fi + local versionFlags=() if [ "${version-}" ]; then - local -r versionFlag="-p:Version=${version-}" + versionFlags+=("-p:InformationalVersion=${version-}") + fi + + if [ "${versionForDotnet-}" ]; then + versionFlags+=("-p:Version=${versionForDotnet-}") fi dotnetBuild() { @@ -43,7 +48,7 @@ dotnetBuildHook() { -p:Deterministic=true \ --configuration "@buildType@" \ --no-restore \ - ${versionFlag-} \ + ${versionFlags[@]} \ ${runtimeIdFlags[@]} \ ${dotnetBuildFlags[@]} \ ${dotnetFlags[@]} diff --git a/nixpkgs/pkgs/build-support/fetchbzr/builder.sh b/nixpkgs/pkgs/build-support/fetchbzr/builder.sh index 991864719a07..4515e0e82f49 100644 --- a/nixpkgs/pkgs/build-support/fetchbzr/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchbzr/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source "$stdenv/setup" echo "exporting \`$url' (revision $rev) into \`$out'" diff --git a/nixpkgs/pkgs/build-support/fetchcvs/builder.sh b/nixpkgs/pkgs/build-support/fetchcvs/builder.sh index 4b49e9676ec0..7e4dde4a64c8 100644 --- a/nixpkgs/pkgs/build-support/fetchcvs/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchcvs/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup (echo "#!$SHELL"; \ diff --git a/nixpkgs/pkgs/build-support/fetchdarcs/builder.sh b/nixpkgs/pkgs/build-support/fetchdarcs/builder.sh index 75b9066dba6f..39838db255a6 100644 --- a/nixpkgs/pkgs/build-support/fetchdarcs/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchdarcs/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup tagtext="" diff --git a/nixpkgs/pkgs/build-support/fetchdocker/fetchdocker-builder.sh b/nixpkgs/pkgs/build-support/fetchdocker/fetchdocker-builder.sh index 4eb70f672d48..489914a2a8b4 100644 --- a/nixpkgs/pkgs/build-support/fetchdocker/fetchdocker-builder.sh +++ b/nixpkgs/pkgs/build-support/fetchdocker/fetchdocker-builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source "${stdenv}/setup" echo "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}" mkdir -p "${out}" diff --git a/nixpkgs/pkgs/build-support/fetchfossil/builder.sh b/nixpkgs/pkgs/build-support/fetchfossil/builder.sh index 36b758ab574e..fe828d0ada9d 100644 --- a/nixpkgs/pkgs/build-support/fetchfossil/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchfossil/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup echo "Cloning Fossil $url [$rev] into $out" diff --git a/nixpkgs/pkgs/build-support/fetchgit/builder.sh b/nixpkgs/pkgs/build-support/fetchgit/builder.sh index 77f6381b09ab..95176beea8c1 100644 --- a/nixpkgs/pkgs/build-support/fetchgit/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchgit/builder.sh @@ -3,7 +3,7 @@ # - revision specified and remote has a HEAD # - revision specified and remote without HEAD # -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup echo "exporting $url (rev $rev) into $out" diff --git a/nixpkgs/pkgs/build-support/fetchhg/builder.sh b/nixpkgs/pkgs/build-support/fetchhg/builder.sh index 1ce294757713..20dfde4b10d4 100644 --- a/nixpkgs/pkgs/build-support/fetchhg/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchhg/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup echo "getting $url${rev:+ ($rev)} into $out" diff --git a/nixpkgs/pkgs/build-support/fetchipfs/builder.sh b/nixpkgs/pkgs/build-support/fetchipfs/builder.sh index ca77962b5384..1ddd111b1518 100644 --- a/nixpkgs/pkgs/build-support/fetchipfs/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchipfs/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup # Curl flags to handle redirects, not use EPSV, handle cookies for diff --git a/nixpkgs/pkgs/build-support/fetchmtn/builder.sh b/nixpkgs/pkgs/build-support/fetchmtn/builder.sh index 1aabd7949ee1..de929fad55a9 100644 --- a/nixpkgs/pkgs/build-support/fetchmtn/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchmtn/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup set -x diff --git a/nixpkgs/pkgs/build-support/fetchsvn/builder.sh b/nixpkgs/pkgs/build-support/fetchsvn/builder.sh index aa4d049aba43..e187747f14e6 100644 --- a/nixpkgs/pkgs/build-support/fetchsvn/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchsvn/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup echo "exporting $url (r$rev) into $out" diff --git a/nixpkgs/pkgs/build-support/fetchsvnssh/builder.sh b/nixpkgs/pkgs/build-support/fetchsvnssh/builder.sh index 5782151524f7..e553446346de 100644 --- a/nixpkgs/pkgs/build-support/fetchsvnssh/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchsvnssh/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup echo "exporting $url (r$rev) into $out" diff --git a/nixpkgs/pkgs/build-support/fetchurl/builder.sh b/nixpkgs/pkgs/build-support/fetchurl/builder.sh index e8eaba934858..a82728ef1025 100644 --- a/nixpkgs/pkgs/build-support/fetchurl/builder.sh +++ b/nixpkgs/pkgs/build-support/fetchurl/builder.sh @@ -1,4 +1,4 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi source $stdenv/setup source $mirrorsFile diff --git a/nixpkgs/pkgs/build-support/node/build-npm-package/default.nix b/nixpkgs/pkgs/build-support/node/build-npm-package/default.nix index 9babc7ae6287..2aefab8ac7ad 100644 --- a/nixpkgs/pkgs/build-support/node/build-npm-package/default.nix +++ b/nixpkgs/pkgs/build-support/node/build-npm-package/default.nix @@ -35,16 +35,15 @@ # Value for npm `--workspace` flag and directory in which the files to be installed are found. , npmWorkspace ? null , nodejs ? topLevelArgs.nodejs +, npmDeps ? fetchNpmDeps { + inherit forceGitDeps src srcs sourceRoot prePatch patches postPatch; + name = "${name}-npm-deps"; + hash = npmDepsHash; +} , ... } @ args: let - npmDeps = fetchNpmDeps { - inherit forceGitDeps src srcs sourceRoot prePatch patches postPatch; - name = "${name}-npm-deps"; - hash = npmDepsHash; - }; - # .override {} negates splicing, so we need to use buildPackages explicitly npmHooks = buildPackages.npmHooks.override { inherit nodejs; diff --git a/nixpkgs/pkgs/build-support/node/fetch-yarn-deps/fixup.js b/nixpkgs/pkgs/build-support/node/fetch-yarn-deps/fixup.js index 8b91e7efa63f..732e569aba7b 100755 --- a/nixpkgs/pkgs/build-support/node/fetch-yarn-deps/fixup.js +++ b/nixpkgs/pkgs/build-support/node/fetch-yarn-deps/fixup.js @@ -21,6 +21,8 @@ const fixupYarnLock = async (lockContents, verbose) => { if (verbose) console.log(`Rewriting URL ${url} for dependency ${dep}`) pkg.resolved = urlToName(url) + if (hash) + pkg.resolved += `#${hash}` return [dep, pkg] }) diff --git a/nixpkgs/pkgs/build-support/references-by-popularity/default.nix b/nixpkgs/pkgs/build-support/references-by-popularity/default.nix index dfc25275f34c..2171c622f000 100644 --- a/nixpkgs/pkgs/build-support/references-by-popularity/default.nix +++ b/nixpkgs/pkgs/build-support/references-by-popularity/default.nix @@ -6,11 +6,8 @@ path: runCommand "closure-paths" exportReferencesGraph.graph = path; __structuredAttrs = true; preferLocalBuild = true; - PATH = "${coreutils}/bin:${python3}/bin"; - builder = builtins.toFile "builder" - '' - . .attrs.sh - python3 ${./closure-graph.py} .attrs.json graph > ''${outputs[out]} - ''; - } - "" + nativeBuildInputs = [ coreutils python3 ]; +} +'' + python3 ${./closure-graph.py} "$NIX_ATTRS_JSON_FILE" graph > ''${outputs[out]} +'' 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 944434472b0b..e842b6a3f501 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 @@ -1,6 +1,5 @@ { lib, stdenv , mkRustcDepArgs, mkRustcFeatureArgs, needUnstableCLI -, rust }: { crateName, @@ -21,7 +20,7 @@ (mkRustcDepArgs dependencies crateRenames) (mkRustcFeatureArgs crateFeatures) ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - "--target" (rust.toRustTargetSpec stdenv.hostPlatform) + "--target" stdenv.hostPlatform.rust.rustcTargetSpec ] ++ lib.optionals (needUnstableCLI dependencies) [ "-Z" "unstable-options" ] ++ extraRustcOpts 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 60310f178747..a6f2528a82ba 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 @@ -1,4 +1,4 @@ -{ lib, stdenv, rust, echo_colored, noisily, mkRustcDepArgs, mkRustcFeatureArgs }: +{ lib, stdenv, echo_colored, noisily, mkRustcDepArgs, mkRustcFeatureArgs }: { build , buildDependencies @@ -124,8 +124,8 @@ in '' export CARGO_PKG_AUTHORS="${authors}" export CARGO_PKG_DESCRIPTION="${crateDescription}" - export CARGO_CFG_TARGET_ARCH=${rust.toTargetArch stdenv.hostPlatform} - export CARGO_CFG_TARGET_OS=${rust.toTargetOs stdenv.hostPlatform} + export CARGO_CFG_TARGET_ARCH=${stdenv.hostPlatform.rust.platform.arch} + export CARGO_CFG_TARGET_OS=${stdenv.hostPlatform.rust.platform.os} export CARGO_CFG_TARGET_FAMILY="unix" export CARGO_CFG_UNIX=1 export CARGO_CFG_TARGET_ENV="gnu" @@ -136,8 +136,8 @@ in '' export CARGO_MANIFEST_DIR=$(pwd) export DEBUG="${toString (!release)}" export OPT_LEVEL="${toString optLevel}" - export TARGET="${rust.toRustTargetSpec stdenv.hostPlatform}" - export HOST="${rust.toRustTargetSpec stdenv.buildPlatform}" + export TARGET="${stdenv.hostPlatform.rust.rustcTargetSpec}" + export HOST="${stdenv.buildPlatform.rust.rustcTargetSpec}" export PROFILE=${if release then "release" else "debug"} export OUT_DIR=$(pwd)/target/build/${crateName}.out export CARGO_PKG_VERSION_MAJOR=${lib.elemAt version 0} 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 d977fb9f7c27..d569142af66a 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-crate/default.nix @@ -10,7 +10,6 @@ , fetchCrate , pkgsBuildBuild , rustc -, rust , cargo , jq , libiconv @@ -71,18 +70,14 @@ let inherit (import ./log.nix { inherit lib; }) noisily echo_colored; configureCrate = import ./configure-crate.nix { - inherit lib stdenv rust echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs; + inherit lib stdenv echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs; }; buildCrate = import ./build-crate.nix { - inherit lib stdenv mkRustcDepArgs mkRustcFeatureArgs needUnstableCLI rust; + inherit lib stdenv mkRustcDepArgs mkRustcFeatureArgs needUnstableCLI; }; installCrate = import ./install-crate.nix { inherit stdenv; }; - - # Allow access to the rust attribute set from inside buildRustCrate, which - # has a parameter that shadows the name. - rustAttrs = rust; in /* The overridable pkgs.buildRustCrate function. @@ -310,7 +305,7 @@ crate_: lib.makeOverridable depsMetadata = lib.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies); hashedMetadata = builtins.hashString "sha256" (crateName + "-" + crateVersion + "___" + toString (mkRustcFeatureArgs crateFeatures) + - "___" + depsMetadata + "___" + rustAttrs.toRustTarget stdenv.hostPlatform); + "___" + depsMetadata + "___" + stdenv.hostPlatform.rust.rustcTarget); in lib.substring 0 10 hashedMetadata; diff --git a/nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix b/nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix index 8b87bcbee3af..8707ce084705 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix @@ -1,7 +1,6 @@ { lib , importCargoLock , fetchCargoTarball -, rust , stdenv , callPackage , cargoBuildHook @@ -80,13 +79,13 @@ let sha256 = args.cargoSha256; } // depsExtraArgs); - target = rust.toRustTargetSpec stdenv.hostPlatform; + target = stdenv.hostPlatform.rust.rustcTargetSpec; targetIsJSON = lib.hasSuffix ".json" target; useSysroot = targetIsJSON && !__internal_dontAddSysroot; sysroot = callPackage ./sysroot { } { inherit target; - shortTarget = rust.lib.toRustTargetSpecShort stdenv.hostPlatform; + shortTarget = stdenv.hostPlatform.rust.cargoShortTarget; RUSTFLAGS = args.RUSTFLAGS or ""; originalCargoToml = src + /Cargo.toml; # profile info is later extracted }; @@ -158,7 +157,8 @@ let # Platforms without host tools from # https://doc.rust-lang.org/nightly/rustc/platform-support.html "armv7a-darwin" - "armv5tel-linux" "armv7a-linux" "m68k-linux" "riscv32-linux" + "armv5tel-linux" "armv7a-linux" "m68k-linux" "mipsel-linux" + "mips64el-linux" "riscv32-linux" "armv6l-netbsd" "x86_64-redox" "wasm32-wasi" diff --git a/nixpkgs/pkgs/build-support/rust/build-rust-package/sysroot/default.nix b/nixpkgs/pkgs/build-support/rust/build-rust-package/sysroot/default.nix index a6d53056d9c7..bb95b7bdc35c 100644 --- a/nixpkgs/pkgs/build-support/rust/build-rust-package/sysroot/default.nix +++ b/nixpkgs/pkgs/build-support/rust/build-rust-package/sysroot/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, rust, rustPlatform, buildPackages }: +{ lib, stdenv, rustPlatform, buildPackages }: { shortTarget, originalCargoToml, target, RUSTFLAGS }: @@ -26,7 +26,7 @@ in rustPlatform.buildRustPackage { done export RUST_SYSROOT=$(rustc --print=sysroot) - host=${rust.toRustTarget stdenv.buildPlatform} + host=${stdenv.buildPlatform.rust.rustcTarget} cp -r $RUST_SYSROOT/lib/rustlib/$host $out ''; diff --git a/nixpkgs/pkgs/build-support/rust/hooks/default.nix b/nixpkgs/pkgs/build-support/rust/hooks/default.nix index 205d085d3507..7703ff4abad4 100644 --- a/nixpkgs/pkgs/build-support/rust/hooks/default.nix +++ b/nixpkgs/pkgs/build-support/rust/hooks/default.nix @@ -13,7 +13,7 @@ # This confusingly-named parameter indicates the *subdirectory of # `target/` from which to copy the build artifacts. It is derived # from a stdenv platform (or a JSON file). -, target ? rust.lib.toRustTargetSpecShort stdenv.hostPlatform +, target ? stdenv.hostPlatform.rust.cargoShortTarget }: { @@ -65,10 +65,10 @@ diff = "${lib.getBin buildPackages.diffutils}/bin/diff"; cargoConfig = '' - [target."${rust.toRustTarget stdenv.buildPlatform}"] + [target."${stdenv.buildPlatform.rust.rustcTarget}"] "linker" = "${rust.envVars.ccForBuild}" ${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' - [target."${rust.toRustTarget stdenv.hostPlatform}"] + [target."${stdenv.hostPlatform.rust.rustcTarget}"] "linker" = "${rust.envVars.ccForHost}" ''} "rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ] diff --git a/nixpkgs/pkgs/build-support/rust/lib/default.nix b/nixpkgs/pkgs/build-support/rust/lib/default.nix index ceca7323176c..dad8ab528235 100644 --- a/nixpkgs/pkgs/build-support/rust/lib/default.nix +++ b/nixpkgs/pkgs/build-support/rust/lib/default.nix @@ -5,89 +5,6 @@ }: rec { - # https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch - toTargetArch = platform: - /**/ if platform ? rustc.platform then platform.rustc.platform.arch - else if platform.isAarch32 then "arm" - else if platform.isMips64 then "mips64" # never add "el" suffix - else if platform.isPower64 then "powerpc64" # never add "le" suffix - else platform.parsed.cpu.name; - - # https://doc.rust-lang.org/reference/conditional-compilation.html#target_os - toTargetOs = platform: - /**/ if platform ? rustc.platform then platform.rustc.platform.os or "none" - else if platform.isDarwin then "macos" - else platform.parsed.kernel.name; - - # https://doc.rust-lang.org/reference/conditional-compilation.html#target_family - toTargetFamily = platform: - if platform ? rustc.platform.target-family - then - ( - # Since https://github.com/rust-lang/rust/pull/84072 - # `target-family` is a list instead of single value. - let - f = platform.rustc.platform.target-family; - in - if builtins.isList f then f else [ f ] - ) - else lib.optional platform.isUnix "unix" - ++ lib.optional platform.isWindows "windows"; - - # https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor - toTargetVendor = platform: let - inherit (platform.parsed) vendor; - in platform.rustc.platform.vendor or { - "w64" = "pc"; - }.${vendor.name} or vendor.name; - - # Returns the name of the rust target, even if it is custom. Adjustments are - # because rust has slightly different naming conventions than we do. - toRustTarget = platform: let - inherit (platform.parsed) cpu kernel abi; - cpu_ = platform.rustc.platform.arch or { - "armv7a" = "armv7"; - "armv7l" = "armv7"; - "armv6l" = "arm"; - "armv5tel" = "armv5te"; - "riscv64" = "riscv64gc"; - }.${cpu.name} or cpu.name; - vendor_ = toTargetVendor platform; - in platform.rustc.config - or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; - - # Returns the name of the rust target if it is standard, or the json file - # containing the custom target spec. - toRustTargetSpec = platform: - if platform ? rustc.platform - then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) - else toRustTarget platform; - - # Returns the name of the rust target if it is standard, or the - # basename of the file containing the custom target spec, without - # the .json extension. - # - # This is the name used by Cargo for target subdirectories. - toRustTargetSpecShort = platform: - lib.removeSuffix ".json" - (baseNameOf "${toRustTargetSpec platform}"); - - # When used as part of an environment variable name, triples are - # uppercased and have all hyphens replaced by underscores: - # - # https://github.com/rust-lang/cargo/pull/9169 - # https://github.com/rust-lang/cargo/issues/8285#issuecomment-634202431 - # - toRustTargetForUseInEnvVars = platform: - lib.strings.replaceStrings ["-"] ["_"] - (lib.strings.toUpper - (toRustTargetSpecShort platform)); - - # Returns true if the target is no_std - # https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421 - IsNoStdTarget = platform: let rustTarget = toRustTarget platform; in - builtins.any (t: lib.hasInfix t rustTarget) ["-none" "nvptx" "switch" "-uefi"]; - # These environment variables must be set when using `cargo-c` and # several other tools which do not deal well with cross # compilation. The symptom of the problem they fix is errors due @@ -107,12 +24,12 @@ rec { ccForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc"; cxxForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++"; - rustBuildPlatform = toRustTarget stdenv.buildPlatform; - rustBuildPlatformSpec = toRustTargetSpec stdenv.buildPlatform; - rustHostPlatform = toRustTarget stdenv.hostPlatform; - rustHostPlatformSpec = toRustTargetSpec stdenv.hostPlatform; - rustTargetPlatform = toRustTarget stdenv.targetPlatform; - rustTargetPlatformSpec = toRustTargetSpec stdenv.targetPlatform; + rustBuildPlatform = stdenv.buildPlatform.rust.rustcTarget; + rustBuildPlatformSpec = stdenv.buildPlatform.rust.rustcTargetSpec; + rustHostPlatform = stdenv.hostPlatform.rust.rustcTarget; + rustHostPlatformSpec = stdenv.hostPlatform.rust.rustcTargetSpec; + rustTargetPlatform = stdenv.targetPlatform.rust.rustcTarget; + rustTargetPlatformSpec = stdenv.targetPlatform.rust.rustcTargetSpec; in { inherit ccForBuild cxxForBuild rustBuildPlatform rustBuildPlatformSpec @@ -131,20 +48,34 @@ rec { # the following lines when rustTargetPlatform collides with # rustHostPlatform. + lib.optionalString (rustTargetPlatform != rustHostPlatform) '' - "CC_${toRustTargetForUseInEnvVars stdenv.targetPlatform}=${ccForTarget}" \ - "CXX_${toRustTargetForUseInEnvVars stdenv.targetPlatform}=${cxxForTarget}" \ - "CARGO_TARGET_${toRustTargetForUseInEnvVars stdenv.targetPlatform}_LINKER=${ccForTarget}" \ + "CC_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${ccForTarget}" \ + "CXX_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${cxxForTarget}" \ + "CARGO_TARGET_${stdenv.targetPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForTarget}" \ '' + '' - "CC_${toRustTargetForUseInEnvVars stdenv.hostPlatform}=${ccForHost}" \ - "CXX_${toRustTargetForUseInEnvVars stdenv.hostPlatform}=${cxxForHost}" \ - "CARGO_TARGET_${toRustTargetForUseInEnvVars stdenv.hostPlatform}_LINKER=${ccForHost}" \ + "CC_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${ccForHost}" \ + "CXX_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${cxxForHost}" \ + "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForHost}" \ '' + '' - "CC_${toRustTargetForUseInEnvVars stdenv.buildPlatform}=${ccForBuild}" \ - "CXX_${toRustTargetForUseInEnvVars stdenv.buildPlatform}=${cxxForBuild}" \ - "CARGO_TARGET_${toRustTargetForUseInEnvVars stdenv.buildPlatform}_LINKER=${ccForBuild}" \ + "CC_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${ccForBuild}" \ + "CXX_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${cxxForBuild}" \ + "CARGO_TARGET_${stdenv.buildPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForBuild}" \ "CARGO_BUILD_TARGET=${rustBuildPlatform}" \ "HOST_CC=${buildPackages.stdenv.cc}/bin/cc" \ "HOST_CXX=${buildPackages.stdenv.cc}/bin/c++" \ ''; }; +} // lib.mapAttrs (old: new: platform: + # TODO: enable warning after 23.05 is EOL. + # lib.warn "`rust.${old} platform` is deprecated. Use `platform.rust.${new}` instead." + lib.getAttrFromPath new platform.rust) +{ + toTargetArch = [ "platform" "arch" ]; + toTargetOs = [ "platform" "os" ]; + toTargetFamily = [ "platform" "target-family" ]; + toTargetVendor = [ "platform" "vendor" ]; + toRustTarget = [ "rustcTarget" ]; + toRustTargetSpec = [ "rustcTargetSpec" ]; + toRustTargetSpecShort = [ "cargoShortTarget" ]; + toRustTargetForUseInEnvVars = [ "cargoEnvVarTarget" ]; + IsNoStdTarget = [ "isNoStdTarget" ]; } diff --git a/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.py b/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.py index 965384b876fc..261f55854808 100644 --- a/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.py +++ b/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.py @@ -174,7 +174,7 @@ class Dependency: found: bool = False # Whether it was found somewhere -def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]: +def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = [], extra_args: List[str] = []) -> list[Dependency]: try: with open_elf(path) as elf: @@ -213,7 +213,7 @@ def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List if file_is_dynamic_executable: print("setting interpreter of", path) subprocess.run( - ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()], + ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()] + extra_args, check=True) rpath += runtime_deps @@ -250,7 +250,7 @@ def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List if rpath: print("setting RPATH to:", rpath_str) subprocess.run( - ["patchelf", "--set-rpath", rpath_str, path.as_posix()], + ["patchelf", "--set-rpath", rpath_str, path.as_posix()] + extra_args, check=True) return dependencies @@ -262,7 +262,8 @@ def auto_patchelf( runtime_deps: List[Path], recursive: bool = True, ignore_missing: List[str] = [], - append_rpaths: List[Path] = []) -> None: + append_rpaths: List[Path] = [], + extra_args: List[str] = []) -> None: if not paths_to_patch: sys.exit("No paths to patch, stopping.") @@ -275,7 +276,7 @@ def auto_patchelf( dependencies = [] for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): if not path.is_symlink() and path.is_file(): - dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths) + dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths, extra_args) missing = [dep for dep in dependencies if not dep.found] @@ -333,6 +334,12 @@ def main() -> None: type=Path, help="Paths to append to all runtime paths unconditionally", ) + parser.add_argument( + "--extra-args", + nargs="*", + type=str, + help="Extra arguments to pass to patchelf" + ) print("automatically fixing dependencies for ELF files") args = parser.parse_args() @@ -344,7 +351,8 @@ def main() -> None: args.runtime_dependencies, args.recursive, args.ignore_missing, - append_rpaths=args.append_rpaths) + append_rpaths=args.append_rpaths, + extra_args=args.extra_args) interpreter_path: Path = None # type: ignore diff --git a/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.sh b/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.sh index 0625565606f3..371389df427b 100644 --- a/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -63,6 +63,7 @@ autoPatchelf() { local appendRunpathsArray=($appendRunpaths) local runtimeDependenciesArray=($runtimeDependencies) + local patchelfFlagsArray=($patchelfFlags) @pythonInterpreter@ @autoPatchelfScript@ \ ${norecurse:+--no-recurse} \ --ignore-missing "${ignoreMissingDepsArray[@]}" \ @@ -70,7 +71,8 @@ autoPatchelf() { --libs "${autoPatchelfLibs[@]}" \ "${extraAutoPatchelfLibs[@]}" \ --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ - --append-rpaths "${appendRunpathsArray[@]}" + --append-rpaths "${appendRunpathsArray[@]}" \ + --extra-args "${patchelfFlagsArray[@]}" } # XXX: This should ultimately use fixupOutputHooks but we currently don't have diff --git a/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh index 55e196e654df..e103fe77d9be 100644 --- a/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh +++ b/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh @@ -36,5 +36,5 @@ fixDarwinDylibNames() { fixDarwinDylibNamesIn() { local dir="$1" - fixDarwinDylibNames $(find "$dir" -name "*.dylib") + fixDarwinDylibNames $(find "$dir" -name "*.dylib" -o -name "*.so" -o -name "*.so.*") } |