Skip to content

Commit

Permalink
llvmPackages: Multuple outputs for everythting
Browse files Browse the repository at this point in the history
Also begin to start work on cross compilation, though that will have to
be finished later.

The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.

Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.

----

Other misc notes, highly incomplete

- lvm-config-native and llvm-config are put in `dev` because they are
  tools just for build time.

- Clang no longer has an lld dep. That was introduced in
  db29857, but if clang needs help
  finding lld when it is used we should just pass it flags / put in the
  resource dir. Providing it at build time increases critical path
  length for no good reason.

----

A note on `nativeCC`:

`stdenv` takes tools from the previous stage, so:

1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`

while:

1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
  • Loading branch information
thefloweringash authored and Ericson2314 committed Apr 30, 2021
1 parent 17a8c9c commit 7869d16
Show file tree
Hide file tree
Showing 210 changed files with 10,414 additions and 660 deletions.
2 changes: 1 addition & 1 deletion pkgs/applications/blockchains/electrs.nix
Expand Up @@ -17,7 +17,7 @@ rustPlatform.buildRustPackage rec {

# needed for librocksdb-sys
nativeBuildInputs = [ llvmPackages.clang ];
LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";

cargoSha256 = "1rqpadlr9r4z2z825li6vi5a21hivc3bsn5ibxshrdrwiycyyxz8";

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/blockchains/openethereum/default.nix
Expand Up @@ -23,7 +23,7 @@ rustPlatform.buildRustPackage rec {

cargoSha256 = "1gm02pcfll362add8a0dcb0sk0mag8z0q23b87yb6fs870bqvhib";

LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
nativeBuildInputs = [
cmake
llvmPackages.clang
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/blockchains/polkadot/default.nix
Expand Up @@ -20,7 +20,7 @@ rustPlatform.buildRustPackage rec {

nativeBuildInputs = [ clang ];

LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
PROTOC = "${protobuf}/bin/protoc";

# NOTE: We don't build the WASM runtimes since this would require a more
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/editors/jucipp/default.nix
Expand Up @@ -56,8 +56,8 @@ stdenv.mkDerivation rec {
e = "\");";
v = lib.getVersion llvmPackages.clang;
in
p+llvmPackages.libcxx+"/include/c++/v1"+e
+p+llvmPackages.clang-unwrapped+"/lib/clang/"+v+"/include/"+e
p+llvmPackages.libcxx.dev+"/include/c++/v1"+e
+p+llvmPackages.clang-unwrapped.lib+"/lib/clang/"+v+"/include/"+e
+p+glibc.dev+"/include"+e;

preConfigure = ''
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/editors/kdevelop5/kdevelop.nix
Expand Up @@ -23,7 +23,7 @@ mkDerivation rec {

buildInputs = [
kdevelop-pg-qt
llvmPackages.llvm llvmPackages.clang-unwrapped
llvmPackages.llvm llvmPackages.libclang
];

propagatedBuildInputs = [
Expand All @@ -37,7 +37,7 @@ mkDerivation rec {
# https://cgit.kde.org/kdevelop.git/commit/?id=716372ae2e8dff9c51e94d33443536786e4bd85b
# required as nixos seems to be unable to find CLANG_BUILTIN_DIR
cmakeFlags = [
"-DCLANG_BUILTIN_DIR=${llvmPackages.clang-unwrapped}/lib/clang/${lib.getVersion llvmPackages.clang}/include"
"-DCLANG_BUILTIN_DIR=${llvmPackages.libclang.lib}/lib/clang/${lib.getVersion llvmPackages.clang}/include"
];

dontWrapQtApps = true;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/rstudio/clang-location.patch
Expand Up @@ -7,7 +7,7 @@ index ec12a3a1ff..8c81b633ae 100644
// we need to add in the associated libclang headers as
// they are not discovered / used by default during compilation
- FilePath llvmPath = s_libraryPath.parent().parent();
+ FilePath llvmPath("@clang@");
+ FilePath llvmPath("@libclang@");
boost::format fmt("%1%/lib/clang/%2%/include");
fmt % llvmPath.absolutePath() % version.asString();
std::string includePath = fmt.str();
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/editors/rstudio/default.nix
Expand Up @@ -42,8 +42,8 @@ mkDerivation rec {
postPatch = ''
substituteInPlace src/cpp/core/r_util/REnvironmentPosix.cpp --replace '@R@' ${R}
substituteInPlace src/cpp/core/libclang/LibClang.cpp \
--replace '@clang@' ${llvmPackages.clang.cc} \
--replace '@libclang.so@' ${llvmPackages.clang.cc.lib}/lib/libclang.so
--replace '@libclang@' ${llvmPackages.libclang.lib} \
--replace '@libclang.so@' ${llvmPackages.libclang.lib}/lib/libclang.so
'';

ginSrc = fetchurl {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/clipcat/default.nix
Expand Up @@ -14,7 +14,7 @@ rustPlatform.buildRustPackage rec {

cargoSha256 = "1ffgvhkdj8wkhlgi0cj0njdm9ycxq2qda4b5qn8bmaygzr2zkwpd";

LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";

# needed for internal protobuf c wrapper library
PROTOC = "${protobuf}/bin/protoc";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/imag/default.nix
Expand Up @@ -26,7 +26,7 @@ rustPlatform.buildRustPackage rec {
++ lib.optional stdenv.isDarwin Security;
checkInputs = [ gitMinimal util-linuxMinimal ];

LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";

cargoSha256 = "0n8cw70qh8g4hfwfaxwwxbrrx5hm2z037z8kdhvdpqkxljl9189x";

Expand Down
6 changes: 3 additions & 3 deletions pkgs/applications/networking/browsers/firefox/common.nix
Expand Up @@ -248,8 +248,8 @@ buildStdenv.mkDerivation ({
$(< ${buildStdenv.cc}/nix-support/libc-cflags) \
$(< ${buildStdenv.cc}/nix-support/cc-cflags) \
$(< ${buildStdenv.cc}/nix-support/libcxx-cxxflags) \
${lib.optionalString buildStdenv.cc.isClang "-idirafter ${buildStdenv.cc.cc}/lib/clang/${lib.getVersion buildStdenv.cc.cc}/include"} \
${lib.optionalString buildStdenv.cc.isGNU "-isystem ${buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc} -isystem ${buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc}/${buildStdenv.hostPlatform.config}"} \
${lib.optionalString buildStdenv.cc.isClang "-idirafter ${buildStdenv.cc.cc.lib}/lib/clang/${lib.getVersion buildStdenv.cc.cc}/include"} \
${lib.optionalString buildStdenv.cc.isGNU "-isystem ${lib.getDev buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc} -isystem ${buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc}/${buildStdenv.hostPlatform.config}"} \
$NIX_CFLAGS_COMPILE"
echo "ac_add_options BINDGEN_CFLAGS='$BINDGEN_CFLAGS'" >> $MOZCONFIG
Expand Down Expand Up @@ -282,7 +282,7 @@ buildStdenv.mkDerivation ({
"--disable-updater"
"--enable-jemalloc"
"--enable-default-toolkit=${default-toolkit}"
"--with-libclang-path=${llvmPackages.libclang}/lib"
"--with-libclang-path=${llvmPackages.libclang.lib}/lib"
"--with-system-nspr"
"--with-system-nss"
]
Expand Down
Expand Up @@ -244,7 +244,7 @@ stdenv.mkDerivation rec {
"--enable-strip"
]) ++ lib.optionals (!stdenv.hostPlatform.isi686) [
# on i686-linux: --with-libclang-path is not available in this configuration
"--with-libclang-path=${llvmPackages.libclang}/lib"
"--with-libclang-path=${llvmPackages.libclang.lib}/lib"
"--with-clang-path=${llvmPackages.clang}/bin/clang"
] ++ lib.optional alsaSupport "--enable-alsa"
++ lib.optional calendarSupport "--enable-calendar"
Expand Down
Expand Up @@ -242,7 +242,7 @@ stdenv.mkDerivation rec {
"--enable-strip"
]) ++ lib.optionals (!stdenv.hostPlatform.isi686) [
# on i686-linux: --with-libclang-path is not available in this configuration
"--with-libclang-path=${llvmPackages.libclang}/lib"
"--with-libclang-path=${llvmPackages.libclang.lib}/lib"
"--with-clang-path=${llvmPackages.clang}/bin/clang"
] ++ lib.optional alsaSupport "--enable-alsa"
++ lib.optional calendarSupport "--enable-calendar"
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/science/math/R/default.nix
Expand Up @@ -68,8 +68,8 @@ stdenv.mkDerivation rec {
'' + lib.optionalString stdenv.isDarwin ''
--disable-R-framework
OBJC="clang"
CPPFLAGS="-isystem ${libcxx}/include/c++/v1"
LDFLAGS="-L${libcxx}/lib"
CPPFLAGS="-isystem ${lib.getDev libcxx}/include/c++/v1"
LDFLAGS="-L${lib.getLib libcxx}/lib"
'' + ''
)
echo >>etc/Renviron.in "TCLLIBPATH=${tk}/lib"
Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/cc-wrapper/default.nix
Expand Up @@ -370,7 +370,7 @@ stdenv.mkDerivation {
done
''
+ optionalString (libcxx.isLLVM or false) (''
echo "-isystem ${libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-isystem ${lib.getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
'' + lib.optionalString stdenv.targetPlatform.isLinux ''
echo "-lc++abi" >> $out/nix-support/libcxx-ldflags
Expand Down Expand Up @@ -404,7 +404,7 @@ stdenv.mkDerivation {
echo "$ccLDFlags" >> $out/nix-support/cc-ldflags
echo "$ccCFlags" >> $out/nix-support/cc-cflags
'' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) ''
echo " -L${libcxx}/lib" >> $out/nix-support/cc-ldflags
echo " -L${lib.getLib libcxx}/lib" >> $out/nix-support/cc-ldflags
''

##
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/rust/default-crate-overrides.nix
Expand Up @@ -92,7 +92,7 @@ in
nettle-sys = attrs: {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ nettle clang ];
LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
};

openssl = attrs: {
Expand Down
Expand Up @@ -18,7 +18,7 @@ let
inherit spirv-llvm-translator;
};
inherit (llvmPkgs) llvm;
inherit (if buildWithPatches then opencl-clang else llvmPkgs) clang clang-unwrapped spirv-llvm-translator;
inherit (if buildWithPatches then opencl-clang else llvmPkgs) clang libclang spirv-llvm-translator;
inherit (lib) getVersion optional optionals versionOlder versions;
in

Expand Down Expand Up @@ -55,7 +55,7 @@ stdenv.mkDerivation rec {
ln -s ${clang}/bin/clang $out/
ln -s clang $out/clang-${versions.major (getVersion clang)}
ln -s ${opencl-clang}/lib/* $out/
ln -s ${clang-unwrapped}/lib/clang/${getVersion clang}/include/opencl-c.h $out/
ln -s ${lib.getLib libclang}/lib/clang/${getVersion clang}/include/opencl-c.h $out/
'';
};

Expand Down
23 changes: 16 additions & 7 deletions pkgs/development/compilers/llvm/10/clang/default.nix
@@ -1,4 +1,5 @@
{ lib, stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld
{ lib, stdenv, fetch, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3
, buildLlvmTools
, fixDarwinDylibNames
, enableManpages ? false
}:
Expand All @@ -18,28 +19,33 @@ let
mv clang-tools-extra-* $sourceRoot/tools/extra
'';

nativeBuildInputs = [ cmake python3 lld ]
nativeBuildInputs = [ cmake python3 ]
++ lib.optional enableManpages python3.pkgs.sphinx
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;

buildInputs = [ libxml2 llvm ];
buildInputs = [ libxml2 libllvm ];

cmakeFlags = [
"-DCMAKE_CXX_FLAGS=-std=c++14"
"-DCLANGD_BUILD_XPC=OFF"
"-DLLVM_ENABLE_RTTI=ON"
"-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}"
] ++ lib.optionals enableManpages [
"-DCLANG_INCLUDE_DOCS=ON"
"-DLLVM_ENABLE_SPHINX=ON"
"-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
"-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen"
];

patches = [
./purity.patch
# https://reviews.llvm.org/D51899
./compiler-rt-baremetal.patch
./gnu-install-dirs.patch
];

postPatch = ''
Expand All @@ -56,12 +62,12 @@ let
--replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE
'';

outputs = [ "out" "lib" "python" ];
outputs = [ "out" "lib" "dev" "python" ];

# Clang expects to find LLVMgold in its own prefix
postInstall = ''
if [ -e ${llvm}/lib/LLVMgold.so ]; then
ln -sv ${llvm}/lib/LLVMgold.so $out/lib
if [ -e ${libllvm.lib}/lib/LLVMgold.so ]; then
ln -sv ${libllvm.lib}/lib/LLVMgold.so $lib/lib
fi
ln -sv $out/bin/clang $out/bin/cpp
Expand All @@ -80,11 +86,14 @@ let
fi
mv $out/share/clang/*.py $python/share/clang
rm $out/bin/c-index-test
mkdir -p $dev/bin
cp bin/clang-tblgen $dev/bin
'';

passthru = {
isClang = true;
inherit llvm;
inherit libllvm;
};

meta = {
Expand Down

0 comments on commit 7869d16

Please sign in to comment.