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