Last active
January 14, 2020 17:04
-
-
Save Mic92/8016a0b1439e1bd7758416fab4c3e418 to your computer and use it in GitHub Desktop.
Build everything with clang and nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# i.e. nix-build -A hello | |
let | |
pkgs = (import <nixpkgs> {}); | |
in import <nixpkgs> { | |
overlays = [ | |
(self: super: { | |
stdenv = super.overrideCC pkgs.stdenv pkgs.llvmPackages_latest.lldClang; | |
}) | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# i.e. nix-build -A hello | |
let | |
pkgs = (import <nixpkgs> {}); | |
targetLlvmLibraries = pkgs.targetPackages.llvmPackages_latest.libraries; | |
release_version = "9.0.1"; | |
mkExtraBuildCommands = cc: with pkgs; '' | |
rsrc="$out/resource-root" | |
mkdir "$rsrc" | |
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc" | |
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" | |
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags | |
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && llvmPackages_latest.tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) '' | |
echo "--gcc-toolchain=${llvmPackages_latest.tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags | |
''; | |
lldClang = with pkgs; wrapCCWith rec { | |
cc = llvmPackages_latest.tools.clang-unwrapped.overrideAttrs (old: { | |
src = pkgs.fetchFromGithub { | |
owner = ""; | |
repo = ""; | |
rev = ""; | |
sha256 = ""; | |
}; | |
}); | |
libcxx = targetLlvmLibraries.libcxx; | |
bintools = wrapBintoolsWith { | |
inherit (llvmPackages_latest.tools) bintools; | |
}; | |
extraPackages = [ | |
targetLlvmLibraries.libcxx | |
targetLlvmLibraries.libcxxabi | |
targetLlvmLibraries.compiler-rt | |
] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [ | |
targetLlvmLibraries.libunwind | |
]; | |
extraBuildCommands = '' | |
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags | |
echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags | |
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags | |
'' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) '' | |
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags | |
'' + stdenv.lib.optionalString stdenv.targetPlatform.isWasm '' | |
echo "-fno-exceptions" >> $out/nix-support/cc-cflags | |
'' + mkExtraBuildCommands cc; | |
}; | |
in import <nixpkgs> { | |
overlays = [ | |
(self: super: { | |
#stdenv = super.overrideCC pkgs.stdenv (pkgs.llvmPackages_latest.lldClang); | |
stdenv = super.overrideCC pkgs.stdenv (lldClang); | |
}) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment