Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setuptools-rust-hook: Use correct python for cross #262123

Closed
wants to merge 12 commits into from
3 changes: 2 additions & 1 deletion pkgs/development/compilers/gcc/all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, cloog_0_18_0, cloog
, lowPrio
, wrapCC
, __splicedPackages
}@args:

let
Expand All @@ -27,7 +28,7 @@ let
libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then args.libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor majorMinorVersion else { };
isl = if stdenv.isDarwin then null
else if atLeast "9" then isl_0_20
else if atLeast "9" then __splicedPackages.isl_0_20
else if atLeast "7" then isl_0_17
else if atLeast "6" then (if stdenv.targetPlatform.isRedox then isl_0_17 else isl_0_14)
else if atLeast "4.9" then isl_0_11
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib, stdenv
, targetPackages
, targetPackages_bintools

, withoutTargetLibc, libcCross
, threadsCross
Expand Down Expand Up @@ -56,8 +56,8 @@ let
crossConfigureFlags =
# Ensure that -print-prog-name is able to find the correct programs.
[
"--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld"
"--with-as=${if targetPackages_bintools.isLLVM then binutils else targetPackages_bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages_bintools}/bin/${targetPlatform.config}-ld"
]
++ (if withoutTargetLibc then [
"--disable-libssp"
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/compilers/gcc/common/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
, stdenv
, version
, buildPackages
, targetPackages
, texinfo
, which
, gettext
Expand All @@ -12,6 +11,7 @@
, gmp
, mpfr
, libmpc
, targetPackages_bintools
, libucontext ? null
, libxcrypt ? null
, cloog ? null
Expand Down Expand Up @@ -62,7 +62,7 @@ in
depsBuildTarget =
(
if hostPlatform == buildPlatform then [
targetPackages.stdenv.cc.bintools # newly-built gcc will be used
targetPackages_bintools # newly-built gcc will be used
] else assert targetPlatform == hostPlatform; [
# build != host == target
stdenv.cc
Expand All @@ -77,7 +77,7 @@ in
]
++ optionals (lib.versionAtLeast version "10") [ libxcrypt ]
++ [
targetPackages.stdenv.cc.bintools # For linking code at run-time
targetPackages_bintools # For linking code at run-time
]
++ optionals (lib.versionOlder version "5" && cloog != null) [ cloog ]
++ optionals (isl != null) [ isl ]
Expand Down
5 changes: 3 additions & 2 deletions pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
{ lib, stdenv, fetchurl, fetchpatch, noSysDirs
, langC ? true, langCC ? true, langFortran ? false
, langAda ? false
, langObjC ? stdenv.targetPlatform.isDarwin
Expand All @@ -14,6 +14,7 @@
, texinfo ? null
, perl ? null # optional, for texi2pod (then pod2man)
, gmp, mpfr, libmpc, gettext, which, patchelf, binutils
, targetPackages_bintools
, isl ? null # optional, for the Graphite optimization framework.
, zlib ? null
, libucontext ? null
Expand Down Expand Up @@ -173,7 +174,7 @@ let inherit version;
reproducibleBuild
staticCompiler
stdenv
targetPackages
targetPackages_bintools
texinfo
threadsCross
which
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/interpreters/python/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ in {
name = "setuptools-rust-setup-hook";
propagatedBuildInputs = [ setuptools-rust ];
substitutions = {
pyIncludeDir = "${python}/include/${python.libPrefix}";
pyLibDir = "${python}/lib/${python.libPrefix}";
pyBin = python.interpreter;
cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ setuptoolsRustSetup() {
exit 1
fi

export PYO3_CROSS_LIB_DIR="@pyLibDir@"
export PYO3_CROSS_INCLUDE_DIR="@pyIncludeDir@";
export PYO3_CROSS_LIB_DIR="@pyLibDir@";
export PYO3_PYTHON="@pyBin@";
export CARGO_BUILD_TARGET=@cargoBuildTarget@
# TODO theoretically setting linker should not be required because it is
# already set in pkgs/build-support/rust/hooks/default.nix but build fails
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/libraries/cracklib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let version = "2.9.11"; in
{ stdenv, lib, buildPackages, fetchurl, zlib, gettext
, cracklib
, lists ? [ (fetchurl {
url = "https://github.com/cracklib/cracklib/releases/download/v${version}/cracklib-words-${version}.gz";
hash = "sha256-popxGjE1c517Z+nzYLM/DU7M+b1/rE0XwNXkVqkcUXo=";
Expand All @@ -15,7 +16,7 @@ stdenv.mkDerivation rec {
hash = "sha256-yosEmjwtOyIloejRXWE3mOvHSOOVA4jtomlN5Qe6YCA=";
};

nativeBuildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) buildPackages.cracklib;
nativeBuildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) cracklib;
buildInputs = [ zlib gettext ];

postPatch = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
Expand Down
141 changes: 131 additions & 10 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
let

#
# This is a list of pnames of packages that have failed to splice.
# Every one of these is an unfixed bug. Please fix them instead
# of taking shameful behavior, you scoundrel!
#
list-of-shame =
builtins.listToAttrs
(builtins.map
(name: { inherit name; value = true; })
[
# shame on you, python
"pypa-build-hook.sh"
"pypa-install-hook"
"pytest-check-hook"
"python-catch-conflicts-hook"
"python-imports-check-hook.sh"
"python-namespaces-hook.sh"
"python-output-dist-hook"
"python-remove-bin-bytecode-hook"
"python-remove-tests-dir-hook"
"python-remove-tests-dir-hook"
"python3-3.11.5-env"
"setuptools-check-hook"
"setuptools-setup-hook"
"unittest-check-hook"
"wrap-python-hook"
"wrap-python-hook"
"wrap-python-hook"

# shame on you, llvm!
"llvm"
"compiler-rt"
"libcxx"
"libcxxabi"
"libunwind"

# shame on you, embedded ARM!
"arm-none-eabi-stage-final-gcc-wrapper"
"arm-none-eabi-binutils-wrapper"

# wasm doesn't care about shamefulness, so I won't bother...
"rustc-wasm32"

# windows
# has overrides which discard splicing
# improvement: convert makeScope to makeScopeWithSplicing'
# may not fix it but it'll improve the set
# https://github.com/NixOS/nixpkgs/blob/53aa767c849b159cdb8c59dce4a5a44f167fc31b/pkgs/os-specific/windows/default.nix#L20
"mcfgthreads"
"i686-w64-mingw32-stage-final-gcc-wrapper"
"x86_64-w64-mingw32-stage-final-gcc-wrapper"

# other shameful derivations
"git-minimal"
"busybox"
"avr-stage-final-gcc-wrapper"
"boost-build"
"cmake-boot"
"perl" # only for libxcrypt; we should fix this
]);
in

{ lib, config }:

stdenv:
Expand Down Expand Up @@ -283,32 +347,89 @@ else let
references = nativeBuildInputs ++ buildInputs
++ propagatedNativeBuildInputs ++ propagatedBuildInputs;

getSpliced = type: dep:
dep.__spliced or
(let approximate-pname = dep.pname or dep.name; in
assert
(dep?stdenv &&
dep.stdenv.buildPlatform != dep.stdenv.targetPlatform &&

# I can't test on Darwin, so let's just ignore it for now.
!dep.stdenv.buildPlatform.isDarwin &&
!dep.stdenv.hostPlatform.isDarwin &&
!dep.stdenv.targetPlatform.isDarwin &&

!(list-of-shame ? ${approximate-pname})
)

# Hi there! If you're reading this, it's probably
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be way easier to read and a lot less lines if we'd wrote one setence per line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would be but that's part of #263082. I feel like if that got merged it would force us to address the cross-compilation issues.

# because the line below caused your PR to fail CI.
# Don't panic! Most likely, what happened is that you
# used one of the following as a dependency:
#
# - `buildPackages.something`
# - `targetPackages.something`
# - `pkgs{Build,Host,Target}{Build,Host,Target}.something`
#
# You can't use those as dependencies (i.e. in a
# `buildInputs`, `nativeBuildInputs`, or
# `deps{Build,Host,Target}{Build,Host,Target}`
# attribute). The reason is a bit obscure, but the fix
# is easy: just use `something` instead! The explicit
# packagesets (the three bullet points above) are mainly
# for when you need to reference a package with string
# interpolation (e.g. "cat blah | ${buildPackages.jq}").
# For dependencies, you control which packageset is used
# by *which attribute you put the dependency in* -- if
# you put it in `depsBuildHost`, it will get pulled from
# `pkgsBuildHost`.
#
# Please take a moment to try to fix your PR. If you
# can't get it fixed, ping @amjoseph-nixpkgs who can
# help you fix it. If this is a crisis situation and
# the future of humanity depends on your PR passing CI
# pronto, you can mute the warning by adding your
# package's `pname` to the `list-of-shame` at the top of
# this file. But please don't do that.
#
-> lib.warn
''derivation ${attrs.pname or "!!no pname!!"}:
unspliced ${type} dependency ${approximate-pname}
build=${dep.stdenv.buildPlatform.config}
host=${dep.stdenv.hostPlatform.config}
target=${dep.stdenv.targetPlatform.config}
For advice on fixing this, read the comment above the lib.warn that produced this message.
'' true;
{});

dependencies = map (map chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))
(map (drv: (getSpliced "build-build" drv).buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: (getSpliced "build-host" drv).buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
(map (drv: (getSpliced "build-target" drv).buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: (getSpliced "host-host" drv).hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))
#(map (drv: (getSpliced "host-target" drv).hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
(map (drv: (getSpliced "target-target" drv).targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
]
];
propagatedDependencies = map (map chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
(map (drv: (getSpliced "build-build propagated" drv).buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: (getSpliced "build-host propagated" drv).buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: (getSpliced "build-target propagated" drv).buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: (getSpliced "host-host propagated" drv).hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
#(map (drv: (getSpliced "host-target propagated" drv).hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))
(map (drv: (getSpliced "target-target propagated" drv).targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))
]
];

Expand Down
14 changes: 11 additions & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15948,6 +15948,10 @@ with pkgs;
then overrideCC stdenv buildPackages.llvmPackages.clangNoLibc
else gccCrossLibcStdenv;

# This needs to have a top-level entry here in all-packages.nix in
# order to be spliced.
targetPackages_bintools = targetPackages.stdenv.cc.bintools;

# The GCC used to build libc for the target platform. Normal gccs will be
# built with, and use, that cross-compiled libc.
gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let
Expand All @@ -15961,12 +15965,12 @@ with pkgs;
reproducibleBuild = true;
profiledCompiler = false;

isl = if !stdenv.isDarwin then isl_0_20 else null;
isl = if !stdenv.isDarwin then __splicedPackages.isl_0_20 else null;

withoutTargetLibc = true;
langCC = false;
libcCross = libcCross1;
targetPackages.stdenv.cc.bintools = binutilsNoLibc;
targetPackages_bintools = __splicedPackages.binutilsNoLibc;
enableShared =
stdenv.targetPlatform.hasSharedLibraries

Expand Down Expand Up @@ -16963,6 +16967,7 @@ with pkgs;
};
};
}).overrideAttrs (old: {
pname = "rustc-wasm32";
configureFlags = old.configureFlags ++ ["--set=build.docs=false"];
});

Expand Down Expand Up @@ -18630,7 +18635,10 @@ with pkgs;
enableGold = false;
};
});
binutilsNoLibc = wrapBintoolsWith {
binutilsNoLibc =
# this `if..then null else` is an ugly hack to prevent infinite recursion
if stdenv.hostPlatform == stdenv.targetPlatform then null else
wrapBintoolsWith {
bintools = binutils-unwrapped;
libc = preLibcCrossHeaders;
};
Expand Down
Loading