Skip to content

Conversation

RossComputerGuy
Copy link
Member

Things done

Fixes #311930

Works on aarch64-linux after stacking #409265

  • 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.

@nixpkgs-ci nixpkgs-ci bot added 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. 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. labels Jul 31, 2025
@ccicnce113424
Copy link
Contributor

ccicnce113424 commented Jul 31, 2025

I committed and tested commit 15470fe, and the build was successful without setting the rpath.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to set set the rpath here if we correct #320432 (comment).
We can also remove the fake libgcc here since it was already added in #330037.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -101,7 +101,9 @@ stdenv.mkDerivation (finalAttrs: {
(stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM)
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"
++ optional (stdenv.hostPlatform.isDarwin && !withBundledLLVM) "-lc++ -lc++abi"
++ optional stdenv.hostPlatform.isFreeBSD "-rpath ${llvmPackages.libunwind}/lib"
++ optional (
with stdenv.hostPlatform; isFreeBSD || (isLinux && useLLVM && !withBundledLLVM)
Copy link
Member

Choose a reason for hiding this comment

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

Why not just check useLLVM though? If it's needed on both Linux and FreeBSD, it's probably not OS-specific, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably but what if someone sets useLLVM to false on FreeBSD? Or how does setting withBundledLLVM on BSD change things?

Copy link
Member

Choose a reason for hiding this comment

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

@rhelmot WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really sorry I haven't had time to look into this. If I'm the only blocker, please merge it and I'll un-break FreeBSD when I get back to it.

Copy link
Member

Choose a reason for hiding this comment

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

Then let's be optimistic, and just set it to useLLVM && !withBundledLLVM.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@blitz
Copy link
Contributor

blitz commented Aug 13, 2025

@RossComputerGuy @alyssais It would be great to get this merged, because it blocks kernel builds on pkgsLLVM.

Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

Can the commit message please explain why each of these changes is being made?

@RossComputerGuy
Copy link
Member Author

Can the commit message please explain why each of these changes is being made?

Done

@alyssais
Copy link
Member

It doesn't really explain why still, just what changes are happening, which I can see from the diff. Why is each of these changes the correct thing to do?

@RossComputerGuy
Copy link
Member Author

Idk how to explain why, it just does.

@emilazy
Copy link
Member

emilazy commented Aug 15, 2025

I don't think it should be necessary to do any of this llvmPackages or llvmSharedFor stuff at all. Why wouldn't llvmPackages just work, even in pkgsLLVM?

I get the strong impression that there is something buggy with how the toolchain is wired up in pkgsLLVM that is creating the perceived need for all these ad-hoc unexplained workarounds for it across the tree. I know Darwin is a different case to pkgsLLVM in many ways, e.g. around the unwinder library and soon libc++, but it's similar enough that the fact that we don't need any of it there makes me strongly suspect the problem here is not with LLVM or Rust. (Though I wouldn't be surprised if there is a still a degree of "Linux = GCC" confusion in Rust's build system, but e.g. Chimera Linux uses an LLVM toolchain and has none of this stuff (other than perhaps this patch, but it seems to relate more to Musl).)

I am worried about adding to these hacks if we can't explain them, because when we start to move these yo principled toolchain conditions they will start to apply to Darwin and we will need to explain what they are actually conditioning on. I think there needs to be more work put into figuring out what the underlying problem with pkgsLLVM is before we extend workarounds that we already have no explanation for. I know there's at least one known issue there with the broken libgcc_s.so. If we're going to move our toolchain bootstrap and checks to be more granular and consistent then overriding stuff at random until it happens to build isn't the right approach.

@RossComputerGuy
Copy link
Member Author

I don't think it should be necessary to do any of this llvmPackages or llvmSharedFor stuff at all. Why wouldn't llvmPackages just work, even in pkgsLLVM?

Because when rust is a dependency, it comes from buildPackages. When that happens, llvmPackages comes from another stage. The problem which made the special llvmPackages is because things were linking to libstdc++ instead of libc++. This is because things were being accessed too deep.

I did find an easier solution to the cc for one of the overridden dependencies which prompted the first change. However, the libunwind stuff broke since lib.optional was used which made libunwind not discoverable.

@emilazy
Copy link
Member

emilazy commented Aug 15, 2025

If buildPackages uses libstdc++, then it's correct for the Rust compiler to link against it, right? Is this the problem where Rust can't distinguish between a build and host platform with the same target triple, or something else? It probably makes sense for pkgsLLVM to arrange for its buildPackages to use libc++, if it's intended to provide a "native" experience.

@RossComputerGuy
Copy link
Member Author

If buildPackages uses libstdc++, then it's correct for the Rust compiler to link against it, right?

No because it's linking from something like pkgsLLVM.buildPackages.hostPackages.llvmPackages. At that stage, it is pre-LLVM so it ends up not linking to libc++.

@@ -101,7 +101,7 @@ stdenv.mkDerivation (finalAttrs: {
(stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM)
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"
++ optional (stdenv.hostPlatform.isDarwin && !withBundledLLVM) "-lc++ -lc++abi"
++ optional stdenv.hostPlatform.isFreeBSD "-rpath ${llvmPackages.libunwind}/lib"
++ optional (useLLVM && !withBundledLLVM) "-rpath ${llvmPackages.libunwind}/lib"
Copy link
Contributor

Choose a reason for hiding this comment

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

In FreeBSD, we can try adding LLVM libunwind to buildInputs instead of setting rpath here. If moving libunwind to buildInputs works, we can remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/5785

@alyssais
Copy link
Member

I really don't think this is ready for review… It's blocked by a change request, and we're still waiting to find out why it works.

@RossComputerGuy
Copy link
Member Author

I thought we already knew the why:

  1. Funky splicing of buildPackages vs pkgs which causes useLLVM = false at some point, making libc++ not used
  2. libunwind was being provided by lib.optional () [] which causes it to not propagate

@alyssais
Copy link
Member

I thought we already knew the why:

Well last time I asked, I got "Idk how to explain why, it just does.", and the discussion since didn't seem particularly conclusive, still none of that information is in the commit message, and Emily's further probing on Matrix from earlier is still unresponded to, so I'm not sure how the reviewability is supposed to have changed here.

@RossComputerGuy
Copy link
Member Author

Emily's further probing on Matrix from earlier is still unresponded to

When was that? It might've been when I was at work or asleep.

@RossComputerGuy
Copy link
Member Author

still none of that information is in the commit message,

Updated the commit message

@alyssais
Copy link
Member

Emily's further probing on Matrix from earlier is still unresponded to

When was that? It might've been when I was at work or asleep.

https://matrix.to/#/!kxOJEqURGkuOHTRRQB:matrix.org/$jfJfEVIbG_BXOxjKQw4CMiQfwVWRVdrZrGkt_CVnCjk?via=matrix.org&via=nixos.dev&via=tchncs.de (it pinged you)

@emilazy
Copy link
Member

emilazy commented Aug 21, 2025

We add llvmPackages.libunwind to buildInputs depending on stdenv.targetPlatform.isLLVM. The libgcc_s hack aside, I don’t see how that can be correct – it should surely be either stdenv.hostPlatform.isLLVM or be a libunwind for the target platform.

Other than that, it seems like this is likely downstream of either or both of issues wiring up llvmPackages, and the Rust derivation’s confusion about cross. pkgsLLVM.buildPackages.hostPackages doesn’t exist, but assuming we’re talking about targetPackages instead, perhaps these lines are the culprit?

      ccForBuild = ccPrefixForStdenv pkgsBuildBuild.targetPackages.stdenv;
      cxxForBuild = cxxPrefixForStdenv pkgsBuildBuild.targetPackages.stdenv;
      ccForHost = ccPrefixForStdenv pkgsBuildHost.targetPackages.stdenv;
      cxxForHost = cxxPrefixForStdenv pkgsBuildHost.targetPackages.stdenv;
      ccForTarget = ccPrefixForStdenv pkgsBuildTarget.targetPackages.stdenv;
      cxxForTarget = cxxPrefixForStdenv pkgsBuildTarget.targetPackages.stdenv;

@RossComputerGuy
Copy link
Member Author

Emily's further probing on Matrix from earlier is still unresponded to

When was that? It might've been when I was at work or asleep.

https://matrix.to/#/!kxOJEqURGkuOHTRRQB:matrix.org/$jfJfEVIbG_BXOxjKQw4CMiQfwVWRVdrZrGkt_CVnCjk?via=matrix.org&via=nixos.dev&via=tchncs.de (it pinged you)

GOException: no routes for location: im.fluffychat://chat/! kxOJEqURGkuOHTRRQB:matrix.org

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 23, 2025
@RossComputerGuy
Copy link
Member Author

Rebased messed up

@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 24, 2025
@RossComputerGuy
Copy link
Member Author

Managed to do some testing and the funky llvmPackages magic we had is no longer needed afaict.

Fixes `libunwind` from not being included due to improper usage of
`lib.optional` by passing a list instead of a single item. Drops the
hack for `llvmPackages` since just passing it through works now.
@nixpkgs-ci nixpkgs-ci bot 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 Aug 25, 2025
Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

Great to see the hacks going away, thank you!

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 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. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure: rustc on LLVM stdenv
8 participants