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

luajit: fix cross build for 32 bit architectures #212760

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

Cynerd
Copy link
Contributor

@Cynerd Cynerd commented Jan 26, 2023

Description of changes

The 32bit compiler has to be used when building on 64bit system.

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/)
  • 23.05 Release Notes (or backporting 22.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.

The implementation is tied to my journey here #212494. The magic is in the usage of pkgsi686Linux.buildPackages instead of just plain pkgsi686Linux.

@ofborg ofborg bot added 6.topic: cross-compilation Building packages on a different platform than they will be used on 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 26, 2023
Comment on lines +56 to +62
buildStdenv = if buildPackages.stdenv.isx86_64 && stdenv.is32bit
then buildPackages.pkgsi686Linux.buildPackages.stdenv
else buildPackages.stdenv;
Copy link
Member

Choose a reason for hiding this comment

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

While this looks good, I wonder if there is a more universal solution that works on other crosses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I consider the luajit approach of requiring the bitness of the build host to match the build system pretty stupid. It is also the only package I know about that requires it (..although I have not looked for it. It is just from my practice with maintaining packages for OpenWrt.).

I am also afraid that this can't be easily achieved on other platforms. Only some CPUs have the ability to run 32-bit code alongside 64-bit. It is standard on x86_64 but not necessary on ARM or RISC-V (I think that one of the examples is Apple's chips).

I should have added a comment there that it is a speciality of luajit, not some common approach.

@Cynerd Cynerd force-pushed the luajit-crossbuild branch from 8de2ea2 to 5151356 Compare January 27, 2023 10:15
@@ -88,8 +94,7 @@ stdenv.mkDerivation rec {
"PREFIX=$(out)"
"DEFAULT_CC=cc"
"CROSS=${stdenv.cc.targetPrefix}"
# TODO: when pointer size differs, we would need e.g. -m32
Copy link
Member

Choose a reason for hiding this comment

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

The note should be preserved, this special casing only works x86_64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Except that this comment is almost only just for x86 because that is not some universal option. The only other applicable (also directly supported by nixpkgs) I found is PowerPC.

Nixpkgs provides, in general, only a single target compilers. That is why gcc_multi exists alongside gcc. That gcc_multi currently also hard depends on i686 and doesn't work on other platforms.

$ nix shell nixpkgs#pkgsCross.aarch64-multiplatform.stdenv.cc -c aarch64-unknown-linux-gnu-gcc -E -march=help -xc /dev/null
...
cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a
$ nix shell nixpkgs#pkgsCross.aarch64-multiplatform.stdenv_32bit.cc
error: Multilib aarch64-unknown-linux-gnu-stage-final-gcc-wrapper-9.5.0 not supported for ‘aarch64-linux’
(use '--show-trace' to show detailed location information)

I am going to add TODO at the other place instead of this one where support for other platforms should be required. The issue is that it won't be that easy for ARM for example because not every aarch64 supports for example armv7l.

The best practice here would be to use stdenv_32bit but that is broken as I described in #212494. I will suggest that in the TODO.

The 32bit compiler has to be used when building on 64bit system.
@Cynerd Cynerd force-pushed the luajit-crossbuild branch from 5151356 to af28395 Compare January 30, 2023 08:54
@NickCao NickCao merged commit 2603076 into NixOS:master Jan 31, 2023
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: lua 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants