-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
python3Packages.cryptography: fix invalid platform for Rust on cross-… #208401
Conversation
…compile The Rust library was being built for the build platform and not for the host platform when cross-compiling.
CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}"; | ||
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}"; | ||
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" = | ||
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i recommend adding a setup hook to setuptools-rust that does these
CARGO_BUILD_TARGET_TARGET = "${rust.toRustTargetSpec targetPackages.stdenv.hostPlatform}";
PYO3_CROSS_LIB_DIR_TARGET = "${targetPackages.python}/lib/${targetPackages.python.libPrefix}";
CARGO_LINKER_VAR = "CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget targetPackages.stdenv.hostPlatform))}_LINKER"
TARGET_LINKER = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc";
add the above to the setuptools-rust and a setup hook that exports them
export CARGO_BUILD_TARGET_TARGET=@CARGO_BUILD_TARGET@
export PYO3_CROSS_LIB_DIR_TARGET=@PYO3_CROSS_LIB_DIR@
export @CARGO_LINKER_VAR@=@TARGET_LINKER@
CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}"; | ||
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}"; | ||
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" = | ||
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}"; | |
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}"; | |
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" = | |
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; | |
CARGO_BUILD_TARGET = rust.toRustTargetSpec stdenv.hostPlatform; | |
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}"; | |
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" = | |
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; |
Are those generic variables we want to set?
If so we should move them to a setup-hook like maturin or setuptools-rust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the question... I took those variables from here https://github.com/PyO3/setuptools-rust/blob/main/.github/workflows/ci.yml#L270 and here PyO3/setuptools-rust#294 (comment). The CARGO_BUILD_TARGET
and PYO3_CROSS_LIB_DIR
seem reasonable, but I am not sure about CARGO_TARGET_*
. It is kind of weird to have to specify the linker. No other package except of crosvm
has to do this (that is where I took it from anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is kind of weird to have to specify the linker.
Especially weird given that we already do this:
nixpkgs/pkgs/build-support/rust/hooks/default.nix
Lines 98 to 110 in 06542b2
cargoConfig = '' | |
[host] | |
"linker" = "${ccForBuild}" | |
"rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ] | |
[target."${shortTarget}"] | |
"linker" = "${ccForHost}" | |
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ] | |
[unstable] | |
host-config = true | |
target-applies-to-host = true | |
''; |
rustPlatform.cargoSetupHook | ||
rustc | ||
cargo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert/check in a setup hook this somewhere to make sure this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or should this be propagated inputs for setuptools-rust
?
@ofborg eval |
Superseded by #212795. |
Description of changes
The Rust library was being built for the build platform and not for the host platform when cross-compiling. This sets build so it builds it for the correct platform.
The issue was reported and investigated in #205807
I was looking also into other packages that use
setuptools-rust
, and it seems that the same modifications are required there as well.Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes