Skip to content

llvmPackages_12: build from monorepo source#348568

Merged
emilazy merged 4 commits intoNixOS:stagingfrom
sternenseemann:llvm-12-monorepo
Nov 9, 2024
Merged

llvmPackages_12: build from monorepo source#348568
emilazy merged 4 commits intoNixOS:stagingfrom
sternenseemann:llvm-12-monorepo

Conversation

@sternenseemann
Copy link
Member

@sternenseemann sternenseemann commented Oct 14, 2024

As mentioned in #305146, keeping LLVM 12 is a source of pain because it
is the only version to be built from individual release tarball instead
of the LLVM monorepo. This change makes LLVM 12 start from the monorepo
as well, simplifying all common LLVM expressions in the process.
No more LLVM 12 specific default.nix!

Additionally, some additional, simple cleanups are included that just rebuild LLVM 12.
Consequently, this PR is best reviewed commit by commit.
The common default.nix's patch logic can further be simplified by a separate change
that rebuilds all LLVM versions.

This change is not breaking and could be included in 24.11 (or backported if we miss
the window) which seems wise. I've tested LLVM 12 on x86_64-linux and aarch64-linux.
I've also tested GHC 8.10.7 (which uses LLVM 12) on aarch64-linux.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • 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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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.

@sternenseemann sternenseemann requested a review from a team October 14, 2024 16:41
@github-actions github-actions bot added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label Oct 14, 2024
@RossComputerGuy
Copy link
Member

pkgs/development/compilers/llvm/12/default.nix is gone 🎉

pkgs/development/compilers/llvm/common/llvm/default.nix has conflicts.

@sternenseemann sternenseemann force-pushed the llvm-12-monorepo branch 2 times, most recently from dda8d8a to a475c8b Compare October 14, 2024 17:02
@sternenseemann
Copy link
Member Author

I'm going to re-test everything, now that everything is rebased on staging, just to be sure.

@RossComputerGuy
Copy link
Member

lldb in LLVM 12 failed to resolve the cpu_subtype_arm64e_replacement patch.

@sternenseemann
Copy link
Member Author

x86_64-linux builds fine, but aarch64-darwin doesn't. It appears that it is already broken in some way before this change. Is anyone aware of any details?

@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 8.has: package (new) This PR adds a new package 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 Oct 15, 2024
@sternenseemann
Copy link
Member Author

@reckenrode Any ideas about the followng error (staging, aarch64-darwin, llvmPackages_12.libcxx)?

-- Check for working CXX compiler: /nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++
-- Check for working CXX compiler: /nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++ - broken
CMake Error at /nix/store/xl246ny58q2xm0w7srsjkkd1j3f7hakg-cmake-3.30.4/share/cmake-3.30/Modules/CMakeTestCXXCompiler.cmake:73 (message):
  The C++ compiler

    "/nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/tmp/nix-build-libcxx-12.0.1.drv-0/libcxx-src-12.0.1/runtimes/build/CMakeFiles/CMakeScratch/TryCompile-Ul4rVU'
    
    Run Build Command(s): /nix/store/6qaz2a5vrp8bv8wyjcyfkmssxdcbdc2d-ninja-1.12.1/bin/ninja -v cmTC_70287
    [1/2] /nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++   -isysroot /nix/store/9qf26qdqy34chms1vx44w2cm7mjg46nh-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -MD -MT CMakeFiles/cmTC_70287.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_70287.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_70287.dir/testCXXCompiler.cxx.o -c /tmp/nix-build-libcxx-12.0.1.drv-0/libcxx-src-12.0.1/runtimes/build/CMakeFiles/CMakeScratch/TryCompile-Ul4rVU/testCXXCompiler.cxx
    [2/2] : && /nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++ -isysroot /nix/store/9qf26qdqy34chms1vx44w2cm7mjg46nh-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_70287.dir/testCXXCompiler.cxx.o -o cmTC_70287   && :
    FAILED: cmTC_70287 
    : && /nix/store/7qfjlhi98568y1ff5xy93607dgn3lfw8-clang-wrapper-12.0.1/bin/clang++ -isysroot /nix/store/9qf26qdqy34chms1vx44w2cm7mjg46nh-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_70287.dir/testCXXCompiler.cxx.o -o cmTC_70287   && :
    ld: library not found for -lc++
    clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

Interestingly, before my PR, compilation fails later, in compiler-rt-libc. That error is also a mystery to me.

@reckenrode
Copy link
Contributor

reckenrode commented Oct 15, 2024

Interestingly, before my PR, compilation fails later, in compiler-rt-libc. That error is also a mystery to me.

Darwin needed to use buildLlvmPackages.clangWithLibcAndBasicRtAndLibcxx, which it wasn’t before in the separate derivation. It does in the common one.

Any ideas about the followng error (staging, aarch64-darwin, llvmPackages_12.libcxx)?

Its test for a working C++ compiler appears to be trying to link libc++ even though libcxx is building with buildLlvmPackages.clangWithLibcAndBasicRt, which does not have libc++. Before the derivations were unified, libcxx on Darwin was built with a standard stdenv that has libc++.

Does it build if you deaddine "-DCMAKE_CXX_COMPILER_WORKS=ON" to cmakeFlags on Darwin for libcxx-12?

@ofborg ofborg bot removed the 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. label Oct 15, 2024
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. and removed 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. labels Oct 15, 2024
@emilazy
Copy link
Member

emilazy commented Nov 8, 2024

OK. I believe we haven’t yet done an eval with the haskell-updates merge on staging-next anyway, so as long as this is rebased soon I think it should be fine to land directly in staging-next for 24.11. (Though I’m double checking in the Staging room to make sure I’m reading Hydra right.)

We just need to make sure the attribute evaluates so we can cleanly
access `meta.broken` for those versions.
As mentioned in NixOS#305146, keeping LLVM 12 is a source of pain because it
is the only version to be built from individual release tarball instead
of the LLVM monorepo. This commit makes LLVM 12 start from the monorepo
as well, simplifying all common LLVM expressions in the process.

With NixOS#347887, some quirks in the expressions for LLVM <14 were ironed
out, so building LLVM through from the monorepo is quite simple now.

- Most expressions only required minor changes, mostly removing the
  special casing for `sourceRoot`.

- The patch lists from llvm/12/default.nix were ported to
  common/default.nix. This only required a few extra conditionals which
  could be reduced via a rebuild also involving other LLVM versions.
  Outstanding tasks of little urgency have been noted in TODO comments.
  I have verified that the patch lists stay the same for all packages
  except LLVM where merely the order changes. An extra set of eyes
  is appreciated, of course.

- clang: The expression was reworked to use the same symlink location
  for clang-tools-extra for all versions including LLVM 12. This
  required adjusting the ad hoc patching of the clangd cmake files
  slightly.

- libunwind: We no longer need to make the libcxx sources available
  manually. We can rely on the monorepo source instead.

- lld: We no longer need to make the libunwind sources available manually.

- llvm: We no longer need to make the polly sources available manually

- On Darwin, we need to bypass CMake's C++ compiler for libcxx and
  libunwind now. It isn't a 100% clear why, probably because we've
  started to use Darwin's bootstrapStdenv for libcxx in the common
  expression compared to LLVM 12 on master [1].
  The reordering of flags for wasm causes a rebuild for some packages
  like firefox, but this should be tolerable on staging.

[1]: https://github.com/NixOS/nixpkgs/blob/665ebfb253caba7b85c2affefe2a92b305def4e6/pkgs/development/compilers/llvm/12/default.nix#L392-L430
All LLVM versions < 12 have been removed, so this patch can live in the
versioned directory, simplifying the patch list in the process.
Seems like the patch we've written for LLVM 13 and above also works for
LLVM 12 which seems a little more robust.
@sternenseemann
Copy link
Member Author

Rebased, but currently untested. I'd at least want to look at ofborg's rebuild overview before merging.

@Ericson2314
Copy link
Member

Glad this is happening! :)

@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 8, 2024
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 9, 2024
@emilazy
Copy link
Member

emilazy commented Nov 9, 2024

Builds on the community builders, only 220 rebuilds outside of aarch64-linux, and those look as expected for being downstream of Haskell packages that we just merged a huge rebuild of anyway. Going to merge this into -next.

@emilazy emilazy changed the base branch from staging to staging-next November 9, 2024 06:07
@emilazy emilazy changed the base branch from staging-next to staging November 9, 2024 06:10
@emilazy
Copy link
Member

emilazy commented Nov 9, 2024

Realized that actually the haskell-updates had already hit staging-next and that the revert/unrevert dance was just because it hit the trunk job a few days later. So I’m going to merge this into staging for 25.05 after all and we can backport it after branch‐off.

@emilazy emilazy merged commit 40a6c76 into NixOS:staging Nov 9, 2024
@sternenseemann sternenseemann deleted the llvm-12-monorepo branch November 9, 2024 11:31
@sternenseemann
Copy link
Member Author

I had a failure in llvmPackages_12.compiler-rt on aarch64-darwin about a symlink failing to be created because it already existed, but I can't reproduce it. I suppose there's a race condition in the build system.

@github-actions
Copy link
Contributor

Successfully created backport PR for staging-24.11:

@paparodeo
Copy link
Contributor

I had a failure in llvmPackages_12.compiler-rt on aarch64-darwin about a symlink failing to be created because it already existed, but I can't reproduce it. I suppose there's a race condition in the build system.

llvm/llvm-project@b31080c looks like it fixes the race

(cd tools && ln -s ../../clang-tools-extra extra)
'' + lib.optionalString (lib.versionOlder release_version "13") ''
substituteInPlace tools/extra/clangd/quality/CompletionModel.cmake \
--replace ' ''${CMAKE_SOURCE_DIR}/../clang-tools-extra' ' ''${CMAKE_SOURCE_DIR}/tools/extra'
Copy link
Contributor

Choose a reason for hiding this comment

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

@sternenseemann

#356120 (--replace-fail) broke this one on clang 12 (staging 03ed65c).

The path tools/extra doesn't exist; the only reference to it I could find is in the deleted diff hunk which appears after this one. I take it you somehow separated out clang-tools-extra from this derivation and therefore it is vestigial and can be removed. Correct?

Copy link
Contributor

@pwaller pwaller Dec 20, 2024

Choose a reason for hiding this comment

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

Oh no, wait, I see (cd tools && ln -s ../../clang-tools-extra extra) retained in this diff which I missed. Hmm.

Copy link
Contributor

Choose a reason for hiding this comment

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

Found it, it's vestigial because the patch which removed CMAKE_SOURCE_DIR was removed in 12.0.1:
llvm/llvm-project@3be5dbb

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't comment much more, I've just tried to preserve all the parts of the phases in the original LLVM 12 expressions. They may have been unnecessarily copied from earlier versions, yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fix for llvm 12: #367056

pwaller added a commit to pwaller/nixpkgs that referenced this pull request Dec 21, 2024
…l.cmake

Fix up NixOS#356120 for clang 12. The failing replacement target was removed
between llvm 12.0.0 and 12.0.1.

Ref: NixOS#348568 (comment)
Ref: llvm/llvm-project@3be5dbb
Signed-off-by: Peter Waller <[email protected]>
alyssais pushed a commit that referenced this pull request Dec 22, 2024
…l.cmake

Fix up #356120 for clang 12. The failing replacement target was removed
between llvm 12.0.0 and 12.0.1.

Ref: #348568 (comment)
Ref: llvm/llvm-project@3be5dbb
Signed-off-by: Peter Waller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants