From 46d5893733f4e9a1016419525d761ff5de556a22 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 14 Jan 2024 22:00:26 +0000 Subject: [PATCH] nix: Remove our version of llvm --- nix/clang/default.nix | 160 ------- nix/compiler-rt/X86-support-extension.patch | 21 - .../darwin-plistbuddy-workaround.patch | 25 -- .../darwin-targetconditionals.patch | 71 ---- nix/compiler-rt/default.nix | 160 ------- nix/compiler-rt/gnu-install-dirs.patch | 20 - nix/compiler-rt/normalize-var.patch | 16 - nix/libcxx/default.nix | 128 ------ nix/libcxx/gnu-install-dirs.patch | 22 - nix/libcxxabi/default.nix | 129 ------ nix/libcxxabi/gnu-install-dirs.patch | 44 -- nix/libcxxabi/standalone.patch | 24 -- nix/libunwind/default.nix | 69 --- nix/libunwind/gnu-install-dirs.patch | 21 - nix/llvm.nix | 360 ---------------- nix/llvm/TLI-musl.patch | 34 -- nix/llvm/default.nix | 399 ------------------ nix/llvm/gnu-install-dirs-polly.patch | 19 - nix/llvm/gnu-install-dirs.patch | 137 ------ ...-script-runner-set-dyld-library-path.patch | 17 - .../llvm-lit-cfg-add-libs-to-dylib-path.patch | 79 ---- ...polly-lit-cfg-add-libs-to-dylib-path.patch | 24 -- nix/llvm_source.nix | 41 -- 23 files changed, 2020 deletions(-) delete mode 100644 nix/clang/default.nix delete mode 100644 nix/compiler-rt/X86-support-extension.patch delete mode 100644 nix/compiler-rt/darwin-plistbuddy-workaround.patch delete mode 100644 nix/compiler-rt/darwin-targetconditionals.patch delete mode 100644 nix/compiler-rt/default.nix delete mode 100644 nix/compiler-rt/gnu-install-dirs.patch delete mode 100644 nix/compiler-rt/normalize-var.patch delete mode 100644 nix/libcxx/default.nix delete mode 100644 nix/libcxx/gnu-install-dirs.patch delete mode 100644 nix/libcxxabi/default.nix delete mode 100644 nix/libcxxabi/gnu-install-dirs.patch delete mode 100644 nix/libcxxabi/standalone.patch delete mode 100644 nix/libunwind/default.nix delete mode 100644 nix/libunwind/gnu-install-dirs.patch delete mode 100644 nix/llvm.nix delete mode 100644 nix/llvm/TLI-musl.patch delete mode 100644 nix/llvm/default.nix delete mode 100644 nix/llvm/gnu-install-dirs-polly.patch delete mode 100644 nix/llvm/gnu-install-dirs.patch delete mode 100644 nix/llvm/lit-shell-script-runner-set-dyld-library-path.patch delete mode 100644 nix/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch delete mode 100644 nix/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch delete mode 100644 nix/llvm_source.nix diff --git a/nix/clang/default.nix b/nix/clang/default.nix deleted file mode 100644 index cf86807..0000000 --- a/nix/clang/default.nix +++ /dev/null @@ -1,160 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - utils, - llvm_source, - runCommand, - substituteAll, - cmake, - ninja, - libxml2, - libllvm, - version, - python3, - buildLlvmTools, - fixDarwinDylibNames, - enableManpages ? false -}: - -let - self = stdenv.mkDerivation (rec { - pname = "clang"; - inherit version; - - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${pname} "$out" - cp -r ${monorepoSrc}/clang-tools-extra "$out" - ''; - - sourceRoot = "${src.name}/${pname}"; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional enableManpages python3.pkgs.sphinx - ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; - - buildInputs = [ libxml2 libllvm ]; - - cmakeFlags = [ - "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" - "-DCLANGD_BUILD_XPC=OFF" - "-DLLVM_ENABLE_RTTI=ON" - "-DLLVM_INCLUDE_TESTS=OFF" - ] ++ lib.optionals enableManpages [ - "-DCLANG_INCLUDE_DOCS=ON" - "-DLLVM_ENABLE_SPHINX=ON" - "-DSPHINX_OUTPUT_MAN=ON" - "-DSPHINX_OUTPUT_HTML=OFF" - "-DSPHINX_WARNINGS_AS_ERRORS=OFF" - ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ - "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" - "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" - # Added in LLVM15: - # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb - # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 - "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" - "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" - ]; - - patches = [ - ./purity.patch - # https://reviews.llvm.org/D51899 - ./gnu-install-dirs.patch - ../../common/clang/add-nostdlibinc-flag.patch - (substituteAll { - src = ../../clang-at-least-16-LLVMgold-path.patch; - libllvmLibdir = "${libllvm.lib}/lib"; - }) - ]; - - postPatch = '' - (cd tools && ln -s ../../clang-tools-extra extra) - '' + lib.optionalString stdenv.hostPlatform.isMusl '' - sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp - ''; - - outputs = [ "out" "lib" "dev" "python" ]; - - postInstall = '' - ln -sv $out/bin/clang $out/bin/cpp - - mkdir -p $lib/lib/clang - mv $lib/lib/17 $lib/lib/clang/17 - - # Move libclang to 'lib' output - moveToOutput "lib/libclang.*" "$lib" - moveToOutput "lib/libclang-cpp.*" "$lib" - substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ - --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ - --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." - - mkdir -p $python/bin $python/share/clang/ - mv $out/bin/{git-clang-format,scan-view} $python/bin - if [ -e $out/bin/set-xcode-analyzer ]; then - mv $out/bin/set-xcode-analyzer $python/bin - fi - mv $out/share/clang/*.py $python/share/clang - rm $out/bin/c-index-test - patchShebangs $python/bin - - mkdir -p $dev/bin - cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin - ''; - - passthru = { - inherit libllvm; - isClang = true; - hardeningUnsupportedFlags = [ "fortify3" ]; - }; - - meta = llvm_meta // { - homepage = "https://clang.llvm.org/"; - description = "A C language family frontend for LLVM"; - longDescription = '' - The Clang project provides a language front-end and tooling - infrastructure for languages in the C language family (C, C++, Objective - C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. - It aims to deliver amazingly fast compiles, extremely useful error and - warning messages and to provide a platform for building great source - level tools. The Clang Static Analyzer and clang-tidy are tools that - automatically find bugs in your code, and are great examples of the sort - of tools that can be built using the Clang frontend as a library to - parse C/C++ code. - ''; - mainProgram = "clang"; - }; - } // lib.optionalAttrs enableManpages { - pname = "clang-manpages"; - - ninjaFlags = [ "docs-clang-man" ]; - - installPhase = '' - mkdir -p $out/share/man/man1 - # Manually install clang manpage - cp docs/man/*.1 $out/share/man/man1/ - ''; - - outputs = [ "out" ]; - - doCheck = false; - - meta = llvm_meta // { - description = "man page for Clang ${version}"; - }; - }); -in self diff --git a/nix/compiler-rt/X86-support-extension.patch b/nix/compiler-rt/X86-support-extension.patch deleted file mode 100644 index 3eb36e1..0000000 --- a/nix/compiler-rt/X86-support-extension.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt -index 3a66dd9c3fb..7efc85d9f9f 100644 ---- a/lib/builtins/CMakeLists.txt -+++ b/lib/builtins/CMakeLists.txt -@@ -348,4 +348,8 @@ if (NOT MSVC) - -+ set(i486_SOURCES ${i386_SOURCES}) -+ set(i586_SOURCES ${i386_SOURCES}) -+ set(i686_SOURCES ${i386_SOURCES}) -+ - if (WIN32) - set(i386_SOURCES - ${i386_SOURCES} -@@ -723,6 +723,7 @@ else () - endif() - - foreach (arch ${BUILTIN_SUPPORTED_ARCH}) -+ message("arch: ${arch}") - if (CAN_TARGET_${arch}) - # For ARM archs, exclude any VFP builtins if VFP is not supported - if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/nix/compiler-rt/darwin-plistbuddy-workaround.patch b/nix/compiler-rt/darwin-plistbuddy-workaround.patch deleted file mode 100644 index 1032e03..0000000 --- a/nix/compiler-rt/darwin-plistbuddy-workaround.patch +++ /dev/null @@ -1,25 +0,0 @@ -CMake tries to read a list field from SDKSettings.plist, but the output of -xcbuild PlistBuddy is incompatible with Apple's. (Plus we don't want it in our -dependencies.) - -Simply assume ARM64 is supported by the SDK. We already limit the actual archs -we build for by setting DARWIN_osx_BUILTIN_ARCHS explicitely. - ---- a/cmake/builtin-config-ix.cmake -+++ b/cmake/builtin-config-ix.cmake -@@ -97,14 +97,7 @@ if(APPLE) - set(DARWIN_osx_BUILTIN_MIN_VER 10.5) - set(DARWIN_osx_BUILTIN_MIN_VER_FLAG - -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER}) -- set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64}) -- # Add support for arm64 macOS if available in SDK. -- foreach(arch ${ARM64}) -- sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT) -- if (MACOS_ARM_SUPPORT) -- list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch}) -- endif() -- endforeach(arch) -+ set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} ${ARM64}) - - if(COMPILER_RT_ENABLE_IOS) - list(APPEND DARWIN_EMBEDDED_PLATFORMS ios) diff --git a/nix/compiler-rt/darwin-targetconditionals.patch b/nix/compiler-rt/darwin-targetconditionals.patch deleted file mode 100644 index 574a74e..0000000 --- a/nix/compiler-rt/darwin-targetconditionals.patch +++ /dev/null @@ -1,71 +0,0 @@ -diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp ---- a/lib/sanitizer_common/sanitizer_mac.cpp -+++ b/lib/sanitizer_common/sanitizer_mac.cpp -@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { - // Offset example: - // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 - constexpr u16 GetOSMajorKernelOffset() { -- if (TARGET_OS_OSX) return 4; -- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; -- if (TARGET_OS_WATCH) return 13; -+#if TARGET_OS_OSX -+ return 4; -+#endif -+#if TARGET_OS_IOS || TARGET_OS_TV -+ return 6; -+#endif -+#if TARGET_OS_WATCH -+ return 13; -+#endif - } - - using VersStr = char[64]; -@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { - u16 os_major = kernel_major - offset; - - const char *format = "%d.0"; -- if (TARGET_OS_OSX) { -- if (os_major >= 16) { // macOS 11+ -- os_major -= 5; -- } else { // macOS 10.15 and below -- format = "10.%d"; -- } -+#if TARGET_OS_OSX -+ if (os_major >= 16) { // macOS 11+ -+ os_major -= 5; -+ } else { // macOS 10.15 and below -+ format = "10.%d"; - } -+#endif - return internal_snprintf(vers, sizeof(VersStr), format, os_major); - } - -@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { - // Aligned versions example: - // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 - static void MapToMacos(u16 *major, u16 *minor) { -- if (TARGET_OS_OSX) -- return; -- -- if (TARGET_OS_IOS || TARGET_OS_TV) -+#if !TARGET_OS_OSX -+#if TARGET_OS_IOS || TARGET_OS_TV - *major += 2; -- else if (TARGET_OS_WATCH) -+#elif TARGET_OS_WATCH - *major += 9; -- else -+#else - UNREACHABLE("unsupported platform"); -+#endif - - if (*major >= 16) { // macOS 11+ - *major -= 5; -@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { - *minor = *major; - *major = 10; - } -+#endif - } - - static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/nix/compiler-rt/default.nix b/nix/compiler-rt/default.nix deleted file mode 100644 index 73681bd..0000000 --- a/nix/compiler-rt/default.nix +++ /dev/null @@ -1,160 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - llvm_source, - runCommand, - cmake, - ninja, - python3, - xcbuild, - libllvm, - linuxHeaders, - llvm_libcxxabi, - libxcrypt, - utils, -}: - -let - baseName = "llvm_compiler-rt"; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; - haveLibc = stdenv.cc.libc != null; - useLLVM = true; - bareMetal = false; - inherit (stdenv.hostPlatform) isMusl; - -in stdenv.mkDerivation rec { - pname = baseName + lib.optionalString (haveLibc) "-libc"; - inherit (llvm_source) version; - - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/compiler-rt "$out" - ''; - - sourceRoot = "${src.name}/compiler-rt"; - - nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] - ++ lib.optional stdenv.isDarwin xcbuild.xcrun; - buildInputs = - lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders - ++ lib.optional stdenv.hostPlatform.isDarwin llvm_libcxxabi; - - env.NIX_CFLAGS_COMPILE = toString ([ - "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" - ] ++ lib.optionals (!haveLibc) [ - # The compiler got stricter about this, and there is a usellvm patch below - # which patches out the assert include causing an implicit definition of - # assert. It would be nicer to understand why compiler-rt thinks it should - # be able to #include in the first place; perhaps it's in the - # wrong, or perhaps there is a way to provide an assert.h. - "-Wno-error=implicit-function-declaration" - ]); - - cmakeFlags = [ - "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" - "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ - "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ - "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" - "-DCOMPILER_RT_BUILD_XRAY=OFF" - "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DCOMPILER_RT_BUILD_MEMPROF=OFF" - "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary - ] ++ lib.optionals (useLLVM || bareMetal) [ - "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCOMPILER_RT_BAREMETAL_BUILD=ON" - "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM && !haveLibc) [ - "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - ] ++ lib.optionals (bareMetal) [ - "-DCOMPILER_RT_OS_DIR=baremetal" - ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ - "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" - "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" - "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" - "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" - - # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: - # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 - "-DCOMPILER_RT_ENABLE_IOS=OFF" - ]; - - outputs = [ "out" "dev" ]; - - patches = [ - ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config - ./gnu-install-dirs.patch - # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the - # extra `/`. - ./normalize-var.patch - # Prevent a compilation error on darwin - ./darwin-targetconditionals.patch - # See: https://github.com/NixOS/nixpkgs/pull/186575 - ./darwin-plistbuddy-workaround.patch - # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 - # ../../common/compiler-rt/armv7l-15.patch - ]; - - # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks - # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra - # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd - # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by - # a flag and turn the flag off during the stdenv build. - postPatch = lib.optionalString (!stdenv.isDarwin) '' - substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' - '' + lib.optionalString stdenv.isDarwin '' - substituteInPlace cmake/config-ix.cmake \ - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' - '' + lib.optionalString (useLLVM && !haveLibc) '' - substituteInPlace lib/builtins/int_util.c \ - --replace "#include " "" - substituteInPlace lib/builtins/clear_cache.c \ - --replace "#include " "" - substituteInPlace lib/builtins/cpu_model.c \ - --replace "#include " "" - ''; - - # Hack around weird upsream RPATH bug - postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' - ln -s "$out/lib"/*/* "$out/lib" - '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o - # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. - ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - ''; - - inherit (utils) meta; -} diff --git a/nix/compiler-rt/gnu-install-dirs.patch b/nix/compiler-rt/gnu-install-dirs.patch deleted file mode 100644 index f3b1f63..0000000 --- a/nix/compiler-rt/gnu-install-dirs.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake -index 8a6219568b3f..30ee68a47ccf 100644 ---- a/cmake/base-config-ix.cmake -+++ b/cmake/base-config-ix.cmake -@@ -100,13 +100,13 @@ endif() - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(COMPILER_RT_OUTPUT_LIBRARY_DIR - ${COMPILER_RT_OUTPUT_DIR}/lib) -- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) -+ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") - set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH - "Path where built compiler-rt libraries should be installed.") - else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(COMPILER_RT_OUTPUT_LIBRARY_DIR - ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) -- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") -+ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") - set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH - "Path where built compiler-rt libraries should be installed.") - endif() diff --git a/nix/compiler-rt/normalize-var.patch b/nix/compiler-rt/normalize-var.patch deleted file mode 100644 index 5cbefc7..0000000 --- a/nix/compiler-rt/normalize-var.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake -index 4c85551d7766..297d7a47c54b 100644 ---- a/cmake/Modules/CompilerRTUtils.cmake -+++ b/cmake/Modules/CompilerRTUtils.cmake -@@ -328,8 +328,9 @@ macro(load_llvm_config) - endif() - endif() - -- set(LLVM_LIBRARY_OUTPUT_INTDIR -- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) -+ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR -+ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} -+ REALPATH) - - set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree") - message(STATUS "LLVM_MAIN_SRC_DIR: \"${LLVM_MAIN_SRC_DIR}\"") diff --git a/nix/libcxx/default.nix b/nix/libcxx/default.nix deleted file mode 100644 index ffde722..0000000 --- a/nix/libcxx/default.nix +++ /dev/null @@ -1,128 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - runCommand, - cmake, - ninja, - python3, - fixDarwinDylibNames, - #cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else llvm_libcxxabi, - #libcxxrt, - llvm_libcxxabi, - llvm_libunwind, - llvm_source, - utils, - # If headersOnly is true, the resulting package would only include the headers. - # Use this to break the circular dependency between libcxx and libcxxabi. - # - # Some context: - # https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb - headersOnly ? false -}: -let - basename = "llvm_libcxx"; -in - -assert stdenv.isDarwin -> llvm_libcxxabi.libName == "c++abi"; - -stdenv.mkDerivation rec { - pname = basename + lib.optionalString headersOnly "-headers"; - inherit (llvm_source) version; - - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/libcxx "$out" - mkdir -p "$out/libcxxabi" - cp -r ${llvm_source}/libcxxabi/include "$out/libcxxabi" - mkdir -p "$out/llvm" - cp -r ${llvm_source}/llvm/cmake "$out/llvm" - cp -r ${llvm_source}/llvm/utils "$out/llvm" - cp -r ${llvm_source}/third-party "$out" - cp -r ${llvm_source}/runtimes "$out" - ''; - - sourceRoot = "${src.name}/runtimes"; - - outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; - - prePatch = '' - cd ../libcxx - chmod -R u+w . - ''; - - patches = [ - ./gnu-install-dirs.patch - ]; - - postPatch = '' - cd ../runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; - - buildInputs = - lib.optionals (!headersOnly) [ llvm_libcxxabi ] - ++ lib.optionals (!stdenv.hostPlatform.isWasm) [ llvm_libunwind ]; - - cmakeFlags = let - # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string - libcxx_cxx_abi_opt = { - "c++abi" = "system-libcxxabi"; - "cxxrt" = "libcxxrt"; - }.${llvm_libcxxabi.libName} or (throw "unknown cxxabi: ${llvm_libcxxabi.libName} (${llvm_libcxxabi.pname})"); - in [ - "-DLLVM_ENABLE_RUNTIMES=libcxx" - "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" - "-DLIBCXX_ENABLE_SHARED=OFF" - "-DLIBCXX_USE_COMPILER_RT=ON" - # There's precedent for this in llvm-project/libcxx/cmake/caches. - # In a monorepo build you might do the following in the libcxxabi build: - # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder - # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On - # libcxx appears to require unwind and doesn't pull it in via other means. - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optional (!headersOnly && llvm_libcxxabi.libName == "c++abi") - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${llvm_libcxxabi.dev}/include/c++/v1" - ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ lib.optionals (headersOnly) [ - # If we're only building the headers we don't actually *need* a functioning - # C/C++ compiler: - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ]; - - ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; - installTargets = lib.optional headersOnly "install-cxx-headers"; - - passthru = { - isLLVM = true; - inherit llvm_libcxxabi; - }; - inherit (utils) meta; -} diff --git a/nix/libcxx/gnu-install-dirs.patch b/nix/libcxx/gnu-install-dirs.patch deleted file mode 100644 index ceab7ac..0000000 --- a/nix/libcxx/gnu-install-dirs.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index b8ac536588d3..a2f4d7d5721b 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -401,7 +401,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") - set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1") - set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") -- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING -+ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING - "Path where built libc++ libraries should be installed.") - set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING - "Path where target-specific libc++ headers should be installed.") -@@ -420,7 +420,7 @@ else() - set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1") - endif() - set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") -- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING -+ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE STRING - "Path where built libc++ libraries should be installed.") - set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING - "Path where target-specific libc++ headers should be installed.") diff --git a/nix/libcxxabi/default.nix b/nix/libcxxabi/default.nix deleted file mode 100644 index a87a8e6..0000000 --- a/nix/libcxxabi/default.nix +++ /dev/null @@ -1,129 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ - lib, - stdenv, - cmake, - ninja, - python3, - runCommand, - fetchpatch, - cxx-headers, - llvm_libunwind, - utils, - llvm_source, -}: - -stdenv.mkDerivation rec { - pname = "llvm_libcxxabi"; - inherit (llvm_source) version; - - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/libcxxabi "$out" - mkdir -p "$out/libcxx/src" - cp -r ${llvm_source}/libcxx/cmake "$out/libcxx" - cp -r ${llvm_source}/libcxx/include "$out/libcxx" - cp -r ${llvm_source}/libcxx/src/include "$out/libcxx/src" - mkdir -p "$out/llvm" - cp -r ${llvm_source}/llvm/cmake "$out/llvm" - cp -r ${llvm_source}/llvm/utils "$out/llvm" - cp -r ${llvm_source}/runtimes "$out" - ''; - - sourceRoot = "${src.name}/runtimes"; - - outputs = [ "out" "dev" ]; - - postUnpack = lib.optionalString stdenv.isDarwin '' - export TRIPLE=x86_64-apple-darwin - ''; - - prePatch = '' - cd ../libcxxabi - chmod -R u+w . - ''; - - patches = [ - ./gnu-install-dirs.patch - # Patch to allow libcxxabi standalone installation - # `LIBCXXABI_LIBCXX_INCLUDES` is not doing anything in the - # vanilla source from the llvm-project, and it will be removed - # in the future. - ./standalone.patch - #./test.patch - ]; - - postPatch = '' - cd ../runtimes - ''; - - nativeBuildInputs = [ cmake ninja python3 ]; - buildInputs = [ llvm_libunwind ]; - - ninjaFlags = [ "-v" ]; - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=libcxxabi" - "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" - - # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached - # (we specify the headers it should use explicitly above). - # - # CMake however checks for this anyways; this flag tells it not to. See: - # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 - "-DCMAKE_CXX_COMPILER_WORKS=ON" - ] ++ lib.optionals (!stdenv.hostPlatform.isWasm) [ - "-DLLVM_ENABLE_LIBCXX=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - "-DLIBCXXABI_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - - # We care only about the static libcxxabi - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - preInstall = lib.optionalString stdenv.isDarwin '' - for file in lib/*.dylib; do - # this should be done in CMake, but having trouble figuring out - # the magic combination of necessary CMake variables - # if you fancy a try, take a look at - # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling - install_name_tool -id $out/$file $file - done - ''; - - postInstall = '' - mkdir -p "$dev/include" - install -m 644 ../../libcxxabi/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" - ''; - - passthru = { - libName = "c++abi"; - }; - - inherit (utils) meta; -} diff --git a/nix/libcxxabi/gnu-install-dirs.patch b/nix/libcxxabi/gnu-install-dirs.patch deleted file mode 100644 index a547297..0000000 --- a/nix/libcxxabi/gnu-install-dirs.patch +++ /dev/null @@ -1,44 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index f380fe6b6b92..40ed4793dafb 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -188,7 +188,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) - set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) -- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING -+ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING - "Path where built libc++abi libraries should be installed.") - if(LIBCXX_LIBDIR_SUBDIR) - string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) -@@ -202,7 +202,7 @@ else() - set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) - set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) - endif() -- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE STRING -+ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE STRING - "Path where built libc++abi libraries should be installed.") - endif() - -diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt -index 0d861cff980c..6a2a2b14fafd 100644 ---- a/test/CMakeLists.txt -+++ b/test/CMakeLists.txt -@@ -17,9 +17,14 @@ else() - set(LIBCXXABI_TEST_DEPS cxxabi_static) - endif() - --list(APPEND LIBCXXABI_TEST_DEPS cxx) --if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind) -- list(APPEND LIBCXXABI_TEST_DEPS unwind) -+if(libcxx IN_LIST LLVM_ENABLE_RUNTIMES) -+ list(APPEND LIBCXXABI_TEST_DEPS cxx) -+endif() -+ -+if(libunwind IN_LIST LLVM_ENABLE_RUNTIMES) -+ if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind) -+ list(APPEND LIBCXXABI_TEST_DEPS unwind) -+ endif() - endif() - - set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!") diff --git a/nix/libcxxabi/standalone.patch b/nix/libcxxabi/standalone.patch deleted file mode 100644 index 9c82e9f..0000000 --- a/nix/libcxxabi/standalone.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/CMakeLists.txt b/libcxxabi/CMakeLists.txt -index f380fe6b6b92..60fca2687be0 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -132,10 +132,17 @@ if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC) - message(FATAL_ERROR "libc++abi must be built as either a shared or static library.") - endif() - --# TODO: Remove this, which shouldn't be necessary since we know we're being built --# side-by-side with libc++. - set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH - "Specify path to libc++ includes.") -+if (NOT libcxx IN_LIST LLVM_ENABLE_RUNTIMES) -+ if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES}) -+ message(FATAL_ERROR -+ "LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. " -+ "Please provide the path to where the libc++ headers have been installed.") -+ endif() -+ add_library(cxx-headers INTERFACE) -+ target_include_directories(cxx-headers INTERFACE "${LIBCXXABI_LIBCXX_INCLUDES}") -+endif() - - set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT OFF) - if (WIN32) diff --git a/nix/libunwind/default.nix b/nix/libunwind/default.nix deleted file mode 100644 index 64b2ba6..0000000 --- a/nix/libunwind/default.nix +++ /dev/null @@ -1,69 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - cmake, - ninja, - python3, - utils, - runCommand, - llvm_source, -}: -stdenv.mkDerivation rec{ - pname = "llvm_libunwind"; - inherit (llvm_source) version; - - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/libunwind "$out" - mkdir -p "$out/libcxx" - cp -r ${llvm_source}/libcxx/cmake "$out/libcxx" - cp -r ${llvm_source}/libcxx/utils "$out/libcxx" - mkdir -p "$out/llvm" - cp -r ${llvm_source}/llvm/cmake "$out/llvm" - cp -r ${llvm_source}/llvm/utils "$out/llvm" - cp -r ${llvm_source}/runtimes "$out" - ''; - - sourceRoot = "${src.name}/runtimes"; - - prePatch = '' - cd ../libunwind - chmod -R u+w . - ''; - - patches = [ - ./gnu-install-dirs.patch - ]; - - postPatch = '' - cd ../runtimes - ''; - - outputs = [ "out" "dev" ]; - - nativeBuildInputs = [ cmake ninja python3 ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=libunwind" - "-DLIBUNWIND_ENABLE_SHARED=OFF" - "-DLIBUNWIND_ENABLE_CROSS_UNWINDING=ON" - "-DLIBUNWIND_USE_COMPILER_RT=ON" - ]; - - inherit (utils) meta; -} diff --git a/nix/libunwind/gnu-install-dirs.patch b/nix/libunwind/gnu-install-dirs.patch deleted file mode 100644 index 9410517..0000000 --- a/nix/libunwind/gnu-install-dirs.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 5a06805f05f1..86a50329e6a8 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -117,7 +117,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH - - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) -- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH -+ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH - "Path where built libunwind libraries should be installed.") - if(LIBCXX_LIBDIR_SUBDIR) - string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) -@@ -129,6 +129,6 @@ else() - else() - set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) - endif() -- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH -+ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH - "Path where built libunwind libraries should be installed.") - endif() diff --git a/nix/llvm.nix b/nix/llvm.nix deleted file mode 100644 index 6d34007..0000000 --- a/nix/llvm.nix +++ /dev/null @@ -1,360 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - llvm_source, - utils, - cmake, - ninja, - libxml2, - python3, - fetchgit, - fetchurl, - # llvm_libcxx, - # llvm_compiler-rt, - # llvm_libcxxabi, - # llvm_libunwind, - zlib, - wrapCCWith, - runCommand, - overrideCC, - ccache ? null, - useCcache ? false, - url ? "https://github.com/llvm/llvm-project.git", - hash ? "sha256-8MEDLLhocshmxoEBRSKlJ/GzJ8nfuzQ8qn0X/vLA+ag=", - version ? "17.0.6", - ref ? "refs/tags/llvmorg-${version}" -}: -let - useLLVM = true; - ncpus = "32"; #builtins.getEnv "NIX_BUILD_CORES"; - major = llvm_source.major; - target = stdenv.targetPlatform.config; - - # We're going to build "include-what-you-use" with our llvm build - iwyu = stdenv.mkDerivation rec { - pname = "include-what-you-use"; - version = "0.21"; - - src = builtins.fetchTarball { - url = "https://${pname}.org/downloads/${pname}-${version}.src.tar.gz"; - sha256 = "14z2r95wbrqpany565zbp3apij54b28mjk4s83hkgsh31ym0zpnw"; - }; - # phases = [ "unpackPhase" "installPhase" ]; - - # installPhase = '' - # mkdir -p $out - # cp -rv $src $out - # ''; - }; - - vanilla = stdenv.mkDerivation (final: rec{ - inherit (llvm_source) version; - pname = "serene_llvm"; - - NIX_CFLAGS_COMPILE = [ "-v" ]; - NIX_CXXFLAGS_COMPILE = [ "-v" ]; - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/libcxxabi "$out" - cp -r ${llvm_source}/libcxx "$out/libcxx" - - cp -r ${llvm_source}/llvm "$out" - cp -r ${llvm_source}/lld "$out" - cp -r ${llvm_source}/clang-tools-extra "$out" - cp -r ${llvm_source}/clang "$out" - cp -r ${llvm_source}/compiler-rt "$out" - cp -r ${llvm_source}/mlir "$out" - cp -r ${llvm_source}/bolt "$out" - cp -r ${llvm_source}/libunwind "$out" - cp -r ${llvm_source}/third-party "$out" - cp -r ${llvm_source}/utils "$out" - - cp -r ${llvm_source}/runtimes "$out" - ''; - sourceRoot = "${src.name}/llvm"; - - nativeBuildInputs = [ cmake ninja python3 zlib ]; - buildInputs = [ libxml2 zlib ]; - - #NIX_CFLAGS_COMPILE = ["-fno-rtti"]; - #ninjaFlags = [ "-v" ]; - - cmakeFlags' = [ - # "-DLLVM_PARALLEL_COMPILE_JOBS=${ncpus}" - # "-DLLVM_PARALLEL_LINK_JOBS=1" - "-DLLVM_BUILD_EXAMPLES=ON" - "-DLLVM_TARGETS_TO_BUILD='X86'" - "-DCMAKE_BUILD_TYPE=Release" - "-DLLVM_ENABLE_ASSERTIONS=ON" - "-DLLVM_CCACHE_BUILD=OFF" - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" - - "-DLLVM_EXTERNAL_PROJECTS=iwyu" - "-DLLVM_EXTERNAL_IWYU_SOURCE_DIR=${iwyu.src}" - - # No lldb? Yes, lldb links against liblldb.so and since we use - # -static with our executables that wouldn't be easy to handle - # and I'm lazy. We can just compile the lldb or any other debugger - # on the host - "-DLLVM_ENABLE_PROJECTS='clang;lld;mlir;clang-tools-extra'" - "-DLLVM_RUNTIME_TARGETS=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind'" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_RUNTIME_TARGET=${stdenv.hostPlatform.config}" - "-DLLVM_BUILTIN_TARGETS=${stdenv.hostPlatform.config}" - - # Serene uses static libs, so no shared lib - "-DLLVM_ENABLE_PIC=OFF" - "-DLLVM_BUILD_STATIC=OFF" - "-DLLVM_LINK_LLVM_DYLIB=off" - - "-DLLVM_ENABLE_LIBXML2=OFF" - "-DLLVM_BUILD_DOCS=OFF" - "-DLLVM_ENABLE_SPHINX=OFF" - "-DSPHINX_OUTPUT_MAN=OFF" - "-DSPHINX_OUTPUT_HTML=OFF" - - "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" - "-DCLANG_DEFAULT_CXX_STDLIB=libc++" - #"-DCLANG_DEFAULT_LINKER=lld" - "-DCLANG_DEFAULT_OBJCOPY=llvm-objcopy" - "-DCLANG_DEFAULT_RTLIB=compiler-rt" - "-DCLANG_VENDOR_UTI=serene.toolchain" - "-DLLVM_ENABLE_LIBCXX=ON" - - "-DLLVM_ENABLE_NEW_PASS_MANAGER=ON" - "-DLLVM_BUILD_TESTS=OFF" - "-DLLVM_ENABLE_ASSERTIONS=ON" - "-DLLVM_ENABLE_LIBXML2=OFF" - "-DLLVM_ENABLE_TERMINFO=OFF" - #"-DLLVM_ENABLE_ZLIB=FORCE_ON" - "-DLLVM_INCLUDE_BENCHMARKS=OFF" - "-DLLVM_INCLUDE_EXAMPLES=OFF" - "-DLLVM_INCLUDE_TESTS=OFF" - "-DLLVM_INCLUDE_GO_TESTS=OFF" - "-DLLVM_ENABLE_BINDINGS=OFF" - #"-DLLVM_TARGETS_TO_BUILD": "X86;AArch64;AMDGPU;ARM;RISCV;WebAssembly" - "-DLLVM_STATIC_LINK_CXX_STDLIB=OFF" - "-DPACKAGE_VENDOR=Serene" - "-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON" - "-DENABLE_X86_RELAX_RELOCATIONS=ON" - "-DBUILD_SHARED_LIBS=OFF" - "-DLIBUNWIND_ENABLE_SHARED=OFF" - "-DLIBUNWIND_ENABLE_STATIC=ON" - "-DCLANG_ENABLE_BOOTSTRAP=ON" - "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" - "-DLIBCXXABI_ENABLE_SHARED=OFF" - "-DLIBCXX_ABI_VERSION=2" - - "-DLLVM_HAVE_LIBXAR=0" - "-DLIBCLANG_BUILD_STATIC=ON" - - "-DCOMPILER_RT_BUILD_BUILTINS=ON" - "-DCOMPILER_RT_USE_LIBCXX=ON" - "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - "-DLIBCLANG_BUILD_STATIC=ON" - "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" - - "-DCOMPILER_RT_ENABLE_STATIC_UNWINDER=ON" - "-DSANITIZER_USE_STATIC_LLVM_UNWINDER=ON" - "-DSANITIZER_USE_STATIC_CXX_ABI=ON" - ] ++ lib.optional (stdenv.hostPlatform.isMusl) [ - "-DDLIBCXX_HAS_MUSL_LIBC=ON" - # ] ++ lib.optional (stdenv.hostPlatform.isStatic) [ - # "-DLIBCLANG_BUILD_STATIC=ON" - ] ++ lib.optional (useCcache) [ - "-DLLVM_CCACHE_BUILD=ON" - ]; - - builtinFlags = [ - "-DBUILTINS_${target}_CMAKE_C_COMPILER_TARGET=${target}" - "-DBUILTINS_${target}_CMAKE_CXX_COMPILER_TARGET=${target}" - "-DBUILTINS_${target}_CMAKE_ASM_COMPILER_TARGET=${target}" - "-DBUILTINS_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - # "CMAKE_EXE_LINKER_FLAGS=--target=${target} {self.buildenv.get('LDFLAGS', '')}" - # "CMAKE_SHARED_LINKER_FLAGS=--target=${target} {self.buildenv.get('LDFLAGS', '')}" - "-DBUILTINS_${target}_CMAKE_INSTALL_RPATH=\$ORIGIN/../lib" - "-DBUILTINS_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH=ON" - "-DBUILTINS_${target}_COMPILER_RT_BAREMETAL_BUILD=ON" - "-DBUILTINS_${target}_COMPILER_RT_DEFAULT_TARGET_ONLY=ON" - "-DBUILTINS_${target}_LIBUNWIND_ENABLE_SHARED=OFF" - "-DBUILTINS_${target}_LIBUNWIND_ENABLE_STATIC=ON" - "-DBUILTINS_${target}_LIBCXXABI_ENABLE_SHARED=OFF" - "-DBUILTINS_${target}_LIBCXX_ENABLE_SHARED=OFF" - - "-DBUILTINS_${target}_COMPILER_RT_ENABLE_STATIC_UNWINDER=ON" - "-DBUILTINS_${target}_SANITIZER_USE_STATIC_LLVM_UNWINDER=ON" - "-DBUILTINS_${target}_SANITIZER_USE_STATIC_CXX_ABI=ON" - ] ++ lib.optional (useLLVM) [ - #"-DBUILTINS_${target}_LLVM_USE_LINKER=lld" - ] ++ lib.optional (useCcache) [ - "-DBUILTINS_${target}_LLVM_CCACHE_BUILD=ON" - ]; - - runtimeFlags = [ - "-DRUNTIMES_${target}_CMAKE_C_COMPILER_TARGET=${target}" - "-DRUNTIMES_${target}_CMAKE_CXX_COMPILER_TARGET=${target}" - "-DRUNTIMES_${target}_CMAKE_ASM_COMPILER_TARGET=${target}" - "-DRUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" - "-DRUNTIMES_${target}_CMAKE_INSTALL_RPATH=\$ORIGIN/../lib" - "-DRUNTIMES_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH=ON" - "-DRUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE=ON" - "-DRUNTIMES_${target}_LLVM_USE_LTO=ON" - - # Make sure we use libc++ from the tree instead from the system. - "-DRUNTIMES_${target}_LIBCXX_ENABLE_SHARED=OFF" - "-DRUNTIMES_${target}_SANITIZER_CXX_ABI=libc++" - "-DRUNTIMES_${target}_SANITIZER_CXX_ABI_INTREE=ON" - "-DRUNTIMES_${target}_LIBCXX_CXX_ABI=libcxxabi" - "-DRUNTIMES_${target}_LIBCXX_USE_COMPILER_RT=ON" - "-DRUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" - "-DRUNTIMES_${target}_LIBCXX_ABI_UNSTABLE=ON" - "-DRUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY=OFF" - "-DRUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON" - "-DRUNTIMES_${target}_LIBCXX_ABI_VERSION=2" - "-DRUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS=ON" - "-DRUNTIMES_${target}_LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL=OFF" - "-DRUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT=ON" - "-DRUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER=ON" - "-DRUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER=ON" - "-DRUNTIMES_${target}_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY=OFF" - "-DRUNTIMES_${target}_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=ON" - "-DRUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED=OFF" - "-DRUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT=ON" - ] ++ (lib.optional (useLLVM) [ - #"-DRUNTIMES_${target}_LLVM_USE_LINKER=lld" - ]) ++ lib.optional (useCcache) [ - "-DRUNTIMES_${target}_LLVM_CCACHE_BUILD=ON" - ] ++ (lib.optional (stdenv.hostPlatform.isMusl) [ - # TODO: Check for more sanitizers that work with musl - "-DRUNTIMES_${target}_COMPILER_RT_SANITIZERS_TO_BUILD='asan;msan;tsan'" - "-DRUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY=ON" - "-DRUNTIMES_${target}_COMPILER_RT_USE_LIBCXX=ON" - "-DRUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS=ON" - # musl doesn't have -latomic - "-DRUNTIMES_${target}_LIBCXX_HAS_ATOMIC_LIB=OFF" - - "-DRUNTIMES_${target}_LIBCXX_HAS_MUSL_LIBC=ON" - # For some reason this flag is not correctly set if we don't - # manually set it and some strange gnu only LDFLAGS are injected. - "-DRUNTIMES_${target}_COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT=OFF" - # X-Ray doesn't seem to compiler with musl - "-DRUNTIMES_${target}_COMPILER_RT_BUILD_XRAY=OFF" - # Only build these if we enable sanitizers since they depend - # on the sanitizer common runtime - "-DRUNTIMES_${target}_COMPILER_RT_BUILD_MEMPROF=ON" - "-DRUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER=OFF" - "-DRUNTIMES_${target}_COMPILER_RT_BUILD_ORC=ON" - "-DRUNTIMES_${target}_LIBUNWIND_ENABLE_SHARED=OFF" - "-DRUNTIMES_${target}_LIBUNWIND_ENABLE_STATIC=ON" - - "-DRUNTIMES_${target}_COMPILER_RT_ENABLE_STATIC_UNWINDER=ON" - "-DRUNTIMES_${target}_SANITIZER_USE_STATIC_LLVM_UNWINDER=ON" - "-DRUNTIMES_${target}_SANITIZER_USE_STATIC_CXX_ABI=ON" - ]); - - cmakeFlags = cmakeFlags' ++ builtinFlags ++ runtimeFlags; - - ninjaFlags = [ - - #"install-clang" - "install-builtins" - "install-compiler-rt" - "install-runtimes" - "tools/iwyu/install" - ]; - - - meta = { - homepage = "https://llvm.org/"; - description = "A collection of modular and reusable compiler and toolchain technologies"; - longDescription = '' - The LLVM Project is a collection of modular and reusable compiler and - toolchain technologies. Despite its name, LLVM has little to do with - traditional virtual machines. The name "LLVM" itself is not an acronym; it - is the full name of the project. - LLVM began as a research project at the University of Illinois, with the - goal of providing a modern, SSA-based compilation strategy capable of - supporting both static and dynamic compilation of arbitrary programming - languages. Since then, LLVM has grown to be an umbrella project consisting - of a number of subprojects, many of which are being used in production by - a wide variety of commercial and open source projects as well as being - widely used in academic research. Code in the LLVM project is licensed - under the "Apache 2.0 License with LLVM exceptions". - ''; - license = lib.licenses.ncsa; - - # TODO: Add the maintainer - # maintainers = "Sameer Rahmani []"; - - # See llvm/cmake/config-ix.cmake. - platforms = - lib.platforms.aarch64 ++ - lib.platforms.arm ++ - lib.platforms.mips ++ - lib.platforms.power ++ - lib.platforms.s390x ++ - lib.platforms.wasi ++ - lib.platforms.x86 ++ - lib.platforms.riscv ++ - lib.platforms.m68k; - }; - }); - - vanila.passthru = { - isLLVM = true; - # libc_bin = stdenv.cc.binutils.libc_bin; - # libc_dev = stdenv.cc.binutils.libc_dev; - cxxabi = vanila; - libc = stdenv.cc.libc; - }; - - tools = lib.makeExtensible (tools: - let - mkExtraBuildCommands0 = cc: '' - rsrc="$out/resource-root" - mkdir "$rsrc" - ln -s "${vanilla}/lib/clang/${major}/include" "$rsrc" - echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags - ''; - - mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' - ln -s "${vanilla}/lib" "$rsrc/lib" - ln -s "${vanilla}/share" "$rsrc/share" - ''; - - bintools' = vanilla; - in { - clang = wrapCCWith rec { - cc = vanilla; - libcxx = vanilla; - libc = stdenv.cc.libc; - extraBuildCommands = mkExtraBuildCommands cc; - nixSupport.cc-cflags = - [ "-rtlib=compiler-rt" - "-lc++" - "-lc++abi" - "-Wno-unused-command-line-argument" - "-B${vanilla}/lib" - ] ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" - ++ lib.optional (!stdenv.targetPlatform.isWasm && (useLLVM || false)) - "-lunwind" - ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; - }; - }); -in vanilla diff --git a/nix/llvm/TLI-musl.patch b/nix/llvm/TLI-musl.patch deleted file mode 100644 index fd2a0e5..0000000 --- a/nix/llvm/TLI-musl.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001 -From: Natanael Copa -Date: Thu, 18 Feb 2016 10:33:04 +0100 -Subject: [PATCH 2/3] Fix build with musl libc - -On musl libc the fopen64 and fopen are the same thing, but for -compatibility they have a `#define fopen64 fopen`. Same applies for -fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64. ---- - include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h -index 7becdf0..7f14427 100644 ---- a/include/llvm/Analysis/TargetLibraryInfo.h -+++ b/include/llvm/Analysis/TargetLibraryInfo.h -@@ -18,6 +18,15 @@ - #include "llvm/IR/Module.h" - #include "llvm/Pass.h" - -+#undef fopen64 -+#undef fseeko64 -+#undef fstat64 -+#undef fstatvfs64 -+#undef ftello64 -+#undef lstat64 -+#undef stat64 -+#undef tmpfile64 -+ - namespace llvm { - /// VecDesc - Describes a possible vectorization of a function. - /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized --- -2.7.3 diff --git a/nix/llvm/default.nix b/nix/llvm/default.nix deleted file mode 100644 index 313b7d7..0000000 --- a/nix/llvm/default.nix +++ /dev/null @@ -1,399 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ lib, - stdenv, - utils, - llvm_source, - pkgsBuildBuild, - runCommand, - cmake, - darwin, - ninja, - python3, - python3Packages, - libffi, - enableGoldPlugin ? true, - libbfd, - libpfm, - libxml2, - ncurses, - zlib, - which, - sysctl, - buildLlvmTools, - debugVersion ? false, - doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) - && (stdenv.hostPlatform == stdenv.buildPlatform), - enableSharedLibraries ? false, - enablePFM ? false, - enablePolly ? true, -}: - -let - inherit (lib) optional optionals optionalString; - release_version = llvm_source.version; - - # Used when creating a version-suffixed symlink of libLLVM.dylib - shortVersion = with lib; - concatStringsSep "." (take 1 (splitString "." release_version)); - - # Ordinarily we would just the `doCheck` and `checkDeps` functionality - # `mkDerivation` gives us to manage our test dependencies (instead of breaking - # out `doCheck` as a package level attribute). - # - # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in - # particular the children it uses to do feature detection. - # - # This means that python deps we add to `checkDeps` (which the python - # interpreter is made aware of via `$PYTHONPATH` – populated by the python - # setup hook) are not picked up by `lit` which causes it to skip tests. - # - # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work - # because this package is shadowed in `$PATH` by the regular `python3` - # package. - # - # So, we "manually" assemble one python derivation for the package to depend - # on, taking into account whether checks are enabled or not: - python = if doCheck then - # Note that we _explicitly_ ask for a python interpreter for our host - # platform here; the splicing that would ordinarily take care of this for - # us does not seem to work once we use `withPackages`. - let - checkDeps = ps: with ps; [ psutil ]; - in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps - else python3; - -in - -stdenv.mkDerivation (rec { - pname = "llvm_llvm"; - inherit (llvm_source) version; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out" - cp -r ${llvm_source}/cmake "$out" - cp -r ${llvm_source}/llvm "$out" - cp -r ${llvm_source}/third-party "$out" - '' + lib.optionalString enablePolly '' - chmod u+w "$out/llvm/tools" - cp -r ${llvm_source}/polly "$out/llvm/tools" - ''); - - sourceRoot = "${src.name}/llvm"; - - outputs = [ "out" "lib" "dev" "python" ]; - - nativeBuildInputs = [ cmake ninja python ]; - - buildInputs = [ libxml2 libffi ] - ++ optional enablePFM libpfm; # exegesis - - propagatedBuildInputs = [ ncurses zlib ]; - - nativeCheckInputs = [ - which - ] ++ lib.optional stdenv.isDarwin sysctl; - - patches = [ - ./gnu-install-dirs.patch - - # Running the tests involves invoking binaries (like `opt`) that depend on - # the LLVM dylibs and reference them by absolute install path (i.e. their - # nix store path). - # - # Because we have not yet run the install phase (we're running these tests - # as part of `checkPhase` instead of `installCheckPhase`) these absolute - # paths do not exist yet; to work around this we point the loader (`ld` on - # unix, `dyld` on macOS) at the `lib` directory which will later become this - # package's `lib` output. - # - # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` - # dir but: - # - this doesn't generalize well to other platforms; `lit` doesn't forward - # `DYLD_LIBRARY_PATH` (macOS): - # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 - # - even if `lit` forwarded this env var, we actually cannot set - # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because - # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for - # "protected processes" (i.e. the python interpreter that runs `lit`): - # https://stackoverflow.com/a/35570229 - # - other LLVM subprojects deal with this issue by having their `lit` - # configuration set these env vars for us; it makes sense to do the same - # for LLVM: - # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 - # - # !!! TODO: look into upstreaming this patch - ./llvm-lit-cfg-add-libs-to-dylib-path.patch - - # `lit` has a mode where it executes run lines as a shell script which is - # constructs; this is problematic for macOS because it means that there's - # another process in between `lit` and the binaries being tested. As noted - # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our - # tests fail with dyld errors. - # - # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when - # present in the test configuration. - # - # It's not clear to me why this isn't an issue for LLVM developers running - # on macOS (nothing about this _seems_ nix specific).. - ./lit-shell-script-runner-set-dyld-library-path.patch - ] ++ lib.optionals enablePolly [ - ./gnu-install-dirs-polly.patch - - # Just like the `llvm-lit-cfg` patch, but for `polly`. - ./polly-lit-cfg-add-libs-to-dylib-path.patch - ]; - - postPatch = optionalString stdenv.isDarwin '' - substituteInPlace cmake/modules/AddLLVM.cmake \ - --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - - # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick - # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 - rm test/MC/ELF/cfi-version.ll - - # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) - # and thus fails under the sandbox: - substituteInPlace unittests/TargetParser/Host.cpp \ - --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" - - # This test tries to call the intrinsics `@llvm.roundeven.f32` and - # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` - # and `roundeven` on macOS. - # - # However these functions are glibc specific so the test fails: - # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html - # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html - # - substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ - --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ - --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" - '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' - # This test fails on darwin x86_64 because `sw_vers` reports a different - # macOS version than what LLVM finds by reading - # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into - # the sandbox on macOS). - # - # The `sw_vers` provided by nixpkgs reports the macOS version associated - # with the `CoreFoundation` framework with which it was built. Because - # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what - # `sw_vers` reports is not guaranteed to match the macOS version of the host - # that's building this derivation. - # - # Astute readers will note that we only _patch_ this test on aarch64-darwin - # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. - # So why does this test pass on aarch64? - # - # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ - # CoreFoundation framework instead of the nixpkgs provided one. - # - # Not entirely sure what the right fix is here. I'm assuming aarch64 - # `sw_vers` doesn't intentionally link against the host `CoreFoundation` - # (still digging into how this ends up happening, will follow up) but that - # aside I think the more pertinent question is: should we be patching LLVM's - # macOS version detection logic to use `sw_vers` instead of reading host - # paths? This *is* a way in which details about builder machines can creep - # into the artifacts that are produced, affecting reproducibility, but it's - # not clear to me when/where/for what this even gets used in LLVM. - # - # TODO(@rrbutani): fix/follow-up - substituteInPlace unittests/TargetParser/Host.cpp \ - --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" - - # This test fails with a `dysmutil` crash; have not yet dug into what's - # going on here (TODO(@rrbutani)). - rm test/tools/dsymutil/ARM/obfuscated.test - '' + '' - # FileSystem permissions tests fail with various special bits - substituteInPlace unittests/Support/CMakeLists.txt \ - --replace "Path.cpp" "" - rm unittests/Support/Path.cpp - substituteInPlace unittests/IR/CMakeLists.txt \ - --replace "PassBuilderCallbacksTest.cpp" "" - rm unittests/IR/PassBuilderCallbacksTest.cpp - rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test - '' + optionalString stdenv.hostPlatform.isMusl '' - patch -p1 -i ${./TLI-musl.patch} - substituteInPlace unittests/Support/CMakeLists.txt \ - --replace "add_subdirectory(DynamicLibrary)" "" - rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp - # valgrind unhappy with musl or glibc, but fails w/musl only - rm test/CodeGen/AArch64/wineh4.mir - '' + optionalString stdenv.hostPlatform.isAarch32 '' - # skip failing X86 test cases on 32-bit ARM - rm test/DebugInfo/X86/convert-debugloc.ll - rm test/DebugInfo/X86/convert-inlined.ll - rm test/DebugInfo/X86/convert-linked.ll - rm test/tools/dsymutil/X86/op-convert.test - rm test/tools/gold/X86/split-dwarf.ll - rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s - rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s - rm test/CodeGen/RISCV/attributes.ll - rm test/CodeGen/RISCV/xtheadmempair.ll - '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' - # Seems to require certain floating point hardware (NEON?) - rm test/ExecutionEngine/frem.ll - '' + '' - patchShebangs test/BugPoint/compile-custom.ll.py - ''; - - preConfigure = '' - # Workaround for configure flags that need to have spaces - cmakeFlagsArray+=( - -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" - ) - ''; - - # Defensive check: some paths (that we make symlinks to) depend on the release - # version, for example: - # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 - # - # So we want to sure that the version in the source matches the release - # version we were given. - # - # We do this check here, in the LLVM build, because it happens early. - postConfigure = let - v = lib.versions; - major = v.major release_version; - minor = v.minor release_version; - patch = v.patch release_version; - in '' - # $1: part, $2: expected - check_version() { - part="''${1^^}" - part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" - - if [[ "$part" != "$2" ]]; then - echo >&2 \ - "mismatch in the $1 version! we have version ${release_version}" \ - "and expected the $1 version to be '$2'; the source has '$part' instead" - exit 3 - fi - } - - check_version major ${major} - check_version minor ${minor} - check_version patch ${patch} - ''; - - # E.g. mesa.drivers use the build-id as a cache key (see #93946): - LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; - - cmakeBuildType = if debugVersion then "Debug" else "Release"; - - cmakeFlags = with stdenv; let - # These flags influence llvm-config's BuildVariables.inc in addition to the - # general build. We need to make sure these are also passed via - # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native - # will return different results from the cross llvm-config. - # - # Some flags don't need to be repassed because LLVM already does so (like - # CMAKE_BUILD_TYPE), others are irrelevant to the result. - flagsForLlvmConfig = [ - "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" - "-DLLVM_ENABLE_RTTI=ON" - ] ++ optionals enableSharedLibraries [ - "-DLLVM_LINK_LLVM_DYLIB=ON" - ]; - in flagsForLlvmConfig ++ [ - "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc - "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" - "-DLLVM_ENABLE_FFI=ON" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_DUMP=ON" - - - "-DLLVM_ENABLE_LIBCXX=ON" - "-DLLVM_ENABLE_LIBCXXABI=ON" - - # Static build options ===== - # Disables building of shared libs, -fPIC is still injected by cc-wrapper - "-DLLVM_ENABLE_PIC=OFF" - "-DLLVM_BUILD_STATIC=ON" - "-DLLVM_LINK_LLVM_DYLIB=off" - # libxml2 needs to be disabled because the LLVM build system ignores its .la - # file and doesn't link zlib as well. - # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 - "-DLLVM_ENABLE_LIBXML2=OFF" - # ==== - - ] ++ optionals stdenv.hostPlatform.isDarwin [ - "-DCAN_TARGET_i386=false" - ] ++ optionals enableGoldPlugin [ - # For LLVMgold plugin - "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" - ] ++ optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ - "-DCMAKE_CROSSCOMPILING=True" - "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" - ( - let - nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; - nativeBintools = nativeCC.bintools.bintools; - nativeToolchainFlags = [ - "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" - "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" - "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" - "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" - "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" - ]; - # We need to repass the custom GNUInstallDirs values, otherwise CMake - # will choose them for us, leading to wrong results in llvm-config-native - nativeInstallFlags = [ - "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" - "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" - "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" - "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" - "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" - ]; - in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" - + lib.concatStringsSep ";" (lib.concatLists [ - flagsForLlvmConfig - nativeToolchainFlags - nativeInstallFlags - ]) - ) - ]; - - postInstall = '' - mkdir -p $python/share - mv $out/share/opt-viewer $python/share/opt-viewer - moveToOutput "bin/llvm-config*" "$dev" - substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ - --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ - --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" - substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ - --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' - '' - + optionalString (stdenv.isDarwin && enableSharedLibraries) '' - ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib - ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib - '' - + optionalString ((stdenv.buildPlatform != stdenv.hostPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) '' - cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native - ''; - - inherit doCheck; - - checkTarget = "check-all"; - - # For the update script: - passthru.monorepoSrc = llvm_source; - - requiredSystemFeatures = [ "big-parallel" ]; - inherit (utils) meta; -}) diff --git a/nix/llvm/gnu-install-dirs-polly.patch b/nix/llvm/gnu-install-dirs-polly.patch deleted file mode 100644 index b01363e..0000000 --- a/nix/llvm/gnu-install-dirs-polly.patch +++ /dev/null @@ -1,19 +0,0 @@ -This is the one remaining Polly install dirs related change that hasn't made it -into upstream yet; previously this patch file also included: -https://reviews.llvm.org/D117541 - -diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake -index 518a09b45a42..bd9d6f5542ad 100644 ---- a/tools/polly/cmake/polly_macros.cmake -+++ b/tools/polly/cmake/polly_macros.cmake -@@ -44,8 +44,8 @@ macro(add_polly_library name) - if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") - install(TARGETS ${name} - EXPORT LLVMExports -- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} -- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) -+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} -+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) - endif() - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) - endmacro(add_polly_library) diff --git a/nix/llvm/gnu-install-dirs.patch b/nix/llvm/gnu-install-dirs.patch deleted file mode 100644 index a903974..0000000 --- a/nix/llvm/gnu-install-dirs.patch +++ /dev/null @@ -1,137 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 471817d68286..c51463304159 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -1010,7 +1010,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") - add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src - ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) - install(TARGETS tf_xla_runtime EXPORT LLVMExports -- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) -+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) - # Once we add more modules, we should handle this more automatically. - if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) -diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake -index 230620c37027..dd16cab1835e 100644 ---- a/cmake/modules/AddLLVM.cmake -+++ b/cmake/modules/AddLLVM.cmake -@@ -876,8 +876,8 @@ macro(add_llvm_library name) - get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) - install(TARGETS ${name} - ${export_to_llvmexports} -- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} -- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} -+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} -+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) - - if (NOT LLVM_ENABLE_IDE) -@@ -2069,7 +2069,7 @@ function(llvm_install_library_symlink name dest type) - set(LLVM_LINK_OR_COPY copy) - endif() - -- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) -+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) - if(WIN32 AND "${type}" STREQUAL "SHARED") - set(output_dir "${CMAKE_INSTALL_BINDIR}") - endif() -@@ -2344,16 +2344,37 @@ function(llvm_setup_rpath name) - - if (APPLE) - set(_install_name_dir INSTALL_NAME_DIR "@rpath") -- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) -+ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) - # $ORIGIN is not interpreted at link time by aix ld. - # Since BUILD_SHARED_LIBS is only recommended for use by developers, - # hardcode the rpath to build/install lib dir first in this mode. - # FIXME: update this when there is better solution. -- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) -+ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - elseif(UNIX) -- set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) -- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") -+ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back -+ # to `_install_rpath` here. -+ # -+ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e. -+ # clang); instead LLVM is its own package and thus lands at its own nix -+ # store path. This makes it so that the default relative rpath (`../lib/`) -+ # does not point at the LLVM shared objects. -+ # -+ # More discussion here: -+ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329 -+ # - https://reviews.llvm.org/D146918 (16.0.5+) -+ # -+ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is -+ # no potential that this will result in us pulling in the "wrong" LLVM. -+ # Adding this to the build rpath means we aren't forced to use -+ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build -+ # dir, pre-install, will have the right rpath for LLVM). -+ # -+ # As noted in the differential above, an alternative solution is to have -+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set -+ # `CMAKE_INSTALL_RPATH`. -+ set(_build_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) -+ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") - set_property(TARGET ${name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-z,origin ") -diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake -index 891c9e6d618c..8d963f3b0069 100644 ---- a/cmake/modules/AddOCaml.cmake -+++ b/cmake/modules/AddOCaml.cmake -@@ -147,9 +147,9 @@ function(add_ocaml_library name) - endforeach() - - if( APPLE ) -- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") -+ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") - elseif( UNIX ) -- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") -+ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") - endif() - list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") - -diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt -index d99af79aa38e..21e794224b99 100644 ---- a/cmake/modules/CMakeLists.txt -+++ b/cmake/modules/CMakeLists.txt -@@ -127,7 +127,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS - ) - list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) - --extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") -+extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") - set(LLVM_CONFIG_LIBRARY_DIRS - "${LLVM_CONFIG_LIBRARY_DIR}" - # FIXME: Should there be other entries here? -diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in -index 370005cd8d7d..7e790bc52111 100644 ---- a/tools/llvm-config/BuildVariables.inc.in -+++ b/tools/llvm-config/BuildVariables.inc.in -@@ -23,6 +23,7 @@ - #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" - #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" - #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" -+#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" - #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" - #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" - #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" -diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp -index e86eb2b44b10..f63e207e792e 100644 ---- a/tools/llvm-config/llvm-config.cpp -+++ b/tools/llvm-config/llvm-config.cpp -@@ -366,7 +366,11 @@ int main(int argc, char **argv) { - sys::fs::make_absolute(ActivePrefix, Path); - ActiveBinDir = std::string(Path.str()); - } -- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; -+ { -+ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); -+ sys::fs::make_absolute(ActivePrefix, Path); -+ ActiveLibDir = std::string(Path.str()); -+ } - { - SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); - sys::fs::make_absolute(ActivePrefix, Path); diff --git a/nix/llvm/lit-shell-script-runner-set-dyld-library-path.patch b/nix/llvm/lit-shell-script-runner-set-dyld-library-path.patch deleted file mode 100644 index 82b7b21..0000000 --- a/nix/llvm/lit-shell-script-runner-set-dyld-library-path.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py -index 0242e0b75af3..d732011306f7 100644 ---- a/utils/lit/lit/TestRunner.py -+++ b/utils/lit/lit/TestRunner.py -@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): - f.write('@echo off\n') - f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) - else: -+ # This env var is *purged* when invoking subprocesses so we have to -+ # manually set it from within the bash script in order for the commands -+ # in run lines to see this var: -+ if "DYLD_LIBRARY_PATH" in test.config.environment: -+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') -+ - for i, ln in enumerate(commands): - match = re.match(kPdbgRegex, ln) - if match: diff --git a/nix/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch b/nix/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch deleted file mode 100644 index 2e2f98c..0000000 --- a/nix/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch +++ /dev/null @@ -1,79 +0,0 @@ -diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py -index 81e8dc04acea..479ff95681e2 100644 ---- a/test/Unit/lit.cfg.py -+++ b/test/Unit/lit.cfg.py -@@ -3,6 +3,7 @@ - # Configuration file for the 'lit' test runner. - - import os -+import platform - import subprocess - - import lit.formats -@@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir): - # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. - if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ: - config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"] -+ -+# Add the LLVM dynamic libs to the platform-specific loader search path env var: -+# -+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. -+def find_shlibpath_var(): -+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]: -+ yield "LD_LIBRARY_PATH" -+ elif platform.system() == "Darwin": -+ yield "DYLD_LIBRARY_PATH" -+ elif platform.system() == "Windows": -+ yield "PATH" -+ elif platform.system() == "AIX": -+ yield "LIBPATH" -+ -+for shlibpath_var in find_shlibpath_var(): -+ shlibpath = os.path.pathsep.join( -+ (config.shlibdir, -+ config.environment.get(shlibpath_var, ''))) -+ config.environment[shlibpath_var] = shlibpath -+ break -+else: -+ lit_config.warning("unable to inject shared library path on '{}'" -+ .format(platform.system())) -diff --git a/test/lit.cfg.py b/test/lit.cfg.py -index 75a38b4c5dad..856fc75c9d74 100644 ---- a/test/lit.cfg.py -+++ b/test/lit.cfg.py -@@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) - llvm_config.with_system_environment( - ["HOME", "INCLUDE", "LIB", "TMP", "TEMP"]) - -+# Add the LLVM dynamic libs to the platform-specific loader search path env var: -+# -+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. -+def find_shlibpath_var(): -+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]: -+ yield "LD_LIBRARY_PATH" -+ elif platform.system() == "Darwin": -+ yield "DYLD_LIBRARY_PATH" -+ elif platform.system() == "Windows": -+ yield "PATH" -+ elif platform.system() == "AIX": -+ yield "LIBPATH" -+ -+for shlibpath_var in find_shlibpath_var(): -+ shlibpath = config.llvm_shlib_dir -+ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) -+ break -+else: -+ lit_config.warning("unable to inject shared library path on '{}'" -+ .format(platform.system())) - - # Set up OCAMLPATH to include newly built OCaml libraries. - top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml") -@@ -318,7 +338,7 @@ def have_cxx_shared_library(): - - try: - readobj_cmd = subprocess.Popen( -- [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE -+ [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment - ) - except OSError: - print("could not exec llvm-readobj") diff --git a/nix/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch b/nix/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch deleted file mode 100644 index a1875e7..0000000 --- a/nix/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg -index 41e3a589c61e..09f3b17498b0 100644 ---- a/tools/polly/test/lit.cfg -+++ b/tools/polly/test/lit.cfg -@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] - path = os.path.pathsep.join(base_paths + config.extra_paths) - config.environment['PATH'] = path - -+# (Copied from polly/test/Unit/lit.cfg) -+if platform.system() == 'Darwin': -+ shlibpath_var = 'DYLD_LIBRARY_PATH' -+elif platform.system() == 'Windows': -+ shlibpath_var = 'PATH' -+else: -+ shlibpath_var = 'LD_LIBRARY_PATH' -+ - path = os.path.pathsep.join((config.llvm_libs_dir, -- config.environment.get('LD_LIBRARY_PATH',''))) --config.environment['LD_LIBRARY_PATH'] = path -+ config.environment.get(shlibpath_var,''))) -+config.environment[shlibpath_var] = path - - llvm_config.use_default_substitutions() - diff --git a/nix/llvm_source.nix b/nix/llvm_source.nix deleted file mode 100644 index f23337d..0000000 --- a/nix/llvm_source.nix +++ /dev/null @@ -1,41 +0,0 @@ -# Serene Programming Language -# -# Copyright (c) 2019-2023 Sameer Rahmani -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 2. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -{ - lib, - stdenv, - fetchgit, - url ? "https://github.com/llvm/llvm-project.git", - hash ? "sha256-8MEDLLhocshmxoEBRSKlJ/GzJ8nfuzQ8qn0X/vLA+ag=", - version ? "17.0.6", - ref ? "refs/tags/llvmorg-${version}" -}: -stdenv.mkDerivation rec{ - pname = "llvm_source"; - inherit version; - - major = lib.versions.major version; - src = fetchgit { - inherit url hash; - rev = ref; - }; - unpackPhase = "true"; - - phases = [ "unpackPhase" "installPhase" ]; - installPhase = '' - mkdir -p "$out" - cp -rv "$src"/* "$out/" - ''; -}