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

libcxxClang doesn't seem to work as a toolchain #445

Open
iphydf opened this issue Nov 12, 2023 · 3 comments
Open

libcxxClang doesn't seem to work as a toolchain #445

iphydf opened this issue Nov 12, 2023 · 3 comments
Labels
P4 unimportant: consider wontfix or other priority type: bug

Comments

@iphydf
Copy link

iphydf commented Nov 12, 2023

Describe the bug
Using clang with libc++ fails to find <cxxabi.h>.

To Reproduce
Use the following in WORKSPACE:

nixpkgs_cc_configure(
    attribute_path = "llvmPackages_16.libcxxClang",
    repository = "@nixpkgs",
)

Try to compile something that includes cxxabi.h (e.g. googletest) and observe:

external/com_google_googletest/googletest/include/gtest/internal/gtest-type-util.h:49:10: fatal error: 'cxxabi.h' file not found
#include <cxxabi.h>
         ^~~~~~~~~~
1 error generated.

Expected behavior
Compilation should succeed.

Environment

  • OS name + version: NixOS 23.05
  • Version of the code: 0.10.0 (loaded by rules_haskell).

Additional context
These files definitely exist:

/nix/store/6bi80vsz2aa0r5j9y16pcz3gkmx80qfj-libcxxabi-16.0.1-dev/include/cxxabi.h
/nix/store/6bi80vsz2aa0r5j9y16pcz3gkmx80qfj-libcxxabi-16.0.1-dev/include/c++/v1/cxxabi.h
@avdv
Copy link
Member

avdv commented Nov 13, 2023

Is this the same problem as NixOS/nixpkgs#150655 ?

Ie. does passing --cxxopt=-x --cxxopt=c++ help?

@iphydf
Copy link
Author

iphydf commented Nov 14, 2023

No, all other C++ standard library headers can be found. Also, -x c++ was already passed by the toolchain. I can see:

/nix/store/y02xngjcbhfgliijh2wnpksc3dqhva56-clang-wrapper-16.0.1/bin/cc -U_FORTIFY_SOURCE -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -x c++ '-std=c++0x' -MD -MF [...]

@avdv
Copy link
Member

avdv commented Nov 15, 2023

I think this is a consequence of nixpkgs having split the toolchain into different packages and libcxxabi not directly being part of the toolchain by default.

A nix-shell provides an environment where these packages are combined again, using the NIX_CFLAGS_COMPILE / NIX_LDFLAGS variables which are respected by the clang wrapper.

Although this is also not enough, when trying to run nix-shell -p llvmPackages_16.libcxxClang --run "clang++ -E - <<<'#include <cxxabi.h>' > /dev/null" it bails out with

In file included from <stdin>:1:
/nix/store/8qwwfr56i3sy5b22a0njp4k3anrqb8c2-libcxxabi-16.0.6-dev/include/cxxabi.h:20:10: fatal error: '__cxxabi_config.h' file not found
#include <__cxxabi_config.h>
         ^~~~~~~~~~~~~~~~~~~
1 error generated.

You could make this work by using wrapCCWith, like this:

# Work around https://github.com/NixOS/nixpkgs/issues/42059.
# See also https://github.com/NixOS/nixpkgs/pull/41589.
pkgs.wrapCCWith rec {
cc = stdenv.cc.cc;
bintools = stdenv.cc.bintools.override { inherit postLinkSignHook; };
extraBuildCommands = with pkgs.darwin.apple_sdk.frameworks; ''
echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
echo "-Wno-elaborated-enum-base" >> $out/nix-support/cc-cflags
echo "-isystem ${pkgs.llvmPackages.libcxx.dev}/include/c++/v1" >> $out/nix-support/cc-cflags
echo "-isystem ${pkgs.llvmPackages.clang-unwrapped.lib}/lib/clang/${cc.version}/include" >> $out/nix-support/cc-cflags
echo "-F${CoreFoundation}/Library/Frameworks" >> $out/nix-support/cc-cflags
echo "-F${CoreServices}/Library/Frameworks" >> $out/nix-support/cc-cflags
echo "-F${Security}/Library/Frameworks" >> $out/nix-support/cc-cflags
echo "-F${Foundation}/Library/Frameworks" >> $out/nix-support/cc-cflags
echo "-L${pkgs.llvmPackages.libcxx}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.llvmPackages.libcxxabi}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.libiconv}/lib" >> $out/nix-support/cc-cflags
echo "-L${pkgs.darwin.libobjc}/lib" >> $out/nix-support/cc-cflags
echo "-resource-dir=${pkgs.stdenv.cc}/resource-root" >> $out/nix-support/cc-cflags
'';
};

Adding in any library and include directories needed.

I am not sure how we could provide a better experience here, we probably would have to run the setupHooks somehow in order to realize the env variables so that the resulting paths would be reflected in the toolchain.

@malt3 malt3 added type: bug P4 unimportant: consider wontfix or other priority labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 unimportant: consider wontfix or other priority type: bug
Projects
None yet
Development

No branches or pull requests

3 participants