From 9d8f9b2e531bf95a700a949d879927fb6996ffc9 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 30 Nov 2017 13:10:41 -0600 Subject: [PATCH] Add clang multilib variants (x64_64-only, 64/32bit), basic multilib tests --- pkgs/development/compilers/llvm/multi.nix | 44 +++++++++++++++++++++++ pkgs/test/cc-wrapper/multilib.nix | 37 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 16 +++++++++ pkgs/top-level/release.nix | 2 ++ 4 files changed, 99 insertions(+) create mode 100644 pkgs/development/compilers/llvm/multi.nix create mode 100644 pkgs/test/cc-wrapper/multilib.nix diff --git a/pkgs/development/compilers/llvm/multi.nix b/pkgs/development/compilers/llvm/multi.nix new file mode 100644 index 000000000000..0fa0eb3404d8 --- /dev/null +++ b/pkgs/development/compilers/llvm/multi.nix @@ -0,0 +1,44 @@ +{ runCommand, +clang, +gcc64, +gcc32, +glibc_multi +}: + +let + combine = basegcc: runCommand "combine-gcc-libc" {} '' + mkdir -p $out + cp -r ${basegcc.cc}/lib $out/lib + + chmod u+rw -R $out/lib + cp -r ${basegcc.libc}/lib/* $(ls -d $out/lib/gcc/*/*) + ''; + gcc_multi_sysroot = runCommand "gcc-multi-sysroot" {} '' + mkdir -p $out/lib/gcc + + ln -s ${combine gcc64}/lib/gcc/* $out/lib/gcc/ + ln -s ${combine gcc32}/lib/gcc/* $out/lib/gcc/ + # XXX: This shouldn't be needed, clang just doesn't look for "i686-unknown" + ln -s $out/lib/gcc/i686-unknown-linux-gnu $out/lib/gcc/i686-pc-linux-gnu + + + # includes + ln -s ${glibc_multi.dev}/include $out/ + + # dynamic linkers + mkdir -p $out/lib/32 + ln -s ${glibc_multi.out}/lib/ld-linux* $out/lib + ln -s ${glibc_multi.out}/lib/32/ld-linux* $out/lib/32/ + ''; + + clangMulti = clang.override { + # Only used for providing expected structure re:dynamic linkers, AFAIK + # Most of the magic is done by setting the --gcc-toolchain option below + libc = gcc_multi_sysroot; + + extraBuildCommands = '' + sed -e '$a --gcc-toolchain=${gcc_multi_sysroot}' -i $out/nix-support/libc-cflags + ''; + }; + +in clangMulti diff --git a/pkgs/test/cc-wrapper/multilib.nix b/pkgs/test/cc-wrapper/multilib.nix new file mode 100644 index 000000000000..5ea50b5eb268 --- /dev/null +++ b/pkgs/test/cc-wrapper/multilib.nix @@ -0,0 +1,37 @@ +{ stdenv }: + +stdenv.mkDerivation { + name = "cc-multilib-test"; + + # XXX: "depend" on cc-wrapper test? + + # TODO: Have tests report pointer size or something; ensure they are what we asked for + buildCommand = '' + NIX_DEBUG=1 $CC -v + NIX_DEBUG=1 $CXX -v + + printf "checking whether compiler builds valid C binaries... " >&2 + $CC -o cc-check ${./cc-main.c} + ./cc-check + + printf "checking whether compiler builds valid 32bit C binaries... " >&2 + $CC -m32 -o c32-check ${./cc-main.c} + ./c32-check + + printf "checking whether compiler builds valid 64bit C binaries... " >&2 + $CC -m64 -o c64-check ${./cc-main.c} + ./c64-check + + printf "checking whether compiler builds valid 32bit C++ binaries... " >&2 + $CXX -m32 -o cxx32-check ${./cxx-main.cc} + ./cxx32-check + + printf "checking whether compiler builds valid 64bit C++ binaries... " >&2 + $CXX -m64 -o cxx64-check ${./cxx-main.cc} + ./cxx64-check + + touch $out + ''; + + meta.platforms = stdenv.lib.platforms.x86_64; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 839bed15d4a8..3470651acdbe 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5579,7 +5579,20 @@ with pkgs; ''; }) else throw "Multilib ${cc.name} not supported on ‘${system}’"; + wrapClangMulti = clang: + if system == "x86_64-linux" then + callPackages ../development/compilers/llvm/multi.nix { + inherit clang; + gcc32 = pkgsi686Linux.gcc; + gcc64 = pkgs.gcc; + } + else throw "Multilib ${clang.cc.name} not supported on '${system}'"; + gcc_multi = wrapCCMulti gcc; + clang_multi = wrapClangMulti clang; + + gccMultiStdenv = overrideCC stdenv gcc_multi; + clangMultiStdenv = overrideCC stdenv clang_multi; gcc_debug = lowPrio (wrapCC (gcc.cc.override { stripped = false; @@ -20040,6 +20053,9 @@ with pkgs; cc-wrapper-libcxx-5 = callPackage ../test/cc-wrapper { stdenv = llvmPackages_5.libcxxStdenv; }; stdenv-inputs = callPackage ../test/stdenv-inputs { }; + cc-multilib-gcc = callPackage ../test/cc-wrapper/multilib.nix { stdenv = gccMultiStdenv; }; + cc-multilib-clang = callPackage ../test/cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; }; + macOSSierraShared = callPackage ../test/macos-sierra-shared {}; }; diff --git a/pkgs/top-level/release.nix b/pkgs/top-level/release.nix index 8cbb7063b4eb..201c3a38cf8b 100644 --- a/pkgs/top-level/release.nix +++ b/pkgs/top-level/release.nix @@ -112,6 +112,8 @@ let jobs.tests.cc-wrapper-clang-39.x86_64-darwin jobs.tests.cc-wrapper-libcxx-39.x86_64-linux jobs.tests.cc-wrapper-libcxx-39.x86_64-darwin + jobs.tests.cc-multilib-gcc.x86_64-linux + jobs.tests.cc-multilib-clang.x86_64-linux jobs.tests.stdenv-inputs.x86_64-linux jobs.tests.stdenv-inputs.x86_64-darwin jobs.tests.macOSSierraShared.x86_64-darwin