mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-29 17:14:33 +00:00
9d663f7fcd
The setuptools-rust requires some environment variables to really perform cross build, otherwise it just builds for build platform. This adds setup hook that introduces these environment variables. There are three variables. The PYO3_CROSS_LIB_DIR has to point to the target's Python library directory. This has to be directory for the target not for the build or host. We have to choose the correct target Python. I am unsure how to do that simply in nixpkgs and this this implementations just delays this and waits for the correct Python when package using this hook is build. The CARGO_BUILD_TARGET triggers cross compilation in setuptools-rust. This is simply the Rust target specification. The CARGO_TARGET_*_LINKER variable should not be essentially required but setuptools-rust probably mangles the Rust build environment somewhat and that results to the missing linker. By explicitly specifying it using the environment variable we force the correct linker.
19 lines
709 B
Bash
19 lines
709 B
Bash
echo "Sourcing setuptools-rust-hook"
|
|
|
|
setuptoolsRustSetup() {
|
|
# This can work only if rustPlatform.cargoSetupHook is also included
|
|
if ! command -v cargoSetupPostPatchHook >/dev/null; then
|
|
echo "ERROR: setuptools-rust has to be used alongside with rustPlatform.cargoSetupHook!"
|
|
exit 1
|
|
fi
|
|
|
|
export PYO3_CROSS_LIB_DIR="@pyLibDir@"
|
|
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
|
|
# on missing linker without this.
|
|
export CARGO_TARGET_@cargoLinkerVar@_LINKER=@targetLinker@
|
|
}
|
|
|
|
preConfigureHooks+=(setuptoolsRustSetup)
|