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

rustc: be extremely principled about cross builds #356769

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

rhelmot
Copy link
Contributor

@rhelmot rhelmot commented Nov 17, 2024

There were a lot of collapsed assumptions about the cross build process in this derivation, especially with the overloaded meanings of useLLVM. This diff splits useLLVM into a value for each of the build, host, and target platforms. We also specify more target-specific configure flags, including passing through the llvm-config-native binary which is built in some cross configurations. This also allows us to clean up some hacky NIX_LDFLAGS code.

This commit was tested with the following build configurations:

  • x86_64-freebsd -> x86_64-freebsd -> x86_64-freebsd
  • x86_64-freebsd -> x86_64-freebsd -> x86_64-linux
  • x86_64-freebsd -> x86_64-linux -> x86_64-linux
  • x86_64-freebsd -> x86_64-freebsd -> aarch64-linux
  • x86_64-freebsd -> aarch64-linux -> aarch64-linux
  • x86_64-linux -> x86_64-linux -> x86_64-linux
  • x86_64-linux -> x86_64-linux -> aarch64-linux
  • x86_64-linux -> aarch64-linux -> aarch64-linux
  • x86_64-linux -> x86_64-linux -> x86_64-freebsd
  • x86_64-linux -> x86_64-freebsd -> x86_64-freebsd

Please note that darwin is completely absent from this list. I don't have any apple machines!

This PR has several dependencies. I've submitted them all as separate PRs, but some of them target staging and others master. If you'd like to test this branch, please build rhelmot:freebsd-staging-test.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux (cross)
    • x86_64-darwin
    • aarch64-darwin
    • x86_64-freebsd
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 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
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@rhelmot rhelmot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Nov 17, 2024
@emilazy
Copy link
Member

emilazy commented Nov 17, 2024

First impressions: This looks significantly more correct. I’m still sceptical of the weird llvmPackages override in 1_82.nix. I’m still sceptical of the remaining targetPlatform conditionals. I hope that the Darwin conditionals are unneeded, and can builds on Darwin as required. Will try to take a more detailed look later if nobody with deeper Rust/cross knowledge does.

There were a lot of collapsed assumptions about the cross build process
in this derivation, especially with the overloaded meanings of useLLVM.
This diff splits useLLVM into a value for each of the build, host, and
target platforms. We also specify more target-specific configure flags,
including passing through the llvm-config-native binary which is built
in some cross configurations. This also allows us to clean up some hacky
NIX_LDFLAGS code.

This commit was tested with the following build configurations:

* x86_64-freebsd -> x86_64-freebsd -> x86_64-freebsd
* x86_64-freebsd -> x86_64-freebsd -> x86_64-linux
* x86_64-freebsd -> x86_64-linux -> x86_64-linux
* x86_64-freebsd -> x86_64-freebsd -> aarch64-linux
* x86_64-freebsd -> aarch64-linux -> aarch64-linux
* x86_64-linux -> x86_64-linux -> x86_64-linux
* x86_64-linux -> x86_64-linux -> aarch64-linux
* x86_64-linux -> aarch64-linux -> aarch64-linux
* x86_64-linux -> x86_64-linux -> x86_64-freebsd
* x86_64-linux -> x86_64-freebsd -> x86_64-freebsd
@Mic92
Copy link
Member

Mic92 commented Dec 22, 2024

cc @RossComputerGuy

@RossComputerGuy
Copy link
Member

This looks nice, just make sure rust things build in pkgsLLVM.

@ofborg ofborg bot added 10.rebuild-darwin: 501+ 10.rebuild-linux: 501+ and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Dec 23, 2024
else if withBundledLLVM then
"in-tree"
else
"system"
Copy link
Member

Choose a reason for hiding this comment

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

This is repeated three times — maybe a function?

]
else
[
"${setHost}.llvm-config=${llvmShared.dev}/bin/llvm-config-native"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should always create llvm-config-native, even in non-cross builds… This is fine for now though!

@rhelmot
Copy link
Contributor Author

rhelmot commented Dec 24, 2024

I'll address these review comments in a sec but more importantly Ross' comments reveal that this seems to have broken pkgsLLVM.rustc... the error messages are quite confusing but I'll get to the bottom of it.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 26, 2024
@FliegendeWurst FliegendeWurst marked this pull request as draft January 18, 2025 21:30
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: rust 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants