nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 112 lines 5.2 kB view raw
1{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi 2, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD 3}: 4 5let 6 7 useLLVM = stdenv.hostPlatform.useLLVM or false; 8 bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; 9 inherit (stdenv.hostPlatform) isMusl; 10 11in 12 13stdenv.mkDerivation { 14 pname = "compiler-rt"; 15 inherit version; 16 src = fetch "compiler-rt" "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"; 17 18 nativeBuildInputs = [ cmake python3 libllvm.dev ]; 19 buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; 20 21 env.NIX_CFLAGS_COMPILE = toString [ 22 "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" 23 ]; 24 25 cmakeFlags = [ 26 "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" 27 "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" 28 "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" 29 ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ 30 "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" 31 "-DCOMPILER_RT_BUILD_XRAY=OFF" 32 "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" 33 ] ++ lib.optionals (useLLVM || bareMetal) [ 34 "-DCOMPILER_RT_BUILD_PROFILE=OFF" 35 ] ++ lib.optionals (useLLVM || bareMetal) [ 36 "-DCMAKE_C_COMPILER_WORKS=ON" 37 "-DCMAKE_CXX_COMPILER_WORKS=ON" 38 "-DCOMPILER_RT_BAREMETAL_BUILD=ON" 39 "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" 40 ] ++ lib.optionals (useLLVM) [ 41 "-DCOMPILER_RT_BUILD_BUILTINS=ON" 42 "-DCMAKE_C_FLAGS=-nodefaultlibs" 43 #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program 44 "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" 45 ] ++ lib.optionals (bareMetal) [ 46 "-DCOMPILER_RT_OS_DIR=baremetal" 47 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ 48 # The compiler-rt build infrastructure sniffs supported platforms on Darwin 49 # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails 50 # when it tries to use libc++ and libc++api for i386. 51 "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" 52 ]; 53 54 outputs = [ "out" "dev" ]; 55 56 patches = [ 57 ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory 58 # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce 59 ../../common/compiler-rt/glibc.patch 60 ./gnu-install-dirs.patch 61 ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch 62 ] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; 63 64 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 65 # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 66 # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 67 # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 68 # a flag and turn the flag off during the stdenv build. 69 postPatch = lib.optionalString (!stdenv.isDarwin) '' 70 substituteInPlace cmake/builtin-config-ix.cmake \ 71 --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' 72 '' + lib.optionalString stdenv.isDarwin '' 73 substituteInPlace cmake/config-ix.cmake \ 74 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 75 '' + lib.optionalString (useLLVM) '' 76 substituteInPlace lib/builtins/int_util.c \ 77 --replace "#include <stdlib.h>" "" 78 substituteInPlace lib/builtins/clear_cache.c \ 79 --replace "#include <assert.h>" "" 80 substituteInPlace lib/builtins/cpu_model.c \ 81 --replace "#include <assert.h>" "" 82 ''; 83 84 # Hack around weird upsream RPATH bug 85 postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' 86 ln -s "$out/lib"/*/* "$out/lib" 87 '' + lib.optionalString (useLLVM) '' 88 ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/linux/crtbegin.o 89 ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/linux/crtend.o 90 ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/linux/crtbeginS.o 91 ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/linux/crtendS.o 92 '' + lib.optionalString doFakeLibgcc '' 93 ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/freebsd/libgcc.a 94 ''; 95 96 meta = llvm_meta // { 97 homepage = "https://compiler-rt.llvm.org/"; 98 description = "Compiler runtime libraries"; 99 longDescription = '' 100 The compiler-rt project provides highly tuned implementations of the 101 low-level code generator support routines like "__fixunsdfdi" and other 102 calls generated when a target doesn't have a short sequence of native 103 instructions to implement a core IR operation. It also provides 104 implementations of run-time libraries for dynamic testing tools such as 105 AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. 106 ''; 107 # "All of the code in the compiler-rt project is dual licensed under the MIT 108 # license and the UIUC License (a BSD-like license)": 109 license = with lib.licenses; [ mit ncsa ]; 110 broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; 111 }; 112}