Skip to content

python3Packages.setuptools-rust: fix cross build for all setuptools-rust based packages#467817

Merged
dotlambda merged 1 commit intoNixOS:stagingfrom
DavHau:setuptools-rust
Dec 11, 2025
Merged

python3Packages.setuptools-rust: fix cross build for all setuptools-rust based packages#467817
dotlambda merged 1 commit intoNixOS:stagingfrom
DavHau:setuptools-rust

Conversation

@DavHau
Copy link
Member

@DavHau DavHau commented Dec 4, 2025

Prior to this change all python packages using setuptools-rust were broken when cross compiled as they built binaries for the build platform instead of for the host platform.

The setuptoolsRustBuildHook hook would have to be included as a native build input instead of the setuptools-rust package, but practically wasn't used anywhere.

This change makes it so that setuptoolsRustBuildHook becomes unnecessary, and instead setuptools-rust propagates a setup-hook directly setting up the build environment, similar to how cmake does it when included via nativeBuildInputs.

This change fixes cross on all packages using setuptools-rust as a build-system.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Dec 4, 2025
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 6.topic: python Python is a high-level, general-purpose programming language. labels Dec 4, 2025
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Dec 4, 2025
@dotlambda
Copy link
Member

Commit messages should probably start with python3Packages.setuptools-rust:

@dotlambda dotlambda changed the title python3Packages: fix cross build for all setuptools-rust based packages python3Packages.setuptools-rust: fix cross build for all setuptools-rust based packages Dec 7, 2025
@DavHau DavHau requested a review from dotlambda December 9, 2025 03:51
…rust` based packages

Prior to this change all python packages using `setuptools-rust` were broken when cross compiled as they built binaries for the build platform instead of for the host platform.

The setuptoolsRustBuildHook hook would have to be included as a native build input instead of the `setuptools-rust` package, but practically wasn't used anywhere.

This change makes it so that `setuptoolsRustBuildHook` becomes unnecessary, and instead `setuptools-rust` propagates a setup-hook directly setting up the build environment, similar to how cmake does it when included via nativeBuildInputs.

This change fixes cross on all packages using `setuptools-rust` as a build-system.
@dotlambda dotlambda added this pull request to the merge queue Dec 11, 2025
Merged via the queue into NixOS:staging with commit 195e2bc Dec 11, 2025
27 of 29 checks passed
null
else
replaceVars ./setuptools-rust-hook.sh {
pyLibDir = "${targetPackages.python3}/lib/${targetPackages.python3.libPrefix}";
Copy link
Member

Choose a reason for hiding this comment

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

The default version of python is incorrectly introduced here, instead of the correct one corresponding to python3Packages.

This is causing python312Packages.bcrypt to fail in staging-next, and potentially other packages, because pyo3 tries to use a higher version than current system, resulting in incompatible symbols.

alois31 added a commit to alois31/nixpkgs that referenced this pull request Jan 4, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
alois31 added a commit to alois31/nixpkgs that referenced this pull request Jan 4, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
nixpkgs-ci bot pushed a commit that referenced this pull request Jan 5, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] #476822
[2] #467817

(cherry picked from commit aba5e58)
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 8, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 9, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
@jmbaur
Copy link
Contributor

jmbaur commented Jan 10, 2026

I think this is the change that broke cross-compiling the linux kernel for (e.g.) armv7 targets. Due to ubootTools being used in nativeBuildInputs of the kernel derivation, one can reproduce the failure with nix build nixpkgs#pkgsCross.armv7l-hf-multiplatform.pkgsBuildHost.ubootTools and notice some python bcrypt dependency fails to build. That ends up being because of this line, which pulls in pyopenssl (depends on failing bcrypt). I'm not sure exactly on how this can best be resolved. Is it the fault of this change? Is it being done incorrectly on the ubootTools side?

vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 10, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 11, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 12, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 13, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it mixed cross compilation stage variables in the variables
injected (substituted) to the setup hook. The variables injected in this
commit are identical to those that were used prior to
e656303, but in
`setuptoolsRustBuildHook`.

Should fix this report:

NixOS#467817 (comment)
Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

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

The intention of this PR is good and it is mostly well written, but I too encountered the issue quoted below, and #473299 didn't fix it.

I think this is the change that broke cross-compiling the linux kernel for (e.g.) armv7 targets. Due to ubootTools being used in nativeBuildInputs of the kernel derivation, one can reproduce the failure with nix build nixpkgs#pkgsCross.armv7l-hf-multiplatform.pkgsBuildHost.ubootTools and notice some python bcrypt dependency fails to build. That ends up being because of this line, which pulls in pyopenssl (depends on failing bcrypt). I'm not sure exactly on how this can best be resolved. Is it the fault of this change? Is it being done incorrectly on the ubootTools side?

@DavHau Could you share a nix build command that reproduces the issue you encountered? I can share a command that fails now:

nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.bcrypt

Per my review comment below, I open the following:

EDIT: But it is not fully functional. See comments within. It is functional now.

Comment on lines -450 to -453
substitutions = {
pyLibDir = "${python}/lib/${python.libPrefix}";
cargoBuildTarget = stdenv.hostPlatform.rust.rustcTargetSpec;
cargoLinkerVar = stdenv.hostPlatform.rust.cargoEnvVarTarget;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why didn't you use these variables in the setputools-rust.setupHook?

doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it mixed cross compilation stage variables in the variables
injected (substituted) to the setup hook. The variables injected in this
commit are identical to those that were used prior to
e656303, but in
`setuptoolsRustBuildHook`.

Should fix this report:

NixOS#467817 (comment)
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
doronbehar added a commit to doronbehar/nixpkgs that referenced this pull request Jan 14, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
vdemeester pushed a commit to vdemeester/nixpkgs that referenced this pull request Jan 14, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] NixOS#476822
[2] NixOS#467817
lopsided98 pushed a commit to lopsided98/nixpkgs that referenced this pull request Jan 19, 2026
Commit e656303 (PR NixOS#467817) made
`setuptools-rust` work automatically in cross compilation scenarios by
replacing `setuptoolsRustBuildHook` with `setuptools-rust.setupHook`.
However it broke builds such as:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.buildPackages.python3.pkgs.cryptography
```

As reported here:

NixOS#467817 (comment)

This adjustment fixes the above build, while also maintaining the
following working:

```sh
nix build -Lf. pkgsCross.armv7l-hf-multiplatform.python3.pkgs.libcst
```
vcunat pushed a commit that referenced this pull request Jan 22, 2026
Due to an issue [1] in the Python splices uncovered by the setuptools-rust
cross compilation fix [2], some dependencies will otherwise fail to build.
Unfortunately this actually means losing the tests when the build platform
can execute host binaries (such as in `pkgsStatic`), but there's not a lot
one can do about this without fixing the Python splicing.

[1] #476822
[2] #467817

(cherry picked from commit aba5e58)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants