Skip to content

python3Packages.setuptools: add distutils patch to support cross-compilation#173435

Merged
Artturin merged 1 commit intoNixOS:stagingfrom
lopsided98:setuptools-cross
Jun 13, 2022
Merged

python3Packages.setuptools: add distutils patch to support cross-compilation#173435
Artturin merged 1 commit intoNixOS:stagingfrom
lopsided98:setuptools-cross

Conversation

@lopsided98
Copy link
Copy Markdown
Contributor

Description of changes

This is mostly the same patch applied to stdlib distutils, except rebased and reworked a bit. This fixes cross-compilation of Python packages with C extension modules now that setuptools uses bundled distutils. I will make another try at getting this patch upstreamed.

Fixes #168861.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label May 17, 2022
@ofborg ofborg bot added 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. labels May 18, 2022
@lopsided98 lopsided98 changed the base branch from master to staging May 18, 2022 02:03
@lopsided98
Copy link
Copy Markdown
Contributor Author

lopsided98 commented May 18, 2022

I'm running into a strange issue (not obviously related to this PR) where packages that depend on cffi as a native build input (such as brotlicffi) are attempting to build a version of cffi that is built for build platform but depends on host platform libffi. This obviously fails to build, with the following error:

gcc -shared -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-zlib-1.2.12/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bzip2-1.0.6.0.2/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-expat-2.4.8/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeee>
/nix/store/rs684lgm8k7akkgbisb49z4vpxxc2zns-binutils-2.38/bin/ld: skipping incompatible /nix/store/b7p34l2l1w21b6kvpv31kr65v0pdfyzh-libffi-armv6l-unknown-linux-gnueabihf-3.4.2/lib/libffi.so when searching for -lffi
/nix/store/rs684lgm8k7akkgbisb49z4vpxxc2zns-binutils-2.38/bin/ld: skipping incompatible /nix/store/b7p34l2l1w21b6kvpv31kr65v0pdfyzh-libffi-armv6l-unknown-linux-gnueabihf-3.4.2/lib/libffi.so when searching for -lffi
/nix/store/rs684lgm8k7akkgbisb49z4vpxxc2zns-binutils-2.38/bin/ld: cannot find -lffi: No such file or directory
/nix/store/rs684lgm8k7akkgbisb49z4vpxxc2zns-binutils-2.38/bin/ld: skipping incompatible /nix/store/b7p34l2l1w21b6kvpv31kr65v0pdfyzh-libffi-armv6l-unknown-linux-gnueabihf-3.4.2/lib/libffi.so when searching for -lffi
/nix/store/rs684lgm8k7akkgbisb49z4vpxxc2zns-binutils-2.38/bin/ld: skipping incompatible /nix/store/b7p34l2l1w21b6kvpv31kr65v0pdfyzh-libffi-armv6l-unknown-linux-gnueabihf-3.4.2/lib/libffi.so when searching for -lffi
collect2: error: ld returned 1 exit status
error: command '/nix/store/bg35nfwn6zd616facdywiysgpprfvsji-gcc-wrapper-11.3.0/bin/gcc' failed with exit code 1

@Mindavi
Copy link
Copy Markdown
Contributor

Mindavi commented May 18, 2022

That ffi issue is an issue I observed before already, so I'd say it's unrelated.

@lopsided98
Copy link
Copy Markdown
Contributor Author

Yes, I bisected it and found that #169475 was responsible.

@Mindavi Mindavi added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label May 18, 2022
@lopsided98
Copy link
Copy Markdown
Contributor Author

@ofborg build pkgsCross.armv7l-hf-multiplatform.python3Packages.numpy

./tag-date.patch
./setuptools-distutils-C++.patch
# Use sysconfigdata to find headers. Fixes cross-compilation of extension modules.
(fetchpatch {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is fetchpatch allowed here? Think this is somewhere in the bootstrap, hence causing the eval failure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was wondering about that as well. I'm not sure how to know whether that is the case.

Copy link
Copy Markdown
Member

@FRidh FRidh May 20, 2022

Choose a reason for hiding this comment

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

The Python interpreter is a bootstrap package, but setuptools is not (and should not be).

@Artturin
Copy link
Copy Markdown
Member

Artturin commented Jun 4, 2022

The eval failure is unrelated and is due to ofborg timing out building something

Copy link
Copy Markdown
Member

@Artturin Artturin left a comment

Choose a reason for hiding this comment

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

Cross built on ofborg

@bobby285271 bobby285271 added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 5, 2022
@Artturin Artturin added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Jun 6, 2022
…ilation

This is mostly the same patch applied to stdlib distutils, except rebased
and reworked a bit. This fixes cross-compilation of Python packages with
C extension modules now that setuptools uses bundled distutils.
@bobby285271 bobby285271 removed the 12.approvals: 2 This PR was reviewed and approved by two persons. label Jun 12, 2022
@Artturin Artturin merged commit 0fd678e into NixOS:staging Jun 13, 2022
@lopsided98 lopsided98 deleted the setuptools-cross branch June 13, 2022 23:39
@ck3d
Copy link
Copy Markdown
Contributor

ck3d commented Jul 14, 2022

@lopsided98 I had the same problem in nixos-22.05, do you want to backport this PR or should I open a new PR?

@Artturin
Copy link
Copy Markdown
Member

Artturin commented Jul 14, 2022

cross-compilation is usually in the best shape on master so I recommend using nixos-unstable (afaik all of the people interested in cross-compilation are on nixos-unstable)

you can add labels yourself if you want since you're a member of the org

@ck3d
Copy link
Copy Markdown
Contributor

ck3d commented Jul 16, 2022

I want to migrate from NixOS-21.11 to NixOS-22.05 but I hit this issue. It is frustrating if we loose capabilities between NixOS releases. I try to find a workaround on my production side. We will see if more people are interested to fix this issue for NixOS-22.05.

@Mindavi
Copy link
Copy Markdown
Contributor

Mindavi commented Jul 16, 2022

We can backport this, but it depends on what you're doing if this is sufficient

@github-actions
Copy link
Copy Markdown
Contributor

Successfully created backport PR #181734 for staging-22.05.

@ck3d
Copy link
Copy Markdown
Contributor

ck3d commented Jul 17, 2022

Thanks. Yes this PR is sufficient to cross compile a lot of Python packages (e.g. lxml, btrfs-progs, ...) for NixOS-22.05.

rnhmjoj added a commit to rnhmjoj/nixpkgs that referenced this pull request Aug 28, 2022
This fixes, again, the issue with the wrong headers being used when
cross compiling python packages with extensions.
For context, see NixOS#173435.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

btrfs-progs: doesn't cross compile to armv6l-linux (from x86_64-linux)

8 participants