fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{
2 lib,
3 stdenv,
4 llvm_meta,
5 src ? null,
6 monorepoSrc ? null,
7 version,
8 release_version,
9 runCommand,
10 python3,
11 python3Packages,
12 patches ? [ ],
13 cmake,
14 ninja,
15 isFullBuild ? true,
16 linuxHeaders,
17}:
18let
19 pname = "libc";
20
21 src' = runCommand "${pname}-src-${version}" { } (''
22 mkdir -p "$out"
23 cp -r ${monorepoSrc}/cmake "$out"
24 cp -r ${monorepoSrc}/runtimes "$out"
25 cp -r ${monorepoSrc}/llvm "$out"
26 cp -r ${monorepoSrc}/compiler-rt "$out"
27 cp -r ${monorepoSrc}/${pname} "$out"
28 '');
29in
30stdenv.mkDerivation (finalAttrs: {
31 inherit pname version patches;
32
33 src = src';
34
35 sourceRoot = "${finalAttrs.src.name}/runtimes";
36
37 nativeBuildInputs =
38 [
39 cmake
40 python3
41 ]
42 ++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
43 ++ (lib.optional isFullBuild python3Packages.pyyaml);
44
45 buildInputs = lib.optional isFullBuild linuxHeaders;
46
47 outputs = [ "out" ] ++ (lib.optional isFullBuild "dev");
48
49 postUnpack = lib.optionalString isFullBuild ''
50 chmod +w $sourceRoot/../$pname/utils/hdrgen
51 patchShebangs $sourceRoot/../$pname/utils/hdrgen/main.py
52 chmod +x $sourceRoot/../$pname/utils/hdrgen/main.py
53 '';
54
55 prePatch = ''
56 cd ../${finalAttrs.pname}
57 chmod -R u+w ../
58 '';
59
60 postPatch = ''
61 cd ../runtimes
62 '';
63
64 postInstall =
65 lib.optionalString (!isFullBuild) ''
66 substituteAll ${./libc-shim.tpl} $out/lib/libc.so
67 ''
68 # LLVM libc doesn't recognize static vs dynamic yet.
69 # Treat LLVM libc as a static libc, requires this symlink until upstream fixes it.
70 + lib.optionalString (isFullBuild && stdenv.hostPlatform.isLinux) ''
71 ln $out/lib/crt1.o $out/lib/Scrt1.o
72 '';
73
74 libc = if (!isFullBuild) then stdenv.cc.libc else null;
75
76 cmakeFlags =
77 [
78 (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
79 (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc;compiler-rt")
80 # Tests requires the host to have a libc.
81 (lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null))
82 (lib.cmakeBool "LLVM_LIBC_INCLUDE_SCUDO" true)
83 (lib.cmakeBool "COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC" true)
84 (lib.cmakeBool "COMPILER_RT_BUILD_GWP_ASAN" false)
85 (lib.cmakeBool "COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED" false)
86 ]
87 ++ lib.optional (isFullBuild && stdenv.cc.libc == null) [
88 # CMake runs a check to see if the compiler works.
89 # This includes including headers which requires a libc.
90 # Skip these checks because a libc cannot be used when one doesn't exist.
91 (lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
92 (lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
93 ];
94
95 # For the update script:
96 passthru = {
97 monorepoSrc = monorepoSrc;
98 inherit isFullBuild;
99 };
100
101 meta = llvm_meta // {
102 broken = stdenv.hostPlatform.isDarwin;
103 homepage = "https://libc.llvm.org/";
104 description = "Standard C library for LLVM";
105 };
106})