···1+{ lib, stdenv, llvm_meta
2+, pkgsBuildBuild
3+, monorepoSrc
4+, runCommand
5+, cmake
6+, darwin
7+, ninja
8+, python3
9+, python3Packages
10+, libffi
11+, enableGoldPlugin ? true
12+, libbfd
13+, libpfm
14+, libxml2
15+, ncurses
16+, version
17+, release_version
18+, zlib
19+, which
20+, sysctl
21+, buildLlvmTools
22+, debugVersion ? false
23+, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl)
24+ && (stdenv.hostPlatform == stdenv.buildPlatform)
25+, enableManpages ? false
26+, enableSharedLibraries ? !stdenv.hostPlatform.isStatic
27+, enablePFM ? stdenv.isLinux /* PFM only supports Linux */
28+ # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245
29+ # broken for the armv7l builder
30+ && !stdenv.hostPlatform.isAarch
31+, enablePolly ? true
32+}:
33+34+let
35+ inherit (lib) optional optionals optionalString;
36+37+ # Used when creating a version-suffixed symlink of libLLVM.dylib
38+ shortVersion = with lib;
39+ concatStringsSep "." (take 1 (splitString "." release_version));
40+41+ # Ordinarily we would just the `doCheck` and `checkDeps` functionality
42+ # `mkDerivation` gives us to manage our test dependencies (instead of breaking
43+ # out `doCheck` as a package level attribute).
44+ #
45+ # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in
46+ # particular the children it uses to do feature detection.
47+ #
48+ # This means that python deps we add to `checkDeps` (which the python
49+ # interpreter is made aware of via `$PYTHONPATH` – populated by the python
50+ # setup hook) are not picked up by `lit` which causes it to skip tests.
51+ #
52+ # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work
53+ # because this package is shadowed in `$PATH` by the regular `python3`
54+ # package.
55+ #
56+ # So, we "manually" assemble one python derivation for the package to depend
57+ # on, taking into account whether checks are enabled or not:
58+ python = if doCheck then
59+ # Note that we _explicitly_ ask for a python interpreter for our host
60+ # platform here; the splicing that would ordinarily take care of this for
61+ # us does not seem to work once we use `withPackages`.
62+ let
63+ checkDeps = ps: with ps; [ psutil ];
64+ in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps
65+ else python3;
66+67+in
68+69+stdenv.mkDerivation (rec {
70+ pname = "llvm";
71+ inherit version;
72+73+ src = runCommand "${pname}-src-${version}" {} (''
74+ mkdir -p "$out"
75+ cp -r ${monorepoSrc}/cmake "$out"
76+ cp -r ${monorepoSrc}/${pname} "$out"
77+ cp -r ${monorepoSrc}/third-party "$out"
78+ '' + lib.optionalString enablePolly ''
79+ chmod u+w "$out/${pname}/tools"
80+ cp -r ${monorepoSrc}/polly "$out/${pname}/tools"
81+ '');
82+83+ sourceRoot = "${src.name}/${pname}";
84+85+ outputs = [ "out" "lib" "dev" "python" ];
86+87+ nativeBuildInputs = [ cmake ninja python ]
88+ ++ optionals enableManpages [
89+ # Note: we intentionally use `python3Packages` instead of `python3.pkgs`;
90+ # splicing does *not* work with the latter. (TODO: fix)
91+ python3Packages.sphinx
92+ ] ++ optionals (lib.versionOlder version "18" && enableManpages) [
93+ python3Packages.recommonmark
94+ ] ++ optionals (lib.versionAtLeast version "18" && enableManpages) [
95+ python3Packages.myst-parser
96+ ];
97+98+ buildInputs = [ libxml2 libffi ]
99+ ++ optional enablePFM libpfm; # exegesis
100+101+ propagatedBuildInputs = [ ncurses zlib ];
102+103+ nativeCheckInputs = [
104+ which
105+ ] ++ lib.optional stdenv.isDarwin sysctl;
106+107+ patches = [
108+ ./gnu-install-dirs.patch
109+110+ # Running the tests involves invoking binaries (like `opt`) that depend on
111+ # the LLVM dylibs and reference them by absolute install path (i.e. their
112+ # nix store path).
113+ #
114+ # Because we have not yet run the install phase (we're running these tests
115+ # as part of `checkPhase` instead of `installCheckPhase`) these absolute
116+ # paths do not exist yet; to work around this we point the loader (`ld` on
117+ # unix, `dyld` on macOS) at the `lib` directory which will later become this
118+ # package's `lib` output.
119+ #
120+ # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib`
121+ # dir but:
122+ # - this doesn't generalize well to other platforms; `lit` doesn't forward
123+ # `DYLD_LIBRARY_PATH` (macOS):
124+ # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26
125+ # - even if `lit` forwarded this env var, we actually cannot set
126+ # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because
127+ # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for
128+ # "protected processes" (i.e. the python interpreter that runs `lit`):
129+ # https://stackoverflow.com/a/35570229
130+ # - other LLVM subprojects deal with this issue by having their `lit`
131+ # configuration set these env vars for us; it makes sense to do the same
132+ # for LLVM:
133+ # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31
134+ #
135+ # !!! TODO: look into upstreaming this patch
136+ ./llvm-lit-cfg-add-libs-to-dylib-path.patch
137+138+ # `lit` has a mode where it executes run lines as a shell script which is
139+ # constructs; this is problematic for macOS because it means that there's
140+ # another process in between `lit` and the binaries being tested. As noted
141+ # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our
142+ # tests fail with dyld errors.
143+ #
144+ # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when
145+ # present in the test configuration.
146+ #
147+ # It's not clear to me why this isn't an issue for LLVM developers running
148+ # on macOS (nothing about this _seems_ nix specific)..
149+ ./lit-shell-script-runner-set-dyld-library-path.patch
150+ ] ++ lib.optionals enablePolly [
151+ ./gnu-install-dirs-polly.patch
152+153+ # Just like the `llvm-lit-cfg` patch, but for `polly`.
154+ ./polly-lit-cfg-add-libs-to-dylib-path.patch
155+ ];
156+157+ postPatch = optionalString stdenv.isDarwin ''
158+ substituteInPlace cmake/modules/AddLLVM.cmake \
159+ --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \
160+ --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
161+162+ # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick
163+ # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7
164+ rm test/MC/ELF/cfi-version.ll
165+166+ # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`)
167+ # and thus fails under the sandbox:
168+ substituteInPlace unittests/TargetParser/Host.cpp \
169+ --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }"
170+171+ # This test tries to call the intrinsics `@llvm.roundeven.f32` and
172+ # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf`
173+ # and `roundeven` on macOS.
174+ #
175+ # However these functions are glibc specific so the test fails:
176+ # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html
177+ # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html
178+ #
179+ substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
180+ --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
181+ --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
182+183+ # fails when run in sandbox
184+ substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
185+ --replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
186+ '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) ''
187+ # This test fails on darwin x86_64 because `sw_vers` reports a different
188+ # macOS version than what LLVM finds by reading
189+ # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into
190+ # the sandbox on macOS).
191+ #
192+ # The `sw_vers` provided by nixpkgs reports the macOS version associated
193+ # with the `CoreFoundation` framework with which it was built. Because
194+ # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what
195+ # `sw_vers` reports is not guaranteed to match the macOS version of the host
196+ # that's building this derivation.
197+ #
198+ # Astute readers will note that we only _patch_ this test on aarch64-darwin
199+ # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright.
200+ # So why does this test pass on aarch64?
201+ #
202+ # Well, it seems that `sw_vers` on aarch64 actually links against the _host_
203+ # CoreFoundation framework instead of the nixpkgs provided one.
204+ #
205+ # Not entirely sure what the right fix is here. I'm assuming aarch64
206+ # `sw_vers` doesn't intentionally link against the host `CoreFoundation`
207+ # (still digging into how this ends up happening, will follow up) but that
208+ # aside I think the more pertinent question is: should we be patching LLVM's
209+ # macOS version detection logic to use `sw_vers` instead of reading host
210+ # paths? This *is* a way in which details about builder machines can creep
211+ # into the artifacts that are produced, affecting reproducibility, but it's
212+ # not clear to me when/where/for what this even gets used in LLVM.
213+ #
214+ # TODO(@rrbutani): fix/follow-up
215+ substituteInPlace unittests/TargetParser/Host.cpp \
216+ --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
217+218+ # This test fails with a `dysmutil` crash; have not yet dug into what's
219+ # going on here (TODO(@rrbutani)).
220+ rm test/tools/dsymutil/ARM/obfuscated.test
221+ '' + ''
222+ # FileSystem permissions tests fail with various special bits
223+ substituteInPlace unittests/Support/CMakeLists.txt \
224+ --replace "Path.cpp" ""
225+ rm unittests/Support/Path.cpp
226+ substituteInPlace unittests/IR/CMakeLists.txt \
227+ --replace "PassBuilderCallbacksTest.cpp" ""
228+ rm unittests/IR/PassBuilderCallbacksTest.cpp
229+ rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
230+231+ # Fails in the presence of anti-virus software or other intrusion-detection software that
232+ # modifies the atime when run. See #284056.
233+ rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
234+ '' + optionalString stdenv.hostPlatform.isMusl ''
235+ patch -p1 -i ${../../common/llvm/TLI-musl.patch}
236+ substituteInPlace unittests/Support/CMakeLists.txt \
237+ --replace "add_subdirectory(DynamicLibrary)" ""
238+ rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
239+ # valgrind unhappy with musl or glibc, but fails w/musl only
240+ rm test/CodeGen/AArch64/wineh4.mir
241+ '' + optionalString stdenv.hostPlatform.isAarch32 ''
242+ # skip failing X86 test cases on 32-bit ARM
243+ rm test/DebugInfo/X86/convert-debugloc.ll
244+ rm test/DebugInfo/X86/convert-inlined.ll
245+ rm test/DebugInfo/X86/convert-linked.ll
246+ rm test/tools/dsymutil/X86/op-convert.test
247+ rm test/tools/gold/X86/split-dwarf.ll
248+ rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s
249+ rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s
250+ rm test/CodeGen/RISCV/attributes.ll
251+ rm test/CodeGen/RISCV/xtheadmempair.ll
252+ '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") ''
253+ # Seems to require certain floating point hardware (NEON?)
254+ rm test/ExecutionEngine/frem.ll
255+ '' + ''
256+ patchShebangs test/BugPoint/compile-custom.ll.py
257+ '';
258+259+ preConfigure = ''
260+ # Workaround for configure flags that need to have spaces
261+ cmakeFlagsArray+=(
262+ -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar"
263+ )
264+ '';
265+266+ # Defensive check: some paths (that we make symlinks to) depend on the release
267+ # version, for example:
268+ # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185
269+ #
270+ # So we want to sure that the version in the source matches the release
271+ # version we were given.
272+ #
273+ # We do this check here, in the LLVM build, because it happens early.
274+ postConfigure = let
275+ v = lib.versions;
276+ major = v.major release_version;
277+ minor = v.minor release_version;
278+ patch = v.patch release_version;
279+ in ''
280+ # $1: part, $2: expected
281+ check_version() {
282+ part="''${1^^}"
283+ part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)"
284+285+ if [[ "$part" != "$2" ]]; then
286+ echo >&2 \
287+ "mismatch in the $1 version! we have version ${release_version}" \
288+ "and expected the $1 version to be '$2'; the source has '$part' instead"
289+ exit 3
290+ fi
291+ }
292+293+ check_version major ${major}
294+ check_version minor ${minor}
295+ check_version patch ${patch}
296+ '';
297+298+ # E.g. mesa.drivers use the build-id as a cache key (see #93946):
299+ LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1";
300+301+ hardeningDisable = [ "trivialautovarinit" ];
302+303+ cmakeBuildType = if debugVersion then "Debug" else "Release";
304+305+ cmakeFlags = with stdenv; let
306+ # These flags influence llvm-config's BuildVariables.inc in addition to the
307+ # general build. We need to make sure these are also passed via
308+ # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native
309+ # will return different results from the cross llvm-config.
310+ #
311+ # Some flags don't need to be repassed because LLVM already does so (like
312+ # CMAKE_BUILD_TYPE), others are irrelevant to the result.
313+ flagsForLlvmConfig = [
314+ "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm"
315+ "-DLLVM_ENABLE_RTTI=ON"
316+ ] ++ optionals enableSharedLibraries [
317+ "-DLLVM_LINK_LLVM_DYLIB=ON"
318+ ];
319+ in flagsForLlvmConfig ++ [
320+ "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
321+ "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}"
322+ "-DLLVM_ENABLE_FFI=ON"
323+ "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
324+ "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
325+ "-DLLVM_ENABLE_DUMP=ON"
326+ ] ++ optionals stdenv.hostPlatform.isStatic [
327+ # Disables building of shared libs, -fPIC is still injected by cc-wrapper
328+ "-DLLVM_ENABLE_PIC=OFF"
329+ "-DLLVM_BUILD_STATIC=ON"
330+ "-DLLVM_LINK_LLVM_DYLIB=off"
331+ # libxml2 needs to be disabled because the LLVM build system ignores its .la
332+ # file and doesn't link zlib as well.
333+ # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812
334+ "-DLLVM_ENABLE_LIBXML2=OFF"
335+ ] ++ optionals enableManpages [
336+ "-DLLVM_BUILD_DOCS=ON"
337+ "-DLLVM_ENABLE_SPHINX=ON"
338+ "-DSPHINX_OUTPUT_MAN=ON"
339+ "-DSPHINX_OUTPUT_HTML=OFF"
340+ "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
341+ ] ++ optionals enableGoldPlugin [
342+ "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
343+ ] ++ optionals isDarwin [
344+ "-DLLVM_ENABLE_LIBCXX=ON"
345+ "-DCAN_TARGET_i386=false"
346+ ] ++ optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [
347+ "-DCMAKE_CROSSCOMPILING=True"
348+ "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen"
349+ (
350+ let
351+ nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
352+ nativeBintools = nativeCC.bintools.bintools;
353+ nativeToolchainFlags = [
354+ "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc"
355+ "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++"
356+ "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar"
357+ "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip"
358+ "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib"
359+ ];
360+ # We need to repass the custom GNUInstallDirs values, otherwise CMake
361+ # will choose them for us, leading to wrong results in llvm-config-native
362+ nativeInstallFlags = [
363+ "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
364+ "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin"
365+ "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include"
366+ "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib"
367+ "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec"
368+ ];
369+ in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list="
370+ + lib.concatStringsSep ";" (lib.concatLists [
371+ flagsForLlvmConfig
372+ nativeToolchainFlags
373+ nativeInstallFlags
374+ ])
375+ )
376+ ];
377+378+ postInstall = ''
379+ mkdir -p $python/share
380+ mv $out/share/opt-viewer $python/share/opt-viewer
381+ moveToOutput "bin/llvm-config*" "$dev"
382+ substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
383+ --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \
384+ --replace "$out/bin/llvm-config" "$dev/bin/llvm-config"
385+ substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
386+ --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
387+ ''
388+ + optionalString (stdenv.isDarwin && enableSharedLibraries) ''
389+ ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
390+ ''
391+ + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
392+ cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native
393+ '';
394+395+ inherit doCheck;
396+397+ checkTarget = "check-all";
398+399+ # For the update script:
400+ passthru.monorepoSrc = monorepoSrc;
401+402+ requiredSystemFeatures = [ "big-parallel" ];
403+ meta = llvm_meta // {
404+ homepage = "https://llvm.org/";
405+ description = "A collection of modular and reusable compiler and toolchain technologies";
406+ longDescription = ''
407+ The LLVM Project is a collection of modular and reusable compiler and
408+ toolchain technologies. Despite its name, LLVM has little to do with
409+ traditional virtual machines. The name "LLVM" itself is not an acronym; it
410+ is the full name of the project.
411+ LLVM began as a research project at the University of Illinois, with the
412+ goal of providing a modern, SSA-based compilation strategy capable of
413+ supporting both static and dynamic compilation of arbitrary programming
414+ languages. Since then, LLVM has grown to be an umbrella project consisting
415+ of a number of subprojects, many of which are being used in production by
416+ a wide variety of commercial and open source projects as well as being
417+ widely used in academic research. Code in the LLVM project is licensed
418+ under the "Apache 2.0 License with LLVM exceptions".
419+ '';
420+ };
421+} // lib.optionalAttrs enableManpages {
422+ pname = "llvm-manpages";
423+424+ propagatedBuildInputs = [];
425+426+ ninjaFlags = [ "docs-llvm-man" ];
427+ installTargets = [ "install-docs-llvm-man" ];
428+429+ postPatch = null;
430+ postInstall = null;
431+432+ outputs = [ "out" ];
433+434+ doCheck = false;
435+436+ meta = llvm_meta // {
437+ description = "man pages for LLVM ${version}";
438+ };
439+})
···40 if (APPLE)
41 set(_install_name_dir INSTALL_NAME_DIR "@rpath")
42- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
43-+ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
44 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS)
45 # $ORIGIN is not interpreted at link time by aix ld.
46 # Since BUILD_SHARED_LIBS is only recommended for use by developers,
···72+ # As noted in the differential above, an alternative solution is to have
73+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set
74+ # `CMAKE_INSTALL_RPATH`.
75-+ set(_build_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
76-+ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
77 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
78 set_property(TARGET ${name} APPEND_STRING PROPERTY
79 LINK_FLAGS " -Wl,-z,origin ")
···8687 if( APPLE )
88- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
89-+ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
90 elseif( UNIX )
91- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
92-+ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
93 endif()
94 list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
95
···40 if (APPLE)
41 set(_install_name_dir INSTALL_NAME_DIR "@rpath")
42- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
43++ set(_install_rpath ${extra_libdir})
44 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS)
45 # $ORIGIN is not interpreted at link time by aix ld.
46 # Since BUILD_SHARED_LIBS is only recommended for use by developers,
···72+ # As noted in the differential above, an alternative solution is to have
73+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set
74+ # `CMAKE_INSTALL_RPATH`.
75++ set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
76++ set(_install_rpath ${extra_libdir})
77 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
78 set_property(TARGET ${name} APPEND_STRING PROPERTY
79 LINK_FLAGS " -Wl,-z,origin ")
···8687 if( APPLE )
88- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
89++ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
90 elseif( UNIX )
91- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
92++ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
93 endif()
94 list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
95
···1-diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py
2-index 0242e0b75af3..d732011306f7 100644
3---- a/utils/lit/lit/TestRunner.py
4-+++ b/utils/lit/lit/TestRunner.py
5-@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
6- f.write('@echo off\n')
7- f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands))
8 else:
9-+ # This env var is *purged* when invoking subprocesses so we have to
10-+ # manually set it from within the bash script in order for the commands
11-+ # in run lines to see this var:
12+ if "DYLD_LIBRARY_PATH" in test.config.environment:
13+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n')
14+
15 for i, ln in enumerate(commands):
16- match = re.match(kPdbgRegex, ln)
17 if match:
···1+--- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700
2++++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700
3+@@ -1183,6 +1183,9 @@
4+ f.write("@echo on\n")
5+ f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
006 else:
0007+ if "DYLD_LIBRARY_PATH" in test.config.environment:
8+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n')
9+
10 for i, ln in enumerate(commands):
11+ match = re.fullmatch(kPdbgRegex, ln)
12 if match:
···1-diff --git a/CMakeLists.txt b/CMakeLists.txt
2-index b6ddbe90516d..311ab1d50e7f 100644
3---- a/CMakeLists.txt
4-+++ b/CMakeLists.txt
5-@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD)
6- set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
7- "Suffix of lib installation directory, e.g. 64 => lib64")
8- # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
9-- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}" CACHE STRING
10-+ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}" CACHE STRING
11- "Path where built OpenMP libraries should be installed.")
12-13- # Group test settings.
14-@@ -47,7 +47,7 @@ if (OPENMP_STANDALONE_BUILD)
15- else()
16- set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
17- # If building in tree, we honor the same install suffix LLVM uses.
18-- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING
19-+ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" CACHE STRING
20- "Path where built OpenMP libraries should be installed.")
21-22- if (NOT MSVC)
···0000000000000000000000
+5-5
pkgs/development/compilers/llvm/update-git.py
···43 """Get the current revision of llvmPackages_git."""
44 with open(DEFAULT_NIX) as f:
45 for line in f:
46- rev = re.search(r'^ rev = "(.*)";', line)
47 if rev:
48 return rev.group(1)
49 sys.exit(1)
···75print('Updating default.nix...')
76with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f:
77 for line in f:
78- if match := re.search(r'^ rev-version = "unstable-(.+)";', line):
79 old_date = match.group(1)
80- result = re.sub(r'^ release_version = ".+";', f' release_version = "{release_version}";', line)
81- result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result)
82- result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result)
83 result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result)
84 print(result, end='')
85# Commit the result:
···43 """Get the current revision of llvmPackages_git."""
44 with open(DEFAULT_NIX) as f:
45 for line in f:
46+ rev = re.search(r'^ rev = "(.*)";', line)
47 if rev:
48 return rev.group(1)
49 sys.exit(1)
···75print('Updating default.nix...')
76with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f:
77 for line in f:
78+ if match := re.search(r'^ rev-version = "unstable-(.+)";', line):
79 old_date = match.group(1)
80+ result = re.sub(r'^ version = ".+";', f' version = "{release_version}";', line)
81+ result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result)
82+ result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result)
83 result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result)
84 print(result, end='')
85# Commit the result: