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

llvm8: support c++ in cross case #59338

Merged
merged 2 commits into from Apr 12, 2019
Merged

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Apr 12, 2019

this adds libc++ to the LLVM cross, giving us access to the full
Nixpkgs set. This requires 4 stages of wrapped compilers:

  • Clang with no libraries
  • Clang with just compiler-rt
  • Clang with Libc, and compiler-rt
  • Clang with Libc++, Libc, and compiler-rt
Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nix-review --run "nix-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)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Test:

with import ./default.nix {
  crossSystem = (import ./lib).systems.examples.aarch64-multiplatform-musl // {useLLVM = true;};
};
let
cpp = builtins.toFile "test.c++" ''
#include <iostream>

int main() {
  std::cout << "Hello world!" << std::endl;
}
'';
testdrv = { callPackage, stdenv, llvmPackages_8 }: stdenv.mkDerivation
    {
        name = "cross-test";
        version = "0.1";
        unpackPhase = "true";
        buildInputs = [llvmPackages_8.libunwind];
        buildPhase = ''
            $CXX -lunwind -o test ${cpp}
        '';
        installPhase = ''
            mkdir -p $out/bin
            cp test $out/bin/test
            ${stdenv.hostPlatform.emulator buildPackages} $out/bin/test
        '';
    };
in callPackage testdrv {}

this adds libc++ to the LLVM cross, giving us access to the full
Nixpkgs set. This requires 4 stages of wrapped compilers:

- Clang with no libraries
- Clang with just compiler-rt
- Clang with Libc, and compiler-rt
- Clang with Libc++, Libc, and compiler-rt
# pulled in. As a consequence, it is very quick to build different
# targets provided by LLVM and we can also build for what GCC
# doesn’t support like LLVM. Probably we should move to some other
# file.
Copy link
Member

Choose a reason for hiding this comment

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

If we have libc, libcxx, librt, and libunwind attributes in cc-wrapper, I think most of this logic could move there even though some it is clang-specific.

Copy link
Member Author

Choose a reason for hiding this comment

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

You would still need the 4 ccs though right?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps but it could arise organically like:

{
# all-packages.nix
libc = ...;
librt = ...;
}
{
# llvm default.nix
xxx = ... (stdenvNoLlibs.override {
  foo = libraries.noNull; 
}) ...;
}

@Ericson2314
Copy link
Member

Pushed a WIP thing with unwind to my own repo, but it didn't work right off the bat.

Backport the `--unwindlib` flag, so it don't try to use libgcc on Linux
for hysterical reasons. The alternative of passing `-lunwind` always
would mess up C.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants