Skip to content

stdenv/darwin: enable tapi support in cctools #93912

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

Merged
merged 2 commits into from
Sep 11, 2020

Conversation

thefloweringash
Copy link
Member

@thefloweringash thefloweringash commented Jul 26, 2020

Motivation for this change

Working towards #19906 with the overall goal of Big Sur compatibility via .tbd files.

Comes with the unfortunate downside of requiring clang_6 to build the stdenv, which increases the time required.

  • Tested:
    • nix-build -A hello
    • nix-build pkgs/stdenv/darwin/make-bootstrap-tools.nix -A test

cc @matthewbauer

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added 6.topic: darwin Running or building packages on Darwin 6.topic: stdenv Standard environment 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. labels Jul 26, 2020
@ofborg ofborg bot requested a review from matthewbauer July 26, 2020 13:08
@ofborg ofborg bot added 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: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jul 26, 2020

# ncurses is required here to avoid a reference to bootstrap-tools, which is
# not allowed for the stdenv.
buildInputs = [ ncurses clang_6.cc ];
Copy link
Member

Choose a reason for hiding this comment

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

We should really get this to build with the current compiler if it's enabled by default, bootstrapping multiple versions is a huge pain and llvm 6 is already quite old at this point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking closer, I don't think clang is intended to be an external dependency. I've pushed an update but I'm still waiting for it to test building stdenv locally.

@LnL7
Copy link
Member

LnL7 commented Jul 27, 2020

I see there's a link to 1100.0.11 here https://opensource.apple.com/release/developer-tools-1131.html, while it's currently broken it seems like a good indication that apple intends to publish the sources for the new version.

installTarget looks like a typo for installTargets. This causes a lot
of llvm and clang to be built and installed.

Clang is not intended to be an external dependency. The source bundle
includes llvm and clang. Adding include paths and building clangBasic
first is sufficient to use the internal clang components.
@thefloweringash
Copy link
Member Author

I see there's a link to 1100.0.11 here https://opensource.apple.com/release/developer-tools-1131.html, while it's currently broken it seems like a good indication that apple intends to publish the sources for the new version.

I sent an email to the listed address but no reply yet.

@thefloweringash
Copy link
Member Author

Tests for the updated libtapi finished building, seems ok. Updated main comment.

nativeBuildInputs = [ cmake python3 ];
buildInputs = [ clang_6.cc ];
Copy link
Member

Choose a reason for hiding this comment

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

i can't remember why clang_6 was needed here - but if everything builds correctly it sounds good to remove

Copy link
Member Author

Choose a reason for hiding this comment

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

This project seems to be intended to be built from its source tree without an external clang. The source tree includes the parts of clang that are required. I didn't look at exactly how much is included or built, but the build is a lot shorter than a full llvm/clang build.

Taking clang out of the build inputs required adding clangBasic to the built targets to generate the required headers (compare to upstream) and fixing the include directories to include the generated headers (compare to upstream). The external clang was probably filling in these holes in the build system.

'';

cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ];
buildFlags = [ "clangBasic" "libtapi" ];
Copy link
Member

Choose a reason for hiding this comment

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

do you need clangBasic here? we're already building it elsewhere, so i was hoping we could leave it off

Copy link
Member Author

Choose a reason for hiding this comment

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

This is required after removing clang_6.cc from buildInputs. I'm guessing it's an undeclared dependency in the build system. If this isn't specified then the build fails with:

  In file included from /tmp/nix-build-libtapi-1000.10.8.drv-0/source/src/llvm/projects/libtapi/lib/Core/Architecture.cpp:18:
  In file included from /private/tmp/nix-build-libtapi-1000.10.8.drv-0/source/src/llvm/projects/clang/include/clang/Basic/Diagnostic.h:18:
  /private/tmp/nix-build-libtapi-1000.10.8.drv-0/source/src/llvm/projects/clang/include/clang/Basic/DiagnosticIDs.h:71:10: fatal error: 'clang/Basic/DiagnosticCommonKinds.inc' file not found
  #include "clang/Basic/DiagnosticCommonKinds.inc"
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.

we're already building it elsewhere, so i was hoping we could leave it off

I'm making a bit of an assumption that "clangBasic" is a small internal clang target and not something that should be shared between builds, but a quick web search doesn't show up documentation for what it contains. The library definition is fairly small.

@@ -100,6 +100,8 @@ in rec {
cp ${cctools_}/bin/$i $out/bin
done

cp -d ${darwin.libtapi}/lib/libtapi* $out/lib
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually needed? If so, we will have to regenerate bootstrap tools

Copy link
Member Author

Choose a reason for hiding this comment

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

libtapi is enabled everywhere, so the ld that's included in the bootstrap tools now depends on libtapi. The intent is to make sure that the bootstrap tools can be updated, but this change doesn't require a bootstrap tools update.

Removing this causes

$ nix-build pkgs/stdenv/darwin/make-bootstrap-tools.nix -A test
[...]
dyld: Library not loaded: @rpath/libtapi.dylib
  Referenced from: /nix/store/ym4nscqv1h7sxn6b6dby0i4106lcw9sr-unpack/bin/ld
  Reason: image not found

I do want to regenerate the bootstrap tools as part of my overall goals. Next step is a .tbd based libSystem which I have on a branch. It can link hello on Big Sur, but there's still a decent amount of work before I can open that as a PR.

@matthewbauer
Copy link
Member

Looks good! I think it may cause conflicts with #93596 but this one is small enough to go first.

@thefloweringash
Copy link
Member Author

I'm interested in advancing this as a step towards a Big Sur compatible stdenv. Is there anything I can do to help get this merged?

@matthewbauer matthewbauer requested a review from LnL7 August 19, 2020 01:29
@matthewbauer
Copy link
Member

It looks good to me. Maybe @LnL7 could rereview though.

@thefloweringash
Copy link
Member Author

thefloweringash commented Aug 20, 2020

I noticed this was causing a large amount of extra building in stage 4 by building a full cmake. I've pushed an updated version that avoids this by reusing cmake in stage 4. This change now only introduces a build of libtapi in stage 1 and stage 4. I've attempted to show the changes in the history of a gist.

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: stdenv Standard environment 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-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants