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

llvmPackages_13.libcxx: fix darwin build #147289

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

midchildan
Copy link
Member

@midchildan midchildan commented Nov 24, 2021

Motivation for this change

This succeeds #146517. It fixes the Darwin build of libcxx by applying the following fixes:

  • Use a newer version of Clang to avoid compilation errors
  • Break the circular dependency between libcxx and libcxxabi. libcxxabi needs libcxx headers to build, but libcxx has a runtime dependency on libcxxabi. To fix this, this PR creates a header-only variant of the libcxx derivation for building libcxxabi.

The Linux build seems to have avoided the circular dependency problem by dropping the libcxx dependency on libcxxabi. This approach appears not to be possible on Darwin.

llvmPackages_git probably needs the same fix too, but I haven't looked into it closely yet.

ZHF: #144627

Things done

Like in #146517, I've tested on the master branch and rebased against staging to avoid the overwhelming amount of local builds.

  • 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/)
  • 21.11 Release Notes (or backporting 21.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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Nov 24, 2021
@midchildan
Copy link
Member Author

I'm marking this as draft because I found out that building llvmPackages_13 with llvmPackages_12 fixes libcxx, but breaks llvm.

building
'/nix/store/ba45qlpblgyabh8kl00d14fxzb8b1307-llvm-13.0.0/lib' -> '/private/tmp/nix-build-llvm-13.0.0.drv-1/source/llvm/build/lib'
build flags: -j4 -l4 SHELL=/nix/store/r42x7q316gznkm5y9b0cl4564g174zyl-bash-5.1-p8/bin/bash
[  0%] Generating VCSRevision.h
[  0%] Creating export file for LLVMHello
[  0%] Building CXX object utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/AsmMatcherEmitter.cpp.o
[  1%] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/Demangle.cpp.o
CMake Warning at /tmp/nix-build-llvm-13.0.0.drv-1/source/llvm/cmake/modules/VersionFromVCS.cmake:49 (message):
  Git not found.  Version cannot be determined.
Call Stack (most recent call first):
  /tmp/nix-build-llvm-13.0.0.drv-1/source/llvm/cmake/modules/GenerateVersionFromVCS.cmake:23 (get_source_info)
  /tmp/nix-build-llvm-13.0.0.drv-1/source/llvm/cmake/modules/GenerateVersionFromVCS.cmake:45 (append_info)


[  1%] Built target LLVMHello_exports
[  1%] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o
[  1%] Built target llvm_vcsrevision_h
[  1%] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o
[  1%] Building CXX object utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/PerfectShuffle.cpp.o
[  2%] Linking CXX executable ../../bin/llvm-PerfectShuffle
[  2%] Building C object utils/count/CMakeFiles/count.dir/count.c.o
Undefined symbols for architecture x86_64:
  "operator new(unsigned long)", referenced from:
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in PerfectShuffle.cpp.o
      Operator::Operator(unsigned short, char const*, unsigned int, unsigned int) in PerfectShuffle.cpp.o
  "operator delete(void*)", referenced from:
      std::__1::vector<Operator*, std::__1::allocator<Operator*> >::~vector() in PerfectShuffle.cpp.o
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in PerfectShuffle.cpp.o
      Operator::Operator(unsigned short, char const*, unsigned int, unsigned int) in PerfectShuffle.cpp.o
ld: symbol(s) not found for architecture x86_64
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/build.make:97: bin/llvm-PerfectShuffle] Error 1
make[1]: *** [CMakeFiles/Makefile2:25003: utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

@midchildan
Copy link
Member Author

This is now ready for review. LLVM, Clang, and libcxx all built successfully after I replaced llvmPackages_12.stdenv with llvmPackages_11.stdenv.

Comment on lines +53 to +55
pushd "$dev"
rmdir -p include/c++/v1
popd
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pushd "$dev"
rmdir -p include/c++/v1
popd
rmdir -p $dev/include/c++/v1

Copy link
Member Author

@midchildan midchildan Nov 25, 2021

Choose a reason for hiding this comment

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

I believe this would result in different behavior. I want the directories v1, c++, and include to be deleted in order while making sure that each of those directories are completely empty before deletion. The suggested change would also attempt to delete each path component in $dev too.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
@domenkozar
Copy link
Member

@toonn

Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

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

Looks like a good fix overall.

inherit llvm_meta;
stdenv = if stdenv.hostPlatform.useLLVM or false
libcxxabi = let
stdenv_ = if stdenv.hostPlatform.useLLVM or false
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what you want to do here is test stdenv.cc.isClang. useLLVM isn't true for Darwin, for example. (Unless that changed recently?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not exactly sure what the intention behind that conditional expression is, so I left it unchanged in this PR. Does your suggestion apply to other parts of the code too? I see the same conditional expression used everywhere throughout the LLVM packaging code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I guess leave it if you've tested it on Darwin anyway?

cxx-headers = callPackage ./libcxx {
inherit llvm_meta;
stdenv = stdenv_;
isCxxHeaders = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen headersOnly as the argument for triggering a headers only build a couple times, might be nice to align with that convention?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've now changed it to headersOnly.


outputs = [ "out" "dev" ];
outputs = [ "out" ] ++ lib.optional (!isCxxHeaders) "dev";
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be simpler if dev would be the single output when only building the headers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried, but it failed to evaluate when I did this.

nix-build -A llvmPackages_13.libcxx
these 3 derivations will be built:
  /nix/store/9za4wnq6g4kzls8kda2lma2axhppgis4-cxx-headers-13.0.0.drv
  /nix/store/yhfjvzqrz6d1rs8d7mfifsvm4i6c0rdd-libcxxabi-13.0.0.drv
  /nix/store/2c18dsqr57z2sl6bw0y85ziz44349jn7-libcxx-13.0.0.drv
building '/nix/store/9za4wnq6g4kzls8kda2lma2axhppgis4-cxx-headers-13.0.0.drv'...
Error: _assignFirst found no valid variant!

@@ -12578,6 +12578,8 @@ with pkgs;
targetLlvmLibraries = targetPackages.llvmPackages_13.libraries;
} // lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
stdenv = gcc7Stdenv;
} // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that the LLVM bump to 11 #126411 was just merged to staging so I don't think it's necessary to explicitly pick the LLVM version here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this change in the latest commit.

Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

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

LGTM, didn't have time to run test builds though.

@domenkozar domenkozar merged commit 845225e into NixOS:staging Nov 26, 2021
@github-actions
Copy link
Contributor

Backport failed for release-21.11, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-21.11
git worktree add -d .worktree/backport-147289-to-release-21.11 origin/release-21.11
cd .worktree/backport-147289-to-release-21.11
git checkout -b backport-147289-to-release-21.11
ancref=$(git merge-base d71611fb7221eaa8804a355ca22fadecacc4b9f6 7994b1dfc0a5431cbb4c052c740db8992045af8c)
git cherry-pick -x $ancref..7994b1dfc0a5431cbb4c052c740db8992045af8c

@rrbutani rrbutani added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 10.rebuild-darwin: 11-100 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants