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

Detect whether compiler is Clang at nix eval time #216

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions toolchains/cc/cc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ let
pkgs.runCommand "bazel-nixpkgs-cc-wrapper"
{
buildInputs = [ pkgs.makeWrapper ];
passthru = {
isClang = pkgs.stdenv.cc.isClang;
};
}
''
mkdir -p $out/bin
Expand All @@ -41,17 +44,31 @@ let
else if ccType == "ccTypeExpression" then
ccExpr
else
pkgs.buildEnv {
name = "bazel-nixpkgs-cc";
# XXX: `gcov` is missing in `/bin`.
# It exists in `stdenv.cc.cc` but that collides with `stdenv.cc`.
paths =
if pkgs.stdenv.isDarwin then
[ (pkgs.overrideCC pkgs.stdenv darwinCC).cc pkgs.darwin.binutils ]
else
[ pkgs.stdenv.cc pkgs.binutils ];
pathsToLink = [ "/bin" ];
}
pkgs.buildEnv (
let
paths =
if pkgs.stdenv.isDarwin then
{
cc = (pkgs.overrideCC pkgs.stdenv darwinCC).cc;
binutils = pkgs.darwin.binutils;
}
else
{
cc = pkgs.stdenv.cc;
binutils = pkgs.binutils;
};
in
{
name = "bazel-nixpkgs-cc";
# XXX: `gcov` is missing in `/bin`.
# It exists in `stdenv.cc.cc` but that collides with `stdenv.cc`.
paths = [ paths.cc paths.binutils ];
pathsToLink = [ "/bin" ];
passthru = {
isClang = paths.cc.isClang;
};
}
)
;
in
pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
Expand Down Expand Up @@ -261,9 +278,7 @@ pkgs.runCommand "bazel-nixpkgs-cc-toolchain"
)
)
IS_CLANG=(
$(
${cc}/bin/cc -v 2>&1 | grep -q clang && echo True || echo False
)
${if cc.isClang then "True" else "False"}
)

# Write CC_TOOLCHAIN_INFO
Expand Down