nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 132 lines 5.9 kB view raw
1{ lib, stdenv, llvm_meta, version, src, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt 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 haveLibc = stdenv.cc.libc != null; 10 inherit (stdenv.hostPlatform) isMusl isAarch64; 11 12in 13 14stdenv.mkDerivation { 15 pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; 16 inherit version; 17 18 inherit src; 19 sourceRoot = "source/compiler-rt"; 20 21 nativeBuildInputs = [ cmake python3 libllvm.dev ] 22 ++ lib.optional stdenv.isDarwin xcbuild.xcrun; 23 buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; 24 25 env.NIX_CFLAGS_COMPILE = toString [ 26 "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" 27 ]; 28 29 cmakeFlags = [ 30 "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" 31 "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" 32 "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" 33 ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ 34 "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" 35 ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isAarch64) [ 36 "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" 37 ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ 38 "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" 39 "-DCOMPILER_RT_BUILD_XRAY=OFF" 40 "-DCOMPILER_RT_BUILD_MEMPROF=OFF" 41 "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary 42 ] ++ lib.optionals (useLLVM || bareMetal) [ 43 "-DCOMPILER_RT_BUILD_PROFILE=OFF" 44 ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ 45 "-DCMAKE_C_COMPILER_WORKS=ON" 46 "-DCMAKE_CXX_COMPILER_WORKS=ON" 47 "-DCOMPILER_RT_BAREMETAL_BUILD=ON" 48 "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" 49 ] ++ lib.optionals (useLLVM) [ 50 "-DCOMPILER_RT_BUILD_BUILTINS=ON" 51 #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program 52 "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" 53 ] ++ lib.optionals (bareMetal) [ 54 "-DCOMPILER_RT_OS_DIR=baremetal" 55 ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ 56 "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" 57 "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" 58 "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" 59 ]; 60 61 outputs = [ "out" "dev" ]; 62 63 patches = [ 64 ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory 65 ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config 66 # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the 67 # extra `/`. 68 ./normalize-var.patch 69 # Prevent a compilation error on darwin 70 ./darwin-targetconditionals.patch 71 ../../common/compiler-rt/darwin-plistbuddy-workaround.patch 72 ./armv7l.patch 73 # Fix build on armv6l 74 ../../common/compiler-rt/armv6-mcr-dmb.patch 75 ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch 76 ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch 77 ../../common/compiler-rt/armv6-scudo-no-yield.patch 78 ../../common/compiler-rt/armv6-scudo-libatomic.patch 79 ]; 80 81 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 82 # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 83 # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 84 # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 85 # a flag and turn the flag off during the stdenv build. 86 postPatch = lib.optionalString (!stdenv.isDarwin) '' 87 substituteInPlace cmake/builtin-config-ix.cmake \ 88 --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' 89 '' + lib.optionalString stdenv.isDarwin '' 90 substituteInPlace cmake/config-ix.cmake \ 91 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 92 '' + lib.optionalString (useLLVM) '' 93 substituteInPlace lib/builtins/int_util.c \ 94 --replace "#include <stdlib.h>" "" 95 substituteInPlace lib/builtins/clear_cache.c \ 96 --replace "#include <assert.h>" "" 97 substituteInPlace lib/builtins/cpu_model.c \ 98 --replace "#include <assert.h>" "" 99 ''; 100 101 preConfigure = lib.optionalString (useLLVM && !haveLibc) '' 102 cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") 103 ''; 104 105 # Hack around weird upsream RPATH bug 106 postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' 107 ln -s "$out/lib"/*/* "$out/lib" 108 '' + lib.optionalString (useLLVM) '' 109 ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o 110 ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o 111 ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o 112 ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o 113 '' + lib.optionalString doFakeLibgcc '' 114 ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a 115 ''; 116 117 meta = llvm_meta // { 118 homepage = "https://compiler-rt.llvm.org/"; 119 description = "Compiler runtime libraries"; 120 longDescription = '' 121 The compiler-rt project provides highly tuned implementations of the 122 low-level code generator support routines like "__fixunsdfdi" and other 123 calls generated when a target doesn't have a short sequence of native 124 instructions to implement a core IR operation. It also provides 125 implementations of run-time libraries for dynamic testing tools such as 126 AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. 127 ''; 128 # "All of the code in the compiler-rt project is dual licensed under the MIT 129 # license and the UIUC License (a BSD-like license)": 130 license = with lib.licenses; [ mit ncsa ]; 131 }; 132}