push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake
index 75b0080f6715..c895b884cd27 100644
--- a/cmake/modules/AddClang.cmake
+++ b/cmake/modules/AddClang.cmake
@@ -119,8 +119,8 @@ macro(add_clang_library name)
install(TARGETS ${lib}
COMPONENT ${lib}
${export_to_clangtargets}
- 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}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if (NOT LLVM_ENABLE_IDE)
diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt
index f2b0c5cddcbb..52f37fc368ce 100644
--- a/lib/Headers/CMakeLists.txt
+++ b/lib/Headers/CMakeLists.txt
@@ -473,6 +473,7 @@ add_header_target("windows-resource-headers" ${windows_only_files})
add_header_target("utility-resource-headers" ${utility_files})
get_clang_resource_dir(header_install_dir SUBDIR include)
+set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include)
#############################################################
# Install rules for the catch-all clang-resource-headers target
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index 4f23065a2472..6a0f55991e24 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -234,7 +234,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS})
COMPONENT
libclang-python-bindings
DESTINATION
- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
+ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
endforeach()
if(NOT LLVM_ENABLE_IDE)
add_custom_target(libclang-python-bindings)
diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt
index 3aca22c0b0a8..3115353e3fe3 100644
--- a/tools/scan-build-py/CMakeLists.txt
+++ b/tools/scan-build-py/CMakeLists.txt
@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib})
install(FILES lib/libscanbuild/${lib}
- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild"
COMPONENT scan-build-py)
endforeach()
@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource})
install(FILES lib/libscanbuild/resources/${resource}
- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild/resources
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources"
COMPONENT scan-build-py)
endforeach()
@@ -122,7 +122,7 @@ foreach(lib ${LibEar})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib})
install(FILES lib/libear/${lib}
- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libear
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear"
COMPONENT scan-build-py)
endforeach()

View File

@@ -0,0 +1,25 @@
From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
From: Will Dietz <w@wdtz.org>
Date: Thu, 18 May 2017 11:56:12 -0500
Subject: [PATCH] "purity" patch for 5.0
---
lib/Driver/ToolChains/Gnu.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
index fe3c0191bb..c6a482bece 100644
--- a/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -446,9 +446,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
ToolChain.isPIEDefault(Args));
if (IsPIE)
CmdArgs.push_back("-pie");
- CmdArgs.push_back("-dynamic-linker");
- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
- ToolChain.getDynamicLinker(Args)));
}
}
--
2.11.0

View File

@@ -0,0 +1,21 @@
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)$")

View File

@@ -0,0 +1,65 @@
From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001
From: Ben Wolsieffer <benwolsieffer@gmail.com>
Date: Wed, 7 Dec 2022 21:25:46 -0500
Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to
libatomic
Standalone scudo uses the atomic operation builtin functions, which require
linking to libatomic on some platforms. Currently, this is done in an ad-hoc
manner. MIPS platforms always link to libatomic, and the tests are always linked
to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is
currently not linked, causing the build to fail.
This patch replaces this ad-hoc logic with the CheckAtomic CMake module already
used in other parts of LLVM. The CheckAtomic module checks whether std::atomic
requires libatomic, which is not strictly the same as checking the atomic
builtins, but should have the same results as far as I know. If this is
problematic, a custom version of CheckAtomic could be used to specifically test
the builtins.
---
compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++
compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt
index ae5c354768c8..eb27374ca520 100644
--- a/lib/scudo/standalone/CMakeLists.txt
+++ b/lib/scudo/standalone/CMakeLists.txt
@@ -1,5 +1,8 @@
add_compiler_rt_component(scudo_standalone)
+include(DetermineGCCCompatible)
+include(CheckAtomic)
+
include_directories(../.. include)
set(SCUDO_CFLAGS)
@@ -34,6 +37,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)
+if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
+ list(APPEND SCUDO_LINK_FLAGS -latomic)
+endif()
+
# We don't use the C++ standard library, so avoid including it by mistake.
append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt
index 8200cd2588b3..73b3e9403c35 100644
--- a/lib/scudo/standalone/tests/CMakeLists.txt
+++ b/lib/scudo/standalone/tests/CMakeLists.txt
@@ -39,9 +39,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
-# Linking against libatomic is required with some compilers
-check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC)
-if (COMPILER_RT_HAS_LIBATOMIC)
+if (HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic)
endif()
--
2.38.1

View File

@@ -0,0 +1,16 @@
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}\"")

View File

@@ -0,0 +1,10 @@
--- a/libclc.pc.in
+++ b/libclc.pc.in
@@ -1,5 +1,5 @@
-includedir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@
-libexecdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATADIR@/clc
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
+libexecdir=@CMAKE_INSTALL_FULL_DATADIR@/clc
Name: libclc
Description: Library requirements of the OpenCL C programming language

View File

@@ -0,0 +1,15 @@
diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake
index d3924f7243d4..42a7cd62281c 100644
--- a/cmake/modules/AddLLD.cmake
+++ b/cmake/modules/AddLLD.cmake
@@ -18,8 +18,8 @@ macro(add_lld_library name)
install(TARGETS ${name}
COMPONENT ${name}
${export_to_lldtargets}
- 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}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)

View File

@@ -0,0 +1,13 @@
--- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700
+++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700
@@ -45,8 +45,8 @@
install(TARGETS ${name}
COMPONENT ${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})
add_llvm_install_targets(install-${name}
COMPONENT ${name})
endif()

View File

@@ -0,0 +1,137 @@
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 ${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/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath ${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 ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
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);

View File

@@ -0,0 +1,12 @@
--- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700
+++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700
@@ -1183,6 +1183,9 @@
f.write("@echo on\n")
f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
else:
+ 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.fullmatch(kPdbgRegex, ln)
if match:

View File

@@ -0,0 +1,80 @@
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")

View File

@@ -0,0 +1,24 @@
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()

View File

@@ -0,0 +1,17 @@
diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt
index 630947abec7e..9f032dc7bd3f 100644
--- a/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/libomptarget/DeviceRTL/CMakeLists.txt
@@ -27,10 +27,10 @@ endif()
if (LLVM_DIR)
# Builds that use pre-installed LLVM have LLVM_DIR set.
# A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route
- find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
+ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR})
find_program(PACKAGER_TOOL clang-offload-packager PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
- find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
+ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR})
if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL) OR (NOT PACKAGER_TOOL))
libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL}, opt: ${OPT_TOOL}, or clang-offload-packager: ${PACKAGER_TOOL}")
return()

View File

@@ -0,0 +1,71 @@
diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake
index 75b0080f6..c895b884c 100644
--- a/cmake/modules/AddClang.cmake
+++ b/cmake/modules/AddClang.cmake
@@ -119,8 +119,8 @@ macro(add_clang_library name)
install(TARGETS ${lib}
COMPONENT ${lib}
${export_to_clangtargets}
- 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}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if (NOT LLVM_ENABLE_IDE)
diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt
index e6ae4e19e..5ef01aea2 100644
--- a/lib/Headers/CMakeLists.txt
+++ b/lib/Headers/CMakeLists.txt
@@ -337,6 +337,7 @@ set(llvm_libc_wrapper_files
include(GetClangResourceDir)
get_clang_resource_dir(output_dir PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
+set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include)
set(out_files)
set(generated_files)
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index b5b6d2807..6b592d255 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -246,7 +246,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS})
COMPONENT
libclang-python-bindings
DESTINATION
- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
+ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
endforeach()
if(NOT LLVM_ENABLE_IDE)
add_custom_target(libclang-python-bindings)
diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt
index 3aca22c0b..3115353e3 100644
--- a/tools/scan-build-py/CMakeLists.txt
+++ b/tools/scan-build-py/CMakeLists.txt
@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib})
install(FILES lib/libscanbuild/${lib}
- DESTINATION lib/libscanbuild
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild"
COMPONENT scan-build-py)
endforeach()
@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource})
install(FILES lib/libscanbuild/resources/${resource}
- DESTINATION lib/libscanbuild/resources
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources"
COMPONENT scan-build-py)
endforeach()
@@ -122,7 +122,7 @@ foreach(lib ${LibEar})
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib})
list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib})
install(FILES lib/libear/${lib}
- DESTINATION lib/libear
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear"
COMPONENT scan-build-py)
endforeach()

View File

@@ -0,0 +1,62 @@
From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001
From: Ben Wolsieffer <benwolsieffer@gmail.com>
Date: Wed, 7 Dec 2022 21:25:46 -0500
Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to
libatomic
Standalone scudo uses the atomic operation builtin functions, which require
linking to libatomic on some platforms. Currently, this is done in an ad-hoc
manner. MIPS platforms always link to libatomic, and the tests are always linked
to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is
currently not linked, causing the build to fail.
This patch replaces this ad-hoc logic with the CheckAtomic CMake module already
used in other parts of LLVM. The CheckAtomic module checks whether std::atomic
requires libatomic, which is not strictly the same as checking the atomic
builtins, but should have the same results as far as I know. If this is
problematic, a custom version of CheckAtomic could be used to specifically test
the builtins.
---
compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++
compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt
index dc700cec9bec..671dc7046604 100644
--- a/lib/scudo/standalone/CMakeLists.txt
+++ b/lib/scudo/standalone/CMakeLists.txt
@@ -1,5 +1,8 @@
add_compiler_rt_component(scudo_standalone)
+include(DetermineGCCCompatible)
+include(CheckAtomic)
+
include_directories(../.. include)
set(SCUDO_CFLAGS)
@@ -39,6 +42,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)
+if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
+ list(APPEND SCUDO_LINK_FLAGS -latomic)
+endif()
+
# We don't use the C++ standard library, so avoid including it by mistake.
append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt
index a85eb737dba0..a23cf4d494f6 100644
--- a/lib/scudo/standalone/tests/CMakeLists.txt
+++ b/lib/scudo/standalone/tests/CMakeLists.txt
@@ -47,7 +47,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS
${SANITIZER_TEST_CXX_LIBRARIES})
list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
-append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic SCUDO_UNITTEST_LINK_FLAGS)
+append_list_if((HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) -latomic SCUDO_UNITTEST_LINK_FLAGS)
set(SCUDO_TEST_HEADERS
scudo_unit_test.h
2.38.1

View File

@@ -0,0 +1,31 @@
From e8b910246d0c7c3d9fff994f71c6f8a48ec09a50 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.ross@midstall.com>
Date: Sat, 24 Aug 2024 19:56:24 -0700
Subject: [PATCH] [libclc] use default paths with find_program when possible
---
libclc/CMakeLists.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02bb859ae8590b..6bcd8ae52a5794 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,7 +55,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI
# Import required tools
if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
- find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+ find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} )
set( ${tool}_exe ${LLVM_TOOL_${tool}} )
set( ${tool}_target )
endforeach()
@@ -104,7 +104,7 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link )
endforeach()
# llvm-spirv is an optional dependency, used to build spirv-* targets.
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} )
if( LLVM_SPIRV )
add_executable( libclc::llvm-spirv IMPORTED GLOBAL )

View File

@@ -0,0 +1,22 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b0e7aac6f8f3..af17e62588fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,7 +57,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI
# Import required tools
if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
- find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+ find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} )
set( ${tool}_exe ${LLVM_TOOL_${tool}} )
set( ${tool}_target )
endforeach()
@@ -93,7 +93,7 @@ if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
# and custom tools.
foreach( tool IN ITEMS clang llvm-as llvm-link opt )
find_program( LLVM_CUSTOM_TOOL_${tool} ${tool}
- PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+ PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
set( ${tool}_exe ${LLVM_CUSTOM_TOOL_${tool}} )
set( ${tool}_target )
endforeach()

View File

@@ -0,0 +1,13 @@
--- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700
+++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700
@@ -45,8 +45,8 @@
install(TARGETS ${name}
COMPONENT ${name}
${exports}
- 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})
add_llvm_install_targets(install-${name}
COMPONENT ${name})
endif()

View File

@@ -0,0 +1,139 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c9ff3696e22d..bd96aab5e237 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1133,9 +1133,9 @@ 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)
install(TARGETS tf_xla_runtime EXPORT LLVMDevelopmentExports
- 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 baf47677b247..81954240a9bf 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -974,8 +974,8 @@ macro(add_llvm_library name)
endif()
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)
@@ -2243,7 +2243,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()
@@ -2519,16 +2519,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 ${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)
+ # 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/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
+ set(_install_rpath ${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 2d9116b08a52..2dd7cad4ec66 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 ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
endif()
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index ef4cfa3acdb5..7478e157a7c2 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -130,7 +130,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 d5b76b1bb6c1..1dbdb2a8f10d 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);
}
- 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);
+ }
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);

View File

@@ -0,0 +1,8 @@
--- a/libclc.pc.in
+++ b/libclc.pc.in
@@ -1,4 +1,4 @@
-libexecdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATADIR@/clc
+libexecdir=@CMAKE_INSTALL_FULL_DATADIR@/clc
Name: libclc
Description: Library requirements of the OpenCL C programming language

View File

@@ -0,0 +1,140 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 73c4fc14f031..42284703a52c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1153,9 +1153,9 @@ 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)
install(TARGETS tf_xla_runtime EXPORT LLVMDevelopmentExports
- 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 52bf7ca0906a..ba2f4be17f08 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -974,8 +974,8 @@ macro(add_llvm_library name)
endif()
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)
@@ -2258,7 +2258,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 OR CYGWIN) AND "${type}" STREQUAL "SHARED")
set(output_dir "${CMAKE_INSTALL_BINDIR}")
endif()
@@ -2534,16 +2534,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 ${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)
+ # 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/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
+ set(_install_rpath ${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 2d9116b08a52..2dd7cad4ec66 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 ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
endif()
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index ef4cfa3acdb5..7478e157a7c2 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -130,7 +130,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 e4e1d449bf4d..3aab6ea7bf8b 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 49df8fdcb7f7..c7cb05b82821 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -365,7 +365,11 @@ int main(int argc, char **argv) {
sys::fs::make_absolute(ActivePrefix, Path);
ActiveBinDir = std::string(Path);
}
- 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);
+ }
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);

View File

@@ -0,0 +1,139 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a90be4f6235e..be9cef03bfea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1207,9 +1207,9 @@ 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)
install(TARGETS tf_xla_runtime EXPORT LLVMDevelopmentExports
- 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 835750e2d2a1..f7400f708535 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -974,8 +974,8 @@ macro(add_llvm_library name)
endif()
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)
@@ -2263,7 +2263,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 OR CYGWIN) AND "${type}" STREQUAL "SHARED")
set(output_dir "${CMAKE_INSTALL_BINDIR}")
endif()
@@ -2539,16 +2539,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 ${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_PREFIX}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
elseif(UNIX)
+ # 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/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
+ set(_install_rpath ${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 2d9116b08a52..2dd7cad4ec66 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 ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
endif()
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index ef4cfa3acdb5..7478e157a7c2 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -130,7 +130,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 e4e1d449bf4d..3aab6ea7bf8b 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 49df8fdcb7f7..c7cb05b82821 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -365,7 +365,11 @@ int main(int argc, char **argv) {
sys::fs::make_absolute(ActivePrefix, Path);
ActiveBinDir = std::string(Path);
}
- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
+ {
+ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX);
+ sys::path::make_absolute(ActivePrefix, Path);
+ ActiveLibDir = std::string(Path);
+ }
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);

View File

@@ -0,0 +1,98 @@
## How to upgrade llvm_git
- Run `update-git.py`.
This will set the github revision and sha256 for `llvmPackages_git.llvm` to whatever the latest chromium build is using.
For a more recent commit, run `nix-prefetch-github` and change the rev and sha256 accordingly.
- That was the easy part.
The hard part is updating the patch files.
The general process is:
1. Try to build `llvmPackages_git.llvm` and associated packages such as
`clang` and `compiler-rt`. You can use the `-L` and `--keep-failed` flags to make
debugging patch errors easy, e.g., `nix build .#llvmPackages_git.clang -L --keep-failed`
2. The build will error out with something similar to this:
```sh
...
clang-unstable> patching sources
clang-unstable> applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch
clang-unstable> patching file lib/Driver/ToolChains/Gnu.cpp
clang-unstable> Hunk #1 FAILED at 487.
clang-unstable> 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej
note: keeping build directory '/tmp/nix-build-clang-unstable-2022-25-07.drv-17'
error: builder for '/nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv' failed with exit code 1;
last 8 log lines:
> unpacking sources
> unpacking source archive /nix/store/mrxadx11wv1ckjr2208qgxp472pmmg6g-clang-src-unstable-2022-25-07
> source root is clang-src-unstable-2022-25-07/clang
> patching sources
> applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch
> patching file lib/Driver/ToolChains/Gnu.cpp
> Hunk #1 FAILED at 487.
> 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej
For full logs, run 'nix log /nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv'.
note: keeping build directory '/tmp/nix-build-compiler-rt-libc-unstable-2022-25-07.drv-20'
error: 1 dependencies of derivation '/nix/store/ndbbh3wrl0l39b22azf46f1n7zlqwmag-clang-wrapper-unstable-2022-25-07.drv' failed to build
```
Notice the `Hunk #1 Failed at 487` line.
The lines above show us that the `purity.patch` failed on `lib/Driver/ToolChains/Gnu.cpp` when compiling `clang`.
3. The task now is to cross reference the hunks in the purity patch with
`lib/Driver/ToolCahins/Gnu.cpp.orig` to see why the patch failed.
The `.orig` file will be in the build directory referenced in the line `note: keeping build directory ...`;
this message results from the `--keep-failed` flag.
4. Now you should be able to open whichever patch failed, and the `foo.orig` file that it failed on.
Correct the patch by adapting it to the new code and be mindful of whitespace;
which can be an easily missed reason for failures.
For cases where the hunk is no longer needed you can simply remove it from the patch.
This is fine for small corrections, but when more serious changes are needed, it's better to use git.
1. Clone the LLVM monorepo at https://github.com/llvm/llvm-project/
2. Check out the revision we were using before.
3. Use `patch -p1 < path/to-path` in the project subdirectories to apply the patches and commit.
4. Use `git rebase HEAD^ --onto <dest>` to rebase the patches onto the new revision we are trying to build, and fix all conflicts.
5. Use `git diff HEAD^:<project> HEAD:<project>` to get subdir diff to write back to Nixpkgs.
## Information on our current patch sets
### "GNU Install Dirs" patches
Use CMake's [`GNUInstallDirs`](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) to support multiple outputs.
Previously, LLVM just hard-coded `bin`, `include`, and `lib${LLVM_TARGET_PREFIX}`.
We are making it use these variables.
For the older LLVM versions, these patches live in https://github.com/Ericson2314/llvm-project branches `split-prefix`.
Instead of applying the patches to the worktree per the above instructions, one can checkout those directly and rebase those instead.
For newer LLVM versions, enough has been upstreamed,
(see https://reviews.llvm.org/differential/query/5UAfpj_9zHwY/ for my progress upstreaming),
that I have just assembled new gnu-install-dirs patches from the remaining unmerged patches instead of rebasing from the prior LLVM's gnu install dirs patch.
## Adding a patch
To add an LLVM patch in the Nixpkgs tree,
1. Put the patch in the corresponding directory (`<VERSION>/<PACKAGE>`).
_Example_: If you want your patch to apply to clang version 12 (and, optionally, later versions), put it in `./12/clang`.
2. Add the patch to the `patches` argument of the corresponding package in `./common`, guarded by a `lib.optionals` with the desired version constraints, passed through the `getVersionFile` function.
_Example_: If you want the patch `./12/llvm/fix-llvm-issue-49955.patch` to apply to LLVM 12, add `lib.optional (lib.versions.major release_version == "12") (getVersionFile "llvm/fix-llvm-issue-49955.patch")` to `./common/llvm/default.nix`.
3. If you wish for this single patch to apply to multiple versions of the package, extend the conditions in the `lib.optional` guard and add the corresponding constraints to `./common/patches.nix`; note that `after` is inclusive and `before` is exclusive.
_Example_:
If you want the patch `./12/clang/purity.patch` to apply to versions 12, 13 and 14, you have to
- Modify the guard in `./common/clang/default.nix` as follows: `lib.optional (lib.versionAtLeast release_version "12" && lib.versionOlder release_version "15")`
- Add `{ "clang/purity.patch" = [ { after = 12; before = 15; path = ../12; } ]; }` to `common/patches.nix`.
You may have multiple different patches with the same name that would apply to different versions; in that case, add the necessary constraints to `common/patches.nix`.

View File

@@ -0,0 +1,59 @@
{
lib,
runCommand,
stdenv,
llvm,
lld,
version,
release_version,
}:
let
targetPrefix = lib.optionalString (
stdenv.hostPlatform != stdenv.targetPlatform
) "${stdenv.targetPlatform.config}-";
in
runCommand "llvm-binutils-${version}"
{
preferLocalBuild = true;
passthru = {
isLLVM = true;
inherit targetPrefix;
inherit llvm lld;
};
}
''
mkdir -p $out/bin
for prog in ${lld}/bin/*; do
ln -s $prog $out/bin/${targetPrefix}$(basename $prog)
done
for prog in ${llvm}/bin/*; do
ln -sf $prog $out/bin/${targetPrefix}$(basename $prog)
done
llvmBin="${llvm}/bin"
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib
ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt
ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp
ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip
ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump
ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf
ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size
ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings
ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line
if [ -e "$llvmBin/llvm-debuginfod" ]; then
ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod
ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find
fi
ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld
# Only >=13 show GNU windres compatible in help
ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres
''

View File

@@ -0,0 +1,92 @@
{
lib,
stdenv,
llvm_meta,
monorepoSrc,
release_version,
runCommand,
cmake,
libxml2,
libllvm,
ninja,
libclang,
version,
python3,
buildLlvmTools,
patches ? [ ],
devExtraCmakeFlags ? [ ],
fetchpatch,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "bolt";
inherit version;
# Blank llvm dir just so relative path works
src = runCommand "bolt-src-${finalAttrs.version}" { inherit (monorepoSrc) passthru; } ''
mkdir $out
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/third-party "$out"
# BOLT re-runs tablegen against LLVM sources, so needs them available.
cp -r ${monorepoSrc}/llvm/ "$out"
chmod -R +w $out/llvm
'';
sourceRoot = "${finalAttrs.src.name}/bolt";
patches = lib.optionals (lib.versions.major release_version == "19") [
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/abc2eae68290c453e1899a94eccc4ed5ea3b69c1.patch";
hash = "sha256-oxCxOjhi5BhNBEraWalEwa1rS3Mx9CuQgRVZ2hrbd7M=";
})
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/5909979869edca359bcbca74042c2939d900680e.patch";
hash = "sha256-l4rQHYbblEADBXaZIdqTG0sZzH4fEQvYiqhLYNZDMa8=";
})
];
nativeBuildInputs = [
cmake
ninja
python3
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
]
++ devExtraCmakeFlags;
postUnpack = ''
chmod -R u+w -- $sourceRoot/..
'';
prePatch = ''
cd ..
'';
postPatch = ''
cd bolt
'';
postInstall = ''
mkdir -p $dev/lib
mv $out/lib/libLLVMBOLT*.a $dev/lib
'';
outputs = [
"out"
"dev"
];
meta = llvm_meta // {
homepage = "https://github.com/llvm/llvm-project/tree/main/bolt";
description = "LLVM post-link optimizer";
};
})

View File

@@ -0,0 +1,59 @@
{
lib,
stdenv,
clang-unwrapped,
clang,
libcxxClang,
llvm_meta,
# enableLibcxx will use the c++ headers from clang instead of gcc.
# This shouldn't have any effect on platforms that use clang as the default compiler already.
enableLibcxx ? false,
}:
stdenv.mkDerivation {
unwrapped = clang-unwrapped;
pname = "clang-tools";
version = lib.getVersion clang-unwrapped;
dontUnpack = true;
clang = if enableLibcxx then libcxxClang else clang;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
for tool in $unwrapped/bin/clang-*; do
tool=$(basename "$tool")
# Compilers have their own derivation, no need to include them here:
if [[ $tool == "clang-cl" || $tool == "clang-cpp" ]]; then
continue
fi
# Clang's derivation produces a lot of binaries, but the tools we are
# interested in follow the `clang-something` naming convention - except
# for clang-$version (e.g. clang-13), which is the compiler again:
if [[ ! $tool =~ ^clang\-[a-zA-Z_\-]+$ ]]; then
continue
fi
ln -s $out/bin/clangd $out/bin/$tool
done
if [[ -z "$(ls -A $out/bin)" ]]; then
echo "Found no binaries - maybe their location or naming convention changed?"
exit 1
fi
substituteAll ${./wrapper} $out/bin/clangd
chmod +x $out/bin/clangd
runHook postInstall
'';
meta = llvm_meta // {
description = "Standalone command line tools for C++ development";
maintainers = with lib.maintainers; [ patryk27 ];
};
}

View File

@@ -0,0 +1,27 @@
#!/bin/sh
buildcpath() {
local path after
while (( $# )); do
case $1 in
-isystem)
shift
path=$path${path:+':'}$1
;;
-idirafter)
shift
after=$after${after:+':'}$1
;;
esac
shift
done
echo $path${after:+':'}$after
}
export CPATH=${CPATH}${CPATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \
$(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include
export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}${CPLUS_INCLUDE_PATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \
$(<@clang@/nix-support/libcxx-cxxflags) \
$(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include
exec -a "$0" @unwrapped@/bin/$(basename $0) "$@"

View File

@@ -0,0 +1,14 @@
diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp
index 34640b3c450d..93c4a4f4ec5c 100644
--- a/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/lib/Driver/ToolChains/CommonArgs.cpp
@@ -589,8 +589,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
#endif
SmallString<1024> Plugin;
- llvm::sys::path::native(Twine(D.Dir) +
- "/../" CLANG_INSTALL_LIBDIR_BASENAME +
+ llvm::sys::path::native(Twine("@libllvmLibdir@") +
PluginName + Suffix,
Plugin);
CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));

View File

@@ -0,0 +1,75 @@
From 7ef5ed98cc6666f64db2f155ded2077ce038e1e4 Mon Sep 17 00:00:00 2001
From: Reno Dakota <paparodeo@proton.me>
Date: Sat, 16 Nov 2024 05:57:40 +0000
Subject: [PATCH] [Clang][Driver] report unsupported option error regardless of
argument order
This change updates clang to report unsupported option errors regardless
of the command line argument order.
When clang with a source file and without `-c` it will both compile and
link. When an unsupported option is also part of the command line clang
should generated an error. However, if the source file name comes before
an object file, eg: `-lc`, the error is ignored.
```
$ clang --target=x86_64 -lc hello.c -mhtm
clang: error: unsupported option '-mhtm' for target 'x86_64'
$ echo $?
1
```
but if `-lc` comes after `hello.c` the error is dropped
```
$ clang --target=x86_64 hello.c -mhtm -lc
$ echo $?
0
```
after this change clang will report the error regardless of the command
line argument order.
---
clang/lib/Driver/Driver.cpp | 13 ++++++-------
clang/test/Driver/unsupported-option.c | 10 ++++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93e85f7dffe35a..8e784a7b130ac3 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -4064,17 +4064,18 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
YcArg = YuArg = nullptr;
}
- unsigned LastPLSize = 0;
+ bool LinkOnly = phases::Link == FinalPhase && Inputs.size() > 0;
for (auto &I : Inputs) {
types::ID InputType = I.first;
const Arg *InputArg = I.second;
auto PL = types::getCompilationPhases(InputType);
- LastPLSize = PL.size();
+
+ phases::ID InitialPhase = PL[0];
+ LinkOnly = LinkOnly && phases::Link == InitialPhase && PL.size() == 1;
// If the first step comes after the final phase we are doing as part of
// this compilation, warn the user about it.
- phases::ID InitialPhase = PL[0];
if (InitialPhase > FinalPhase) {
if (InputArg->isClaimed())
continue;
@@ -4129,10 +4130,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
}
}
- // If we are linking, claim any options which are obviously only used for
- // compilation.
- // FIXME: Understand why the last Phase List length is used here.
- if (FinalPhase == phases::Link && LastPLSize == 1) {
+ // claim any options which are obviously only used for compilation.
+ if (LinkOnly) {
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
}

View File

@@ -0,0 +1,261 @@
{
lib,
stdenv,
llvm_meta,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
release_version,
version,
python3,
buildLlvmTools,
fixDarwinDylibNames,
enableManpages ? false,
enableClangToolsExtra ? true,
devExtraCmakeFlags ? [ ],
replaceVars,
getVersionFile,
fetchpatch,
# for tests
libclang,
}:
stdenv.mkDerivation (
finalAttrs:
{
pname = "clang";
inherit version;
src =
if monorepoSrc != null then
runCommand "clang-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/clang "$out"
${lib.optionalString enableClangToolsExtra "cp -r ${monorepoSrc}/clang-tools-extra \"$out\""}
''
else
src;
sourceRoot = "${finalAttrs.src.name}/clang";
patches = [
(getVersionFile "clang/purity.patch")
# Remove extraneous ".a" suffix from baremetal clang_rt.builtins when compiling for baremetal.
# https://reviews.llvm.org/D51899
(getVersionFile "clang/gnu-install-dirs.patch")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# https://github.com/llvm/llvm-project/pull/116476
# prevent clang ignoring warnings / errors for unsuppored
# options when building & linking a source file with trailing
# libraries. eg: `clang -munsupported hello.c -lc`
./clang-unsupported-option.patch
]
# Pass the correct path to libllvm
++ [
(replaceVars ./clang-at-least-16-LLVMgold-path.patch {
libllvmLibdir = "${libllvm.lib}/lib";
})
]
# Fixes a bunch of lambda-related crashes
# https://github.com/llvm/llvm-project/pull/93206
++ lib.optional (lib.versions.major release_version == "18") (fetchpatch {
name = "tweak-tryCaptureVariable-for-unevaluated-lambdas.patch";
url = "https://github.com/llvm/llvm-project/commit/3d361b225fe89ce1d8c93639f27d689082bd8dad.patch";
# TreeTransform.h is not affected in LLVM 18.
excludes = [
"docs/ReleaseNotes.rst"
"lib/Sema/TreeTransform.h"
];
stripLen = 1;
hash = "sha256-1NKej08R9SPlbDY/5b0OKUsHjX07i9brR84yXiPwi7E=";
});
nativeBuildInputs = [
cmake
python3
ninja
]
++ lib.optionals enableManpages [
python3.pkgs.myst-parser
python3.pkgs.sphinx
]
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [
libxml2
libllvm
];
cmakeFlags = [
(lib.cmakeFeature "CLANG_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/clang")
(lib.cmakeBool "CLANGD_BUILD_XPC" false)
(lib.cmakeBool "LLVM_ENABLE_RTTI" true)
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
(lib.cmakeFeature "CLANG_TABLEGEN" "${buildLlvmTools.tblgen}/bin/clang-tblgen")
]
++ lib.optionals (lib.versionAtLeast release_version "21") [
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "${placeholder "lib"}/lib/clang/${lib.versions.major release_version}")
]
# TODO: Clean up on `staging`.
++ [
(lib.cmakeBool "LLVM_INCLUDE_TESTS" false)
]
++ lib.optionals enableManpages [
(lib.cmakeBool "CLANG_INCLUDE_DOCS" true)
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
# TODO: Clean up on `staging`.
++ [
# 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
(lib.cmakeFeature "CLANG_TIDY_CONFUSABLE_CHARS_GEN" "${buildLlvmTools.tblgen}/bin/clang-tidy-confusable-chars-gen")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# clang-pseudo removed in LLVM20: https://github.com/llvm/llvm-project/commit/ed8f78827895050442f544edef2933a60d4a7935
(lib.cmakeFeature "CLANG_PSEUDO_GEN" "${buildLlvmTools.tblgen}/bin/clang-pseudo-gen")
]
++ lib.optional (lib.versionAtLeast release_version "20") (
lib.cmakeFeature "LLVM_DIR" "${libllvm.dev}/lib/cmake/llvm"
)
++ devExtraCmakeFlags;
postPatch = ''
# Make sure clang passes the correct location of libLTO to ld64
substituteInPlace lib/Driver/ToolChains/Darwin.cpp \
--replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";'
(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"
];
separateDebugInfo = stdenv.buildPlatform.is64bit; # OOMs on 32 bit
postInstall = ''
ln -sv $out/bin/clang $out/bin/cpp
''
+ (lib.optionalString
((lib.versionAtLeast release_version "19") && !(lib.versionAtLeast release_version "21"))
''
mv $out/lib/clang $lib/lib/clang
''
)
+ ''
# Move libclang to 'lib' output
moveToOutput "lib/libclang.*" "$lib"
moveToOutput "lib/libclang-cpp.*" "$lib"
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
''
# TODO(@LunNova): Clean up this rebuild avoidance in staging
+ lib.optionalString enableClangToolsExtra (
if lib.versionOlder release_version "20" then
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin
''
else
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen} $dev/bin
''
)
+ lib.optionalString (!enableClangToolsExtra) ''
cp bin/clang-tblgen $dev/bin
'';
env =
lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM)
{
# The following warning is triggered with (at least) gcc >=
# 12, but appears to occur only for cross compiles.
NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized";
};
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlagsByTargetPlatform =
targetPlatform:
[ "fortify3" ]
++ lib.optional (!targetPlatform.isLinux || !targetPlatform.isx86_64) "shadowstack"
++ lib.optional (!targetPlatform.isAarch64 || !targetPlatform.isLinux) "pacret"
++ lib.optional (
!(targetPlatform.isLinux || targetPlatform.isFreeBSD)
|| !(
targetPlatform.isx86
|| targetPlatform.isPower64
|| targetPlatform.isS390x
|| targetPlatform.isAarch64
)
) "stackclashprotection"
++ lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or [ ]);
tests.withoutOptionalFeatures = libclang.override {
enableClangToolsExtra = false;
};
};
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://clang.llvm.org/";
description = "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}";
};
}
)

View File

@@ -0,0 +1,71 @@
{
lib,
fetchFromGitHub ? null,
release_version ? null,
gitRelease ? null,
officialRelease ? null,
monorepoSrc' ? null,
version ? null,
}@args:
rec {
llvm_meta = {
license =
with lib.licenses;
[ ncsa ]
++
# Contributions after June 1st, 2024 are only licensed under asl20 and
# llvm-exception: https://github.com/llvm/llvm-project/pull/92394
lib.optionals (lib.versionAtLeast release_version "19") [
asl20
llvm-exception
];
teams = [ lib.teams.llvm ];
# 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
++ lib.platforms.loongarch64;
identifiers.cpeParts.vendor = "llvm";
};
releaseInfo =
if gitRelease != null then
rec {
original = gitRelease;
release_version = args.version or original.version;
version = gitRelease.rev-version;
}
else
rec {
original = officialRelease;
release_version = args.version or original.version;
version =
if original ? candidate then "${release_version}-${original.candidate}" else release_version;
};
monorepoSrc =
if monorepoSrc' != null then
monorepoSrc'
else
let
sha256 = releaseInfo.original.sha256;
rev = if gitRelease != null then gitRelease.rev else "llvmorg-${releaseInfo.version}";
in
fetchFromGitHub rec {
owner = "llvm";
repo = "llvm-project";
inherit rev sha256;
passthru = { inherit owner repo rev; };
};
}

View File

@@ -0,0 +1,162 @@
From 4fe3f21bf8b20c766877d2251d61118d0ff36688 Mon Sep 17 00:00:00 2001
From: Ben Wolsieffer <benwolsieffer@gmail.com>
Date: Wed, 7 Dec 2022 14:56:51 -0500
Subject: [PATCH] [compiler-rt][builtins] Do not use ldrexd or strexd on ARMv6
The ldrexd and strexd instructions are not available on base ARMv6, and were
only added in ARMv6K (see [1]). This patch solves this problem once and for all
using the __ARM_FEATURE_LDREX macro (see [2]) defined in the ARM C Language
Extensions (ACLE). Although this macro is technically deprecated in the ACLE,
it allows compiler-rt to reliably detect whether ldrexd and strexd are supported
without complicated conditionals to detect different ARM architecture variants.
[1] https://developer.arm.com/documentation/dht0008/a/ch01s02s01
[2] https://arm-software.github.io/acle/main/acle.html#ldrexstrex
Differential Revision: https://reviews.llvm.org/D139585
---
compiler-rt/lib/builtins/arm/sync_fetch_and_add_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_and_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_max_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_min_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_nand_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_or_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_sub_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_umax_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_umin_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_xor_8.S | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lib/builtins/arm/sync_fetch_and_add_8.S b/lib/builtins/arm/sync_fetch_and_add_8.S
index 18bdd875b8b7..bee6f7ba0f34 100644
--- a/lib/builtins/arm/sync_fetch_and_add_8.S
+++ b/lib/builtins/arm/sync_fetch_and_add_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define add_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
adds rD_LO, rN_LO, rM_LO ; \
adc rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_and_8.S b/lib/builtins/arm/sync_fetch_and_and_8.S
index 3716eff809d5..b4e77a54edf6 100644
--- a/lib/builtins/arm/sync_fetch_and_and_8.S
+++ b/lib/builtins/arm/sync_fetch_and_and_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define and_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
and rD_LO, rN_LO, rM_LO ; \
and rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_max_8.S b/lib/builtins/arm/sync_fetch_and_max_8.S
index 06115ab55246..1813274cc649 100644
--- a/lib/builtins/arm/sync_fetch_and_max_8.S
+++ b/lib/builtins/arm/sync_fetch_and_max_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define max_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, gt)
SYNC_OP_8(max_8)
diff --git a/lib/builtins/arm/sync_fetch_and_min_8.S b/lib/builtins/arm/sync_fetch_and_min_8.S
index 4f3e299d95cc..fa8f3477757b 100644
--- a/lib/builtins/arm/sync_fetch_and_min_8.S
+++ b/lib/builtins/arm/sync_fetch_and_min_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define min_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lt)
SYNC_OP_8(min_8)
diff --git a/lib/builtins/arm/sync_fetch_and_nand_8.S b/lib/builtins/arm/sync_fetch_and_nand_8.S
index 425c94474af7..fb27219ee200 100644
--- a/lib/builtins/arm/sync_fetch_and_nand_8.S
+++ b/lib/builtins/arm/sync_fetch_and_nand_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define nand_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
bic rD_LO, rN_LO, rM_LO ; \
bic rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_or_8.S b/lib/builtins/arm/sync_fetch_and_or_8.S
index 4f18dcf84df9..3b077c8737b1 100644
--- a/lib/builtins/arm/sync_fetch_and_or_8.S
+++ b/lib/builtins/arm/sync_fetch_and_or_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define or_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
orr rD_LO, rN_LO, rM_LO ; \
orr rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_sub_8.S b/lib/builtins/arm/sync_fetch_and_sub_8.S
index 25a4a1076555..c171607eabd8 100644
--- a/lib/builtins/arm/sync_fetch_and_sub_8.S
+++ b/lib/builtins/arm/sync_fetch_and_sub_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define sub_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
subs rD_LO, rN_LO, rM_LO ; \
sbc rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_umax_8.S b/lib/builtins/arm/sync_fetch_and_umax_8.S
index aa5213ff1def..d1224f758049 100644
--- a/lib/builtins/arm/sync_fetch_and_umax_8.S
+++ b/lib/builtins/arm/sync_fetch_and_umax_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define umax_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, hi)
SYNC_OP_8(umax_8)
diff --git a/lib/builtins/arm/sync_fetch_and_umin_8.S b/lib/builtins/arm/sync_fetch_and_umin_8.S
index 8b40541ab47d..595444e6d053 100644
--- a/lib/builtins/arm/sync_fetch_and_umin_8.S
+++ b/lib/builtins/arm/sync_fetch_and_umin_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define umin_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lo)
SYNC_OP_8(umin_8)
diff --git a/lib/builtins/arm/sync_fetch_and_xor_8.S b/lib/builtins/arm/sync_fetch_and_xor_8.S
index 7436eb1d4cae..9fc3d85cef75 100644
--- a/lib/builtins/arm/sync_fetch_and_xor_8.S
+++ b/lib/builtins/arm/sync_fetch_and_xor_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define xor_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
eor rD_LO, rN_LO, rM_LO ; \
eor rD_HI, rN_HI, rM_HI
--
2.38.1

View File

@@ -0,0 +1,25 @@
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)

View File

@@ -0,0 +1,292 @@
{
lib,
stdenv,
llvm_meta,
release_version,
version,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
python3,
libllvm,
jq,
libcxx,
linuxHeaders,
freebsd,
libxcrypt,
# Some platforms have switched to using compiler-rt, but still want a
# libgcc.a for ABI compat purposes. The use case would be old code that
# expects to link `-lgcc` but doesn't care exactly what its contents
# are, so long as it provides some builtins.
doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD,
# In recent releases, the compiler-rt build seems to produce
# many `libclang_rt*` libraries, but not a single unified
# `libcompiler_rt` library, at least under certain configurations. Some
# platforms still expect this, however, so we symlink one into place.
forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
}:
let
useLLVM = stdenv.hostPlatform.useLLVM or false;
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
haveLibc = stdenv.cc.libc != null;
# TODO: Make this account for GCC having libstdcxx, which will help
# use clean up the `cmakeFlags` rats nest below.
haveLibcxx = stdenv.cc.libcxx != null;
isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic;
inherit (stdenv.hostPlatform) isMusl isAarch64 isWindows;
noSanitizers = !haveLibc || bareMetal || isMusl || isDarwinStatic || isWindows;
in
stdenv.mkDerivation (finalAttrs: {
pname = "compiler-rt${lib.optionalString haveLibc "-libc"}";
inherit version;
src =
if monorepoSrc != null then
runCommand "compiler-rt-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/third-party "$out"
''
+ ''
cp -r ${monorepoSrc}/compiler-rt "$out"
''
)
else
src;
sourceRoot = "${finalAttrs.src.name}/compiler-rt";
patches = [
(getVersionFile "compiler-rt/X86-support-extension.patch") # Add support for i486 i586 i686 by reusing i386 config
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
(getVersionFile "compiler-rt/normalize-var.patch")
# Fix build on armv6l
./armv6-no-ldrexd-strexd.patch
# See: https://github.com/NixOS/nixpkgs/pull/186575
./darwin-plistbuddy-workaround.patch
]
++ [
(getVersionFile "compiler-rt/armv6-scudo-libatomic.patch")
]
++ lib.optional (lib.versions.major release_version == "19") (fetchpatch {
url = "https://github.com/llvm/llvm-project/pull/99837/commits/14ae0a660a38e1feb151928a14f35ff0f4487351.patch";
hash = "sha256-JykABCaNNhYhZQxCvKiBn54DZ5ZguksgCHnpdwWF2no=";
relative = "compiler-rt";
});
nativeBuildInputs = [
cmake
python3
libllvm.dev
ninja
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ jq ];
buildInputs =
lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders
++ lib.optional (stdenv.hostPlatform.isFreeBSD) freebsd.include;
env = {
NIX_CFLAGS_COMPILE = toString (
[
"-DSCUDO_DEFAULT_OPTIONS=delete_size_mismatch=false:dealloc_type_mismatch=false"
]
++ 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 <assert.h> 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"
]
);
# Work around clangs trying to invoke unprefixed-ld on Darwin when `-target` is passed.
NIX_CFLAGS_LINK = lib.optionalString (stdenv.hostPlatform.isDarwin) "--ld-path=${stdenv.cc.bintools}/bin/${stdenv.cc.targetPrefix}ld";
};
cmakeFlags = [
(lib.cmakeBool "COMPILER_RT_DEFAULT_TARGET_ONLY" true)
(lib.cmakeFeature "CMAKE_C_COMPILER_TARGET" stdenv.hostPlatform.config)
(lib.cmakeFeature "CMAKE_ASM_COMPILER_TARGET" stdenv.hostPlatform.config)
]
++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [
(lib.cmakeFeature "SANITIZER_COMMON_CFLAGS" "-I${libxcrypt}/include")
]
++ lib.optionals (useLLVM && haveLibc && stdenv.cc.libcxx == libcxx) [
(lib.cmakeFeature "SANITIZER_CXX_ABI" "libcxxabi")
(lib.cmakeFeature "SANITIZER_CXX_ABI_LIBNAME" "libcxxabi")
(lib.cmakeBool "COMPILER_RT_USE_BUILTINS_LIBRARY" true)
]
++ lib.optionals (useLLVM && haveLibc) [
(lib.cmakeBool "COMPILER_RT_BUILD_SANITIZERS" true)
(lib.cmakeBool "COMPILER_RT_BUILD_PROFILE" true)
]
++ lib.optionals noSanitizers [
(lib.cmakeBool "COMPILER_RT_BUILD_SANITIZERS" false)
]
++ lib.optionals ((useLLVM && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [
(lib.cmakeBool "COMPILER_RT_BUILD_XRAY" false)
(lib.cmakeBool "COMPILER_RT_BUILD_LIBFUZZER" false)
(lib.cmakeBool "COMPILER_RT_BUILD_MEMPROF" false)
(lib.cmakeBool "COMPILER_RT_BUILD_ORC" false) # may be possible to build with musl if necessary
]
++ lib.optionals (!haveLibc || bareMetal) [
(lib.cmakeBool "COMPILER_RT_BUILD_PROFILE" false)
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "COMPILER_RT_BAREMETAL_BUILD" true)
(lib.cmakeFeature "CMAKE_SIZEOF_VOID_P" (toString (stdenv.hostPlatform.parsed.cpu.bits / 8)))
]
++ lib.optionals (!haveLibc || bareMetal || isDarwinStatic) [
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
]
++ lib.optionals (!haveLibc) [
(lib.cmakeFeature "CMAKE_C_FLAGS" "-nodefaultlibs")
]
++ lib.optionals useLLVM [
(lib.cmakeBool "COMPILER_RT_BUILD_BUILTINS" true)
#https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
(lib.cmakeFeature "CMAKE_TRY_COMPILE_TARGET_TYPE" "STATIC_LIBRARY")
]
++ lib.optionals bareMetal [
(lib.cmakeFeature "COMPILER_RT_OS_DIR" "baremetal")
]
++ lib.optionals (stdenv.hostPlatform.isDarwin) (
[
(lib.cmakeFeature "CMAKE_LIPO" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo")
]
++ lib.optionals (!haveLibcxx) [
# Darwin fails to detect that the compiler supports the `-g` flag when there is no libc++ during the
# compiler-rt bootstrap, which prevents compiler-rt from building. The `-g` flag is required by the
# Darwin support, so force it to be enabled during the first stage of the compiler-rt bootstrap.
(lib.cmakeBool "COMPILER_RT_HAS_G_FLAG" true)
]
++ [
(lib.cmakeFeature "DARWIN_osx_ARCHS" stdenv.hostPlatform.darwinArch)
(lib.cmakeFeature "DARWIN_osx_BUILTIN_ARCHS" stdenv.hostPlatform.darwinArch)
(lib.cmakeFeature "SANITIZER_MIN_OSX_VERSION" stdenv.hostPlatform.darwinMinVersion)
# `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
(lib.cmakeBool "COMPILER_RT_ENABLE_IOS" false)
]
)
++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [
(lib.cmakeBool "COMPILER_RT_BUILD_CTX_PROFILE" false)
]
++
lib.optional (stdenv.hostPlatform.isAarch64 && !haveLibc)
# Fixes https://github.com/NixOS/nixpkgs/issues/393603
(lib.cmakeBool "COMPILER_RT_DISABLE_AARCH64_FMV" true)
++ devExtraCmakeFlags;
outputs = [
"out"
"dev"
];
postPatch =
lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
substituteInPlace cmake/builtin-config-ix.cmake \
--replace-fail 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
''
+ lib.optionalString (!haveLibc) (
(lib.optionalString (lib.versions.major release_version == "18") ''
substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \
--replace-fail "<stdlib.h>" "<stddef.h>"
'')
+ ''
substituteInPlace lib/builtins/int_util.c \
--replace-fail "#include <stdlib.h>" ""
''
+ (lib.optionalString (!stdenv.hostPlatform.isFreeBSD)
# On FreeBSD, assert/static_assert are macros and allowing them to be implicitly declared causes link errors.
# see description above for why we're nuking assert.h normally but that doesn't work here.
# instead, we add the freebsd.include dependency explicitly
''
substituteInPlace lib/builtins/clear_cache.c \
--replace-fail "#include <assert.h>" ""
substituteInPlace lib/builtins/cpu_model/x86.c \
--replace-fail "#include <assert.h>" ""
''
)
)
+
lib.optionalString (lib.versionAtLeast release_version "19")
# codesign in sigtool doesn't support the various options used by the build
# and is present in the bootstrap-tools. Removing find_program prevents the
# build from trying to use it and failing.
''
substituteInPlace cmake/Modules/AddCompilerRT.cmake \
--replace-fail 'find_program(CODESIGN codesign)' ""
'';
preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
cmakeFlagsArray+=(
"-DDARWIN_macosx_CACHED_SYSROOT=$SDKROOT"
"-DDARWIN_macosx_OVERRIDE_SDK_VERSION=$(jq -r .Version "$SDKROOT/SDKSettings.json")"
)
'';
# Hack around weird upstream 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
''
+ lib.optionalString doFakeLibgcc ''
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a
''
+ lib.optionalString forceLinkCompilerRt ''
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a
'';
meta = llvm_meta // {
homepage = "https://compiler-rt.llvm.org/";
description = "Compiler runtime libraries";
longDescription = ''
The compiler-rt project provides highly tuned implementations of the
low-level code generator support routines like "__fixunsdfdi" and other
calls generated when a target doesn't have a short sequence of native
instructions to implement a core IR operation. It also provides
implementations of run-time libraries for dynamic testing tools such as
AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer.
'';
# "All of the code in the compiler-rt project is dual licensed under the MIT
# license and the UIUC License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
broken =
# compiler-rt requires a Clang stdenv on 32-bit RISC-V:
# https://reviews.llvm.org/D43106#1019077
(stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang)
# emutls wants `<pthread.h>` which isn't available (without experimental WASM threads proposal).
# `enable_execute_stack.c` Also doesn't sound like something WASM would support.
|| (stdenv.hostPlatform.isWasm && haveLibc);
};
})

View File

@@ -0,0 +1,517 @@
{
lowPrio,
newScope,
pkgs,
targetPackages,
lib,
stdenv,
libxcrypt,
substitute,
replaceVars,
fetchFromGitHub,
fetchpatch,
fetchpatch2,
overrideCC,
wrapCCWith,
wrapBintoolsWith,
buildPackages,
buildLlvmTools, # tools, but from the previous stage, for cross
targetLlvmLibraries, # libraries, but from the next stage, for cross
targetLlvm,
# This is the default binutils, but with *this* version of LLD rather
# than the default LLVM version's, if LLD is the choice. We use these for
# the `useLLVM` bootstrapping below.
bootBintoolsNoLibc ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintoolsNoLibc,
bootBintools ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintools,
darwin,
gitRelease ? null,
officialRelease ? null,
monorepoSrc ? null,
version ? null,
patchesFn ? lib.id,
# Allows passthrough to packages via newScope. This makes it possible to
# do `(llvmPackages.override { <someLlvmDependency> = bar; }).clang` and get
# an llvmPackages whose packages are overridden in an internally consistent way.
...
}@args:
assert lib.assertMsg (lib.xor (gitRelease != null) (officialRelease != null)) (
"must specify `gitRelease` or `officialRelease`"
+ (lib.optionalString (gitRelease != null) " not both")
);
let
monorepoSrc' = monorepoSrc;
metadata = rec {
# Import releaseInfo separately to avoid infinite recursion
inherit
(import ./common-let.nix {
inherit (args)
lib
gitRelease
officialRelease
version
;
})
releaseInfo
;
inherit (releaseInfo) release_version version;
inherit
(import ./common-let.nix {
inherit
lib
fetchFromGitHub
release_version
gitRelease
officialRelease
monorepoSrc'
version
;
})
llvm_meta
monorepoSrc
;
src = monorepoSrc;
versionDir =
(toString ../.) + "/${if (gitRelease != null) then "git" else lib.versions.major release_version}";
getVersionFile =
p:
builtins.path {
name = baseNameOf p;
path =
let
patches = args.patchesFn (import ./patches.nix);
constraints = patches."${p}" or null;
matchConstraint =
{
before ? null,
after ? null,
path,
}:
let
check = fn: value: if value == null then true else fn release_version value;
matchBefore = check lib.versionOlder before;
matchAfter = check lib.versionAtLeast after;
in
matchBefore && matchAfter;
patchDir =
toString
(
if constraints == null then
{ path = metadata.versionDir; }
else
(lib.findFirst matchConstraint { path = metadata.versionDir; } constraints)
).path;
in
"${patchDir}/${p}";
};
};
tools = lib.makeExtensible (
tools:
let
callPackage = newScope (tools // args // metadata);
clangVersion = lib.versions.major metadata.release_version;
mkExtraBuildCommands0 =
cc:
''
rsrc="$out/resource-root"
mkdir "$rsrc"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
''
# clang standard c headers are incompatible with FreeBSD so we have to put them in -idirafter instead of -resource-dir
# see https://github.com/freebsd/freebsd-src/commit/f382bac49b1378da3c2dd66bf721beaa16b5d471
+ (
if stdenv.targetPlatform.isFreeBSD then
''
echo "-idirafter ${lib.getLib cc}/lib/clang/${clangVersion}/include" >> $out/nix-support/cc-cflags
''
else
''
ln -s "${lib.getLib cc}/lib/clang/${clangVersion}/include" "$rsrc"
''
);
mkExtraBuildCommandsBasicRt =
cc:
mkExtraBuildCommands0 cc
+ ''
ln -s "${targetLlvmLibraries.compiler-rt-no-libc.out}/lib" "$rsrc/lib"
'';
mkExtraBuildCommands =
cc:
mkExtraBuildCommands0 cc
+ ''
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
'';
bintoolsNoLibc' = if bootBintoolsNoLibc == null then tools.bintoolsNoLibc else bootBintoolsNoLibc;
bintools' = if bootBintools == null then tools.bintools else bootBintools;
in
{
libllvm = callPackage ./llvm {
};
# `llvm` historically had the binaries. When choosing an output explicitly,
# we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get*
llvm = tools.libllvm;
tblgen = callPackage ./tblgen.nix {
patches =
builtins.filter
# Crude method to drop polly patches if present, they're not needed for tblgen.
(p: (!lib.hasInfix "-polly" p))
tools.libllvm.patches;
clangPatches = [
# Would take tools.libclang.patches, but this introduces a cycle due
# to replacements depending on the llvm outpath (e.g. the LLVMgold patch).
# So take the only patch known to be necessary.
(metadata.getVersionFile "clang/gnu-install-dirs.patch")
];
};
libclang = callPackage ./clang {
};
clang-unwrapped = tools.libclang;
llvm-manpages = lowPrio (
tools.libllvm.override {
enableManpages = true;
python3 = pkgs.python3; # don't use python-boot
}
);
clang-manpages = lowPrio (
tools.libclang.override {
enableManpages = true;
python3 = pkgs.python3; # don't use python-boot
}
);
# Wrapper for standalone command line utilities
clang-tools = callPackage ./clang-tools { };
# pick clang appropriate for package set we are targeting
clang =
if stdenv.targetPlatform.libc == null then
tools.clangNoLibc
else if stdenv.targetPlatform.isDarwin then
tools.systemLibcxxClang
else if stdenv.targetPlatform.useLLVM or false then
tools.clangUseLLVM
else if (pkgs.targetPackages.stdenv or args.stdenv).cc.isGNU then
tools.libstdcxxClang
else
tools.libcxxClang;
libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [ targetLlvmLibraries.compiler-rt ];
extraBuildCommands = mkExtraBuildCommands cc;
};
libcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
extraPackages = [ targetLlvmLibraries.compiler-rt ];
extraBuildCommands = mkExtraBuildCommands cc;
};
# Darwin uses the system libc++ by default. It is set up as its own clang definition so that `libcxxClang`
# continues to use the libc++ from LLVM.
systemLibcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = darwin.libcxx;
extraPackages = [ targetLlvmLibraries.compiler-rt ];
extraBuildCommands = mkExtraBuildCommands cc;
};
lld = callPackage ./lld {
};
lldbPlugins = lib.makeExtensible (
lldbPlugins:
let
callPackage = newScope (lldbPlugins // tools // args // metadata);
in
lib.recurseIntoAttrs { llef = callPackage ./lldb-plugins/llef.nix { }; }
);
lldb = callPackage ./lldb { };
lldb-manpages = lowPrio (
tools.lldb.override {
enableManpages = true;
python3 = pkgs.python3; # don't use python-boot
}
);
# Below, is the LLVM bootstrapping logic. It handles building a
# fully LLVM toolchain from scratch. No GCC toolchain should be
# pulled in. As a consequence, it is very quick to build different
# targets provided by LLVM and we can also build for what GCC
# doesnt support like LLVM. Probably we should move to some other
# file.
bintools-unwrapped = callPackage ./bintools.nix { };
bintoolsNoLibc = wrapBintoolsWith {
bintools = tools.bintools-unwrapped;
libc = targetPackages.preLibcHeaders;
};
bintools = wrapBintoolsWith { bintools = tools.bintools-unwrapped; };
clangUseLLVM = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
bintools = bintools';
extraPackages = [
targetLlvmLibraries.compiler-rt
]
++ lib.optionals (!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD) [
targetLlvmLibraries.libunwind
];
extraBuildCommands = mkExtraBuildCommands cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-Wno-unused-command-line-argument"
"-B${targetLlvmLibraries.compiler-rt}/lib"
]
++ lib.optional (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
) "--unwindlib=libunwind"
++ lib.optional (
!stdenv.targetPlatform.isWasm
&& !stdenv.targetPlatform.isFreeBSD
&& stdenv.targetPlatform.useLLVM or false
) "-lunwind"
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
nixSupport.cc-ldflags = lib.optionals (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
};
clangWithLibcAndBasicRtAndLibcxx = wrapCCWith rec {
cc = tools.clang-unwrapped;
# This is used to build compiler-rt. Make sure to use the system libc++ on Darwin.
libcxx = if stdenv.hostPlatform.isDarwin then darwin.libcxx else targetLlvmLibraries.libcxx;
bintools = bintools';
extraPackages = [
targetLlvmLibraries.compiler-rt-no-libc
]
++
lib.optionals
(
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
)
[
targetLlvmLibraries.libunwind
];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-Wno-unused-command-line-argument"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
]
++ lib.optional (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
) "--unwindlib=libunwind"
++ lib.optional (
!stdenv.targetPlatform.isWasm
&& !stdenv.targetPlatform.isFreeBSD
&& stdenv.targetPlatform.useLLVM or false
) "-lunwind"
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
nixSupport.cc-ldflags = lib.optionals (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
};
clangWithLibcAndBasicRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintools';
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
"-nostdlib++"
]
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
clangNoLibcWithBasicRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc';
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
]
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
clangNoLibcNoRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc';
extraPackages = [ ];
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
extraBuildCommands = mkExtraBuildCommands0 cc;
nixSupport.cc-cflags = lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
# This is an "oddly ordered" bootstrap just for Darwin. Probably
# don't want it otherwise.
clangNoCompilerRtWithLibc =
wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintools';
extraPackages = [ ];
extraBuildCommands = mkExtraBuildCommands0 cc;
}
# FIXME: This should be inside the `wrapCCWith` call.
// lib.optionalAttrs stdenv.targetPlatform.isWasm {
nixSupport.cc-cflags = [ "-fno-exceptions" ];
};
# Aliases
clangNoCompilerRt = tools.clangNoLibcNoRt;
clangNoLibc = tools.clangNoLibcWithBasicRt;
clangNoLibcxx = tools.clangWithLibcAndBasicRt;
mlir = callPackage ./mlir { };
libclc = callPackage ./libclc { };
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "19") {
bolt = callPackage ./bolt {
};
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
flang = callPackage ./flang {
mlir = tools.mlir;
};
}
);
libraries = lib.makeExtensible (
libraries:
let
callPackage = newScope (libraries // buildLlvmTools // args // metadata);
in
(
{
compiler-rt-libc = callPackage ./compiler-rt (
let
# temp rename to avoid infinite recursion
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if args.stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else if args.stdenv.hostPlatform.useLLVM or false then
overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else
args.stdenv;
in
{
inherit stdenv;
}
// lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--disable-symvers" ];
});
}
);
compiler-rt-no-libc = callPackage ./compiler-rt {
doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt
else
overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
};
compiler-rt =
if
stdenv.hostPlatform.libc == null
# Building the with-libc compiler-rt and WASM doesn't yet work,
# because wasilibc doesn't provide some expected things. See
# compiler-rt's file for further details.
|| stdenv.hostPlatform.isWasm
# Failing `#include <term.h>` in
# `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp`
# sanitizers, not sure where to get it.
|| stdenv.hostPlatform.isFreeBSD
then
libraries.compiler-rt-no-libc
else
libraries.compiler-rt-libc;
stdenv = overrideCC stdenv buildLlvmTools.clang;
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
libcxx = callPackage ./libcxx {
stdenv =
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt
else
overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};
libunwind = callPackage ./libunwind {
stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};
openmp = callPackage ./openmp {
};
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
libc-overlay = callPackage ./libc {
isFullBuild = false;
# Use clang due to "gnu::naked" not working on aarch64.
# Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882
stdenv = overrideCC stdenv buildLlvmTools.clang;
};
libc-full = callPackage ./libc {
isFullBuild = true;
# Use clang due to "gnu::naked" not working on aarch64.
# Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
cmake =
if stdenv.targetPlatform.libc == "llvm" then buildPackages.cmakeMinimal else buildPackages.cmake;
python3 =
if stdenv.targetPlatform.libc == "llvm" then
buildPackages.python3Minimal
else
buildPackages.python3;
};
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
}
)
);
noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
in
{
inherit tools libraries;
inherit (metadata) release_version;
}
// (noExtend libraries)
// (noExtend tools)

View File

@@ -0,0 +1,95 @@
{
lib,
llvm_meta,
monorepoSrc,
release_version,
runCommand,
cmake,
libxml2,
libllvm,
ninja,
libffi,
libclang,
stdenv,
clang,
mlir,
version,
python3,
buildLlvmTools,
devExtraCmakeFlags ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
pname = "flang";
inherit version;
src = runCommand "flang-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/clang "$out"
cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out"
chmod -R +w $out/llvm
'';
patches = [
./dummy_target_19+.patch
];
patchFlags = [ "-p2" ];
sourceRoot = "${finalAttrs.src.name}/flang";
buildInputs = [
libffi
libxml2
libllvm
libclang
mlir
];
nativeBuildInputs = [
cmake
clang
ninja
python3
libllvm.dev
mlir.dev
];
preConfigure = ''
ls -l ${libllvm.dev}/lib/cmake/llvm/LLVMConfig.cmake
ls -l ${libclang.dev}/lib/cmake/clang/ClangConfig.cmake
ls -l ${mlir.dev}/lib/cmake/mlir/MLIRConfig.cmake
'';
cmakeFlags = [
(lib.cmakeBool "CMAKE_VERBOSE_MAKEFILE" true)
(lib.cmakeFeature "LLVM_DIR" "${libllvm.dev}/lib/cmake/llvm")
(lib.cmakeFeature "LLVM_TOOLS_BINARY_DIR" "${buildLlvmTools.tblgen}/bin/")
(lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${buildLlvmTools.tblgen}/bin/llvm-lit")
(lib.cmakeFeature "CLANG_DIR" "${libclang.dev}/lib/cmake/clang")
(lib.cmakeFeature "MLIR_DIR" "${mlir.dev}/lib/cmake/mlir")
(lib.cmakeFeature "MLIR_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/mlir-tblgen")
(lib.cmakeFeature "MLIR_TABLEGEN_TARGET" "MLIR-TBLGen")
(lib.cmakeBool "LLVM_BUILD_EXAMPLES" false)
(lib.cmakeBool "LLVM_ENABLE_PLUGINS" false)
(lib.cmakeBool "FLANG_STANDALONE_BUILD" true)
(lib.cmakeBool "LLVM_INCLUDE_EXAMPLES" false)
(lib.cmakeBool "FLANG_INCLUDE_TESTS" false)
]
++ devExtraCmakeFlags;
postUnpack = ''
chmod -R u+w -- $sourceRoot/..
'';
outputs = [ "out" ];
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://flang.llvm.org/";
description = "LLVM-based Fortran frontend";
license = lib.licenses.ncsa;
mainProgram = "flang";
maintainers = with lib.maintainers; [ acture ];
};
})

View File

@@ -0,0 +1,27 @@
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 070c39eb6e9a..168c97524943 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -1,6 +1,22 @@
cmake_minimum_required(VERSION 3.20.0)
set(LLVM_SUBPROJECT_TITLE "Flang")
+# Patch: define dummy mlir-tblgen target for TableGen.cmake
+if(DEFINED MLIR_TABLEGEN_EXE AND NOT TARGET mlir-tblgen)
+ add_executable(mlir-tblgen IMPORTED GLOBAL)
+ set_target_properties(mlir-tblgen PROPERTIES
+ IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}"
+ )
+endif()
+
+if(DEFINED MLIR_TABLEGEN_EXE AND NOT TARGET MLIR-TBLGen)
+ add_executable(MLIR-TBLGen IMPORTED GLOBAL)
+ set_target_properties(MLIR-TBLGen PROPERTIES
+ IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}"
+ )
+endif()
+
+
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
endif()

View File

@@ -0,0 +1,105 @@
{
lib,
stdenv,
llvm_meta,
src ? null,
monorepoSrc ? null,
version,
release_version,
runCommand,
python3,
python3Packages,
patches ? [ ],
cmake,
ninja,
isFullBuild ? true,
linuxHeaders,
}:
let
pname = "libc";
src' = runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/runtimes "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/compiler-rt "$out"
cp -r ${monorepoSrc}/${pname} "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/third-party "$out"
''
);
in
stdenv.mkDerivation (finalAttrs: {
inherit pname version patches;
src = src';
sourceRoot = "${finalAttrs.src.name}/runtimes";
nativeBuildInputs = [
cmake
python3
ninja
]
++ (lib.optional isFullBuild python3Packages.pyyaml);
buildInputs = lib.optional isFullBuild linuxHeaders;
outputs = [ "out" ] ++ (lib.optional isFullBuild "dev");
postUnpack = lib.optionalString isFullBuild ''
chmod +w $sourceRoot/../$pname/utils/hdrgen
patchShebangs $sourceRoot/../$pname/utils/hdrgen/main.py
chmod +x $sourceRoot/../$pname/utils/hdrgen/main.py
'';
prePatch = ''
cd ../${finalAttrs.pname}
chmod -R u+w ../
'';
postPatch = ''
cd ../runtimes
'';
postInstall =
lib.optionalString (!isFullBuild) ''
substituteAll ${./libc-shim.tpl} $out/lib/libc.so
''
# LLVM libc doesn't recognize static vs dynamic yet.
# Treat LLVM libc as a static libc, requires this symlink until upstream fixes it.
+ lib.optionalString (isFullBuild && stdenv.hostPlatform.isLinux) ''
ln $out/lib/crt1.o $out/lib/Scrt1.o
'';
libc = if (!isFullBuild) then stdenv.cc.libc else null;
cmakeFlags = [
(lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc;compiler-rt")
# Tests requires the host to have a libc.
(lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null))
]
++ lib.optionals (isFullBuild && stdenv.cc.libc == null) [
# CMake runs a check to see if the compiler works.
# This includes including headers which requires a libc.
# Skip these checks because a libc cannot be used when one doesn't exist.
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
];
# For the update script:
passthru = {
monorepoSrc = monorepoSrc;
inherit isFullBuild;
};
meta = llvm_meta // {
broken = stdenv.hostPlatform.isDarwin;
homepage = "https://libc.llvm.org/";
description = "Standard C library for LLVM";
};
})

View File

@@ -0,0 +1 @@
GROUP (@libc@ @out@/lib/libllvmlibc.a)

View File

@@ -0,0 +1,111 @@
{
lib,
stdenv,
version,
runCommand,
monorepoSrc,
llvm,
buildPackages,
buildLlvmTools,
ninja,
cmake,
python3,
release_version,
getVersionFile,
}:
let
spirv-llvm-translator = buildPackages.spirv-llvm-translator.override {
inherit (buildLlvmTools) llvm;
};
# The build requires an unwrapped clang but wrapped clang++ thus we need to
# split the unwrapped clang out to prevent the build from finding the
# unwrapped clang++
clang-only = runCommand "clang-only" { } ''
mkdir -p "$out"/bin
ln -s "${lib.getExe' buildLlvmTools.clang.cc "clang"}" "$out"/bin
'';
in
stdenv.mkDerivation (finalAttrs: {
pname = "libclc";
inherit version;
src = runCommand "libclc-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libclc "$out"
'';
sourceRoot = "${finalAttrs.src.name}/libclc";
outputs = [
"out"
"dev"
];
patches = [
(getVersionFile "libclc/gnu-install-dirs.patch")
]
# LLVM 19 changes how host tools are looked up.
# Need to remove NO_DEFAULT_PATH and the PATHS arguments for find_program
# so CMake can actually find the tools in nativeBuildInputs.
# https://github.com/llvm/llvm-project/pull/105969
++ lib.optional (lib.versionAtLeast release_version "19") (
getVersionFile "libclc/use-default-paths.patch"
);
# cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
postPatch =
lib.optionalString (lib.versionOlder release_version "19") ''
substituteInPlace CMakeLists.txt \
--replace-fail 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
''
+ lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) (
if (lib.versionOlder release_version "19") then
''
substituteInPlace CMakeLists.txt \
--replace-fail 'COMMAND prepare_builtins' \
'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
''
else
''
substituteInPlace CMakeLists.txt \
--replace-fail 'set( prepare_builtins_exe prepare_builtins )' \
'set( prepare_builtins_exe ${buildLlvmTools.libclc.dev}/bin/prepare_builtins )'
''
);
nativeBuildInputs = [
cmake
ninja
python3
]
++ lib.optionals (lib.versionAtLeast release_version "19") [
clang-only
buildLlvmTools.llvm
spirv-llvm-translator
];
buildInputs = [ llvm ];
strictDeps = true;
postInstall = ''
install -Dt $dev/bin prepare_builtins
'';
meta = with lib; {
homepage = "http://libclc.llvm.org/";
description = "Implementation of the library requirements of the OpenCL C programming language";
mainProgram = "prepare_builtins";
license = licenses.mit;
platforms = platforms.all;
};
})

View File

@@ -0,0 +1,221 @@
{
lib,
stdenv,
llvm_meta,
release_version,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
lndir,
ninja,
python3,
fixDarwinDylibNames,
version,
freebsd,
cxxabi ? if stdenv.hostPlatform.isFreeBSD then freebsd.libcxxrt else null,
libunwind,
enableShared ? stdenv.hostPlatform.hasSharedLibraries,
devExtraCmakeFlags ? [ ],
substitute,
fetchpatch,
}:
# external cxxabi is not supported on Darwin as the build will not link libcxx
# properly and not re-export the cxxabi symbols into libcxx
# https://github.com/NixOS/nixpkgs/issues/166205
# https://github.com/NixOS/nixpkgs/issues/269548
assert cxxabi == null || !stdenv.hostPlatform.isDarwin;
let
cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}";
runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi";
# Note: useLLVM is likely false for Darwin but true under pkgsLLVM
useLLVM = stdenv.hostPlatform.useLLVM or false;
cxxabiCMakeFlags = [
(lib.cmakeBool "LIBCXXABI_USE_LLVM_UNWINDER" false)
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [
(lib.cmakeFeature "LIBCXXABI_ADDITIONAL_LIBRARIES" "unwind")
(lib.cmakeBool "LIBCXXABI_USE_COMPILER_RT" true)
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "LIBCXXABI_ENABLE_THREADS" false)
(lib.cmakeBool "LIBCXXABI_ENABLE_EXCEPTIONS" false)
]
++ lib.optionals (!enableShared || stdenv.hostPlatform.isWindows) [
# Required on Windows due to https://github.com/llvm/llvm-project/issues/55245
(lib.cmakeBool "LIBCXXABI_ENABLE_SHARED" false)
];
cxxCMakeFlags = [
(lib.cmakeFeature "LIBCXX_CXX_ABI" cxxabiName)
(lib.cmakeBool "LIBCXX_ENABLE_SHARED" enableShared)
# https://github.com/llvm/llvm-project/issues/55245
(lib.cmakeBool "LIBCXX_ENABLE_STATIC_ABI_LIBRARY" stdenv.hostPlatform.isWindows)
]
++ lib.optionals (cxxabi == null) [
# Include libc++abi symbols within libc++.a for static linking libc++;
# dynamic linking includes them through libc++.so being a linker script
# which includes both shared objects.
(lib.cmakeBool "LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY" true)
]
++ lib.optionals (cxxabi != null) [
(lib.cmakeFeature "LIBCXX_CXX_ABI_INCLUDE_PATHS" "${lib.getDev cxxabi}/include")
]
++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [
(lib.cmakeFeature "LIBCXX_HAS_MUSL_LIBC" "1")
]
++
lib.optionals (!useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic)
[
(lib.cmakeFeature "LIBCXX_ADDITIONAL_LIBRARIES" "gcc_s")
]
++ lib.optionals stdenv.hostPlatform.isFreeBSD [
# Name and documentation claim this is for libc++abi, but its man effect is adding `-lunwind`
# to the libc++.so linker script. We want FreeBSD's so-called libgcc instead of libunwind.
(lib.cmakeBool "LIBCXXABI_USE_LLVM_UNWINDER" false)
]
++ lib.optionals useLLVM [
(lib.cmakeBool "LIBCXX_USE_COMPILER_RT" true)
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isFreeBSD) [
(lib.cmakeFeature "LIBCXX_ADDITIONAL_LIBRARIES" "unwind")
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "LIBCXX_ENABLE_THREADS" false)
(lib.cmakeBool "LIBCXX_ENABLE_FILESYSTEM" false)
(lib.cmakeBool "LIBCXX_ENABLE_EXCEPTIONS" false)
]
++ lib.optionals (cxxabi != null && cxxabi.libName == "cxxrt") [
(lib.cmakeBool "LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS" true)
];
cmakeFlags = [
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" (lib.concatStringsSep ";" runtimes))
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "UNIX" true) # Required otherwise libc++ fails to detect the correct linker
]
++ cxxCMakeFlags
++ lib.optionals (cxxabi == null) cxxabiCMakeFlags
++ devExtraCmakeFlags;
in
stdenv.mkDerivation (finalAttrs: {
pname = "libcxx";
inherit version cmakeFlags;
src =
if monorepoSrc != null then
runCommand "libcxx-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libcxx "$out"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
cp -r ${monorepoSrc}/third-party "$out"
''
+ (lib.optionalString (lib.versionAtLeast release_version "20") ''
cp -r ${monorepoSrc}/libc "$out"
'')
+ ''
cp -r ${monorepoSrc}/runtimes "$out"
''
+ (lib.optionalString (cxxabi == null) ''
cp -r ${monorepoSrc}/libcxxabi "$out"
'')
)
else
src;
outputs = [
"out"
"dev"
];
preConfigure = lib.optionalString stdenv.hostPlatform.isMusl ''
patchShebangs utils/cat_files.py
'';
# TODO: Remove on `staging`.
patches = [ ];
nativeBuildInputs = [
cmake
ninja
python3
]
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames
++ lib.optional (cxxabi != null) lndir;
buildInputs = [
cxxabi
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm && !stdenv.hostPlatform.isFreeBSD) [
libunwind
];
# TODO: Possibly move back to `sourceRoot` on `staging`?
postPatch = ''
cd runtimes
'';
# libc++.so is a linker script which expands to multiple libraries,
# libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't
# support linker scripts so the external cxxabi needs to be symlinked in
postInstall =
lib.optionalString (cxxabi != null) ''
lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1
lndir ${lib.getLib cxxabi}/lib $out/lib
libcxxabi=$out/lib/lib${cxxabi.libName}.a
''
# LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for
# external cxxabi libraries so merge libc++abi.a into libc++.a ourselves.
# GNU binutils emits objects in LIFO order in MRI scripts so after the merge
# the objects are in reversed order so a second MRI script is required so the
# objects in the archive are listed in proper order (libc++.a, libc++abi.a)
+ lib.optionalString (cxxabi != null) ''
libcxxabi=''${libcxxabi-$out/lib/libc++abi.a}
if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then
$AR -M <<MRI
create $out/lib/libc++.a
addlib $out/lib/libc++.a
addlib $libcxxabi
save
end
MRI
$AR -M <<MRI
create $out/lib/libc++.a
addlib $out/lib/libc++.a
save
end
MRI
fi
'';
passthru = {
isLLVM = true;
};
meta = llvm_meta // {
homepage = "https://libcxx.llvm.org/";
description = "C++ standard library";
longDescription = ''
libc++ is an implementation of the C++ standard library, targeting C++11,
C++14 and above.
'';
# "All of the code in libc++ is dual licensed under the MIT license and the
# UIUC License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
};
})

View File

@@ -0,0 +1,95 @@
{
lib,
stdenv,
release_version,
src ? null,
llvm_meta,
version,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
python3,
libcxx,
enableShared ? !stdenv.hostPlatform.isStatic,
doFakeLibgcc ? stdenv.hostPlatform.useLLVM && !stdenv.hostPlatform.isStatic,
devExtraCmakeFlags ? [ ],
getVersionFile,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libunwind";
inherit version;
# TODO: Remove on `staging`.
patches = [ ];
src =
if monorepoSrc != null then
runCommand "libunwind-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libunwind "$out"
mkdir -p "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
cp -r ${monorepoSrc}/runtimes "$out"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/runtimes";
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
cmake
ninja
python3
];
cmakeFlags = [
(lib.cmakeBool "LIBUNWIND_ENABLE_SHARED" enableShared)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libunwind")
]
++ devExtraCmakeFlags;
# TODO: Remove on `staging`.
prePatch = "";
postPatch = "";
postInstall =
lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows)
''
# libcxxabi wants to link to libunwind_shared.so (?).
ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
''
+ lib.optionalString (enableShared && stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.dll.a $out/lib/libunwind_shared.dll.a
''
+ lib.optionalString (doFakeLibgcc && !stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so
ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so.1
''
+ lib.optionalString (doFakeLibgcc && stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.dll.a $out/lib/libgcc_s.dll.a
'';
meta = llvm_meta // {
# Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
description = "LLVM's unwinder library";
longDescription = ''
The unwind library provides a family of _Unwind_* functions implementing
the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
I). It is a dependency of the C++ ABI library, and sometimes is a
dependency of other runtimes.
'';
};
})

View File

@@ -0,0 +1,90 @@
{
lib,
stdenv,
llvm_meta,
release_version,
buildLlvmTools,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
version,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "lld";
inherit version;
src =
if monorepoSrc != null then
runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/lld "$out"
mkdir -p "$out/libunwind"
cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
mkdir -p "$out/llvm"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/lld";
patches = [
(getVersionFile "lld/gnu-install-dirs.patch")
]
++ lib.optional (lib.versions.major release_version == "18") (
# https://github.com/llvm/llvm-project/pull/97122
fetchpatch {
name = "more-openbsd-program-headers.patch";
url = "https://github.com/llvm/llvm-project/commit/d7fd8b19e560fbb613159625acd8046d0df75115.patch";
stripLen = 1;
hash = "sha256-7wTy7XDTx0+fhWQpW1KEuz7xJvpl42qMTUfd20KGOfA=";
}
);
nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeFeature "LLD_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/lld")
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
]
++ devExtraCmakeFlags;
# TODO: Remove on `staging`.
postPatch = "";
# Musl's default stack size is too small for lld to be able to link Firefox.
LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
outputs = [
"out"
"lib"
"dev"
];
meta = llvm_meta // {
homepage = "https://lld.llvm.org/";
description = "LLVM linker (unwrapped)";
longDescription = ''
LLD is a linker from the LLVM project that is a drop-in replacement for
system linkers and runs much faster than them. It also provides features
that are useful for toolchain developers.
The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
WebAssembly in descending order of completeness. Internally, LLD consists
of several different linkers.
'';
};
})

View File

@@ -0,0 +1,44 @@
{
lib,
stdenv,
fetchFromGitHub,
makeWrapper,
lldb,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "llef";
version = "2.0.0";
src = fetchFromGitHub {
owner = "foundryzero";
repo = "llef";
rev = "v${finalAttrs.version}";
hash = "sha256-pAFjLaZi4Sjlq3evKT2IG+0/imf4Fp5bM2gknLKpRvs=";
};
dontBuild = true;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/share/llef
cp -r llef.py arch commands common handlers $out/share/llef
makeWrapper ${lib.getExe lldb} $out/bin/llef \
--add-flags "-o 'settings set stop-disassembly-display never'" \
--add-flags "-o \"command script import $out/share/llef/llef.py\""
runHook postInstall
'';
meta = with lib; {
description = "LLEF is a plugin for LLDB to make it more useful for RE and VR";
homepage = "https://github.com/foundryzero/llef";
license = licenses.mit;
platforms = platforms.all;
maintainers = with maintainers; [ nrabulinski ];
mainProgram = "llef";
};
})

View File

@@ -0,0 +1,211 @@
{
lib,
stdenv,
llvm_meta,
release_version,
cmake,
zlib,
ncurses,
swig,
which,
libedit,
libxml2,
libllvm,
libclang,
python3,
version,
darwin,
lit,
makeWrapper,
lua5_3,
ninja,
runCommand,
src ? null,
monorepoSrc ? null,
enableManpages ? false,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
fetchpatch2,
replaceVars,
}:
let
vscodeExt = {
name = "lldb-dap";
version = "0.2.0";
};
in
stdenv.mkDerivation (
finalAttrs:
{
passthru.monorepoSrc = monorepoSrc;
pname = "lldb";
inherit version;
src =
if monorepoSrc != null then
runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/lldb "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs"
''
)
else
src;
# There is no `lib` output because some of the files in `$out/lib` depend on files in `$out/bin`.
# For example, `$out/lib/python3.12/site-packages/lldb/lldb-argdumper` is a symlink to `$out/bin/lldb-argdumper`.
# Also, LLDB expects to find the path to `bin` relative to `lib` on Darwin.
outputs = [
"out"
"dev"
];
sourceRoot = "${finalAttrs.src.name}/lldb";
patches = [ ./gnu-install-dirs.patch ];
nativeBuildInputs = [
cmake
python3
which
swig
lit
makeWrapper
lua5_3
]
++ lib.optionals enableManpages [
python3.pkgs.sphinx
python3.pkgs.myst-parser
]
# TODO: Clean up on `staging`.
++ [
ninja
];
buildInputs = [
ncurses
zlib
libedit
libxml2
libllvm
# Starting with LLVM 16, the resource dir patch is no longer enough to get
# libclang into the rpath of the lldb executables. By putting it into
# buildInputs cc-wrapper will set up rpath correctly for us.
(lib.getLib libclang)
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
darwin.bootstrap_cmds
];
hardeningDisable = [ "format" ];
cmakeFlags = [
(lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_RTTI" false)
(lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake")
(lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit")
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
(lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true)
]
++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
(lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic
]
# TODO: Clean up on `staging`.
++ [
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}")
]
++ lib.optionals enableManpages [
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
# docs reference `automodapi` but it's not added to the extensions list when
# only building the manpages:
# https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54
#
# so, we just ignore the resulting errors
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
++ lib.optionals finalAttrs.finalPackage.doCheck [
(lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc")
(lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++")
]
++ devExtraCmakeFlags;
doCheck = false;
doInstallCheck = false;
# TODO: cleanup with mass-rebuild
installCheckPhase = ''
if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then
echo "ERROR: python files not installed where expected!";
return 1;
fi
if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
echo "ERROR: lua files not installed where expected!";
return 1;
fi
'';
postInstall = ''
wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/
# Editor support
# vscode:
install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json
mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
ln -s $out/bin/*${vscodeExt.name} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
'';
passthru.vscodeExtName = vscodeExt.name;
passthru.vscodeExtPublisher = "llvm";
passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}";
meta = llvm_meta // {
homepage = "https://lldb.llvm.org/";
description = "Next-generation high-performance debugger";
longDescription = ''
LLDB is a next generation, high-performance debugger. It is built as a set
of reusable components which highly leverage existing libraries in the
larger LLVM Project, such as the Clang expression parser and LLVM
disassembler.
'';
mainProgram = "lldb";
};
}
// lib.optionalAttrs enableManpages {
pname = "lldb-manpages";
# TODO: Remove on `staging`.
buildPhase = "";
ninjaFlags = [ "docs-lldb-man" ];
propagatedBuildInputs = [ ];
# manually install lldb man page
installPhase = ''
mkdir -p $out/share/man/man1
install docs/man/lldb.1 -t $out/share/man/man1/
'';
postPatch = null;
postInstall = null;
outputs = [ "out" ];
doCheck = false;
meta = llvm_meta // {
description = "man pages for LLDB ${version}";
};
}
)

View File

@@ -0,0 +1,68 @@
diff --git a/bindings/lua/CMakeLists.txt b/bindings/lua/CMakeLists.txt
index 1a739a980..59f8fc3a0 100644
--- a/bindings/lua/CMakeLists.txt
+++ b/bindings/lua/CMakeLists.txt
@@ -56,7 +56,7 @@ function(finish_swig_lua swig_target lldb_lua_bindings_dir lldb_lua_target_dir)
if(LLDB_BUILD_FRAMEWORK)
set(LLDB_LUA_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
else()
- set(LLDB_LUA_INSTALL_PATH ${LLDB_LUA_RELATIVE_PATH})
+ set(LLDB_LUA_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_LUA_RELATIVE_PATH})
endif()
install(DIRECTORY ${lldb_lua_target_dir}/
DESTINATION ${LLDB_LUA_INSTALL_PATH}
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
index c631faf52ac3..1d92d069960b 100644
--- a/bindings/python/CMakeLists.txt
+++ b/bindings/python/CMakeLists.txt
@@ -160,7 +160,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
if(LLDB_BUILD_FRAMEWORK)
set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources/Python)
else()
- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
+ set(LLDB_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH})
endif()
if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake
index 3291a7c808e1..b27d27ce6a87 100644
--- a/cmake/modules/AddLLDB.cmake
+++ b/cmake/modules/AddLLDB.cmake
@@ -109,7 +109,7 @@ function(add_lldb_library name)
endif()
if(PARAM_SHARED)
- set(install_dest lib${LLVM_LIBDIR_SUFFIX})
+ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
if(PARAM_INSTALL_PREFIX)
set(install_dest ${PARAM_INSTALL_PREFIX})
endif()
diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt
index 7d48491ec89a..c04543585588 100644
--- a/tools/intel-features/CMakeLists.txt
+++ b/tools/intel-features/CMakeLists.txt
@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED
)
install(TARGETS lldbIntelFeatures
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt
index 7d48491ec89a..c04543585588 100644
--- a/source/API/CMakeLists.txt 2024-05-30 18:59:13.449269853 -0700
+++ b/source/API/CMakeLists.txt 2024-05-30 19:00:33.721858164 -0700
@@ -115,14 +115,6 @@
${option_install_prefix}
)
-# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
-# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
-# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
-# that _lldb.so can be loaded from Python.
-if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX AND NOT APPLE)
- set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
-endif()
-
if(Python3_RPATH)
set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}")

View File

@@ -0,0 +1,35 @@
From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
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

View File

@@ -0,0 +1,643 @@
{
lib,
stdenv,
llvm_meta,
pkgsBuildBuild,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
darwin,
ninja,
python3,
python3Packages,
libffi,
ld64,
libbfd,
libpfm,
libxml2,
ncurses,
version,
release_version,
zlib,
which,
sysctl,
buildLlvmTools,
updateAutotoolsGnuConfigScriptsHook,
enableManpages ? false,
enableSharedLibraries ? !stdenv.hostPlatform.isStatic,
enablePFM ?
stdenv.hostPlatform.isLinux # PFM only supports Linux
# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245
# broken for the armv7l builder
&& !stdenv.hostPlatform.isAarch,
enablePolly ? true,
enableTerminfo ? true,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
# for tests
libllvm,
}:
let
inherit (lib) optional optionals optionalString;
# Is there a better way to do this? Darwin wants to disable tests in the first
# LLVM rebuild, but overriding doesnt work when building libc++, libc++abi,
# and libunwind. It also wants to disable LTO in the first rebuild.
isDarwinBootstrap = lib.getName stdenv == "bootstrap-stage-xclang-stdenv-darwin";
in
stdenv.mkDerivation (
finalAttrs:
let
# 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 finalAttrs.finalPackage.doCheck && !isDarwinBootstrap 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: [ ps.psutil ];
in
pkgsBuildBuild.targetPackages.python3.withPackages checkDeps
else
python3;
in
{
pname = "llvm";
inherit version;
# TODO: Remove on `staging`.
shortVersion = lib.concatStringsSep "." (lib.take 1 (lib.splitString "." release_version));
src =
if monorepoSrc != null then
runCommand "llvm-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/third-party "$out"
''
+ lib.optionalString enablePolly ''
chmod u+w "$out/llvm/tools"
cp -r ${monorepoSrc}/polly "$out/llvm/tools"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/libc "$out"
''
)
else
src;
sourceRoot = "${finalAttrs.src.name}/llvm";
outputs = [
"out"
"lib"
"dev"
"python"
];
hardeningDisable = [
"trivialautovarinit"
"shadowstack"
];
patches =
# Support custom installation dirs
# Originally based off https://reviews.llvm.org/D99484
# Latest state: https://github.com/llvm/llvm-project/pull/125376
[ (getVersionFile "llvm/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
(getVersionFile "llvm/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)..
(getVersionFile "llvm/lit-shell-script-runner-set-dyld-library-path.patch")
]
++
lib.optional (lib.versionOlder release_version "19")
# Add missing include headers to build against gcc-15:
# https://github.com/llvm/llvm-project/pull/101761
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/7e44305041d96b064c197216b931ae3917a34ac1.patch";
hash = "sha256-1htuzsaPHbYgravGc1vrR8sqpQ/NSQ8PUZeAU8ucCFk=";
stripLen = 1;
}
)
++ lib.optionals (lib.versions.major release_version == "18") [
# Reorgs one test so the next patch applies
(fetchpatch {
name = "osabi-test-reorg.patch";
url = "https://github.com/llvm/llvm-project/commit/06cecdc60ec9ebfdd4d8cdb2586d201272bdf6bd.patch";
stripLen = 1;
hash = "sha256-s9GZTNgzLS511Pzh6Wb1hEV68lxhmLWXjlybHBDMhvM=";
})
# Sets the OSABI for OpenBSD, needed for an LLD patch for OpenBSD.
# https://github.com/llvm/llvm-project/pull/98553
(fetchpatch {
name = "mc-set-openbsd-osabi.patch";
url = "https://github.com/llvm/llvm-project/commit/b64c1de714c50bec7493530446ebf5e540d5f96a.patch";
stripLen = 1;
hash = "sha256-fqw5gTSEOGs3kAguR4tINFG7Xja1RAje+q67HJt2nGg=";
})
]
++ lib.optionals (lib.versionOlder release_version "19") [
# Fixes test-suite on glibc 2.40 (https://github.com/llvm/llvm-project/pull/100804)
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/1e8df9e85a1ff213e5868bd822877695f27504ad.patch";
hash = "sha256-mvBlG2RxpZPFnPI7jvCMz+Fc8JuM15Ye3th1FVZMizE=";
stripLen = 1;
})
]
++ lib.optionals enablePolly [
# Just like the `gnu-install-dirs` patch, but for `polly`.
(getVersionFile "llvm/gnu-install-dirs-polly.patch")
# Just like the `llvm-lit-cfg` patch, but for `polly`.
(getVersionFile "llvm/polly-lit-cfg-add-libs-to-dylib-path.patch")
]
++
lib.optional (lib.versions.major release_version == "20")
# Test failure on riscv64, fixed in llvm 21
# https://github.com/llvm/llvm-project/issues/150818
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/bd49bbaaafc98433a2cb4e95ce25b7a201baf5a5.patch";
hash = "sha256-3hkbYPUVRAtWpo5qBmc2jLZLivURMx8T0GQomvNZesc=";
stripLen = 1;
}
);
nativeBuildInputs = [
cmake
# while this is not an autotools build, it still includes a config.guess
# this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native
updateAutotoolsGnuConfigScriptsHook
python
ninja
]
++ optionals enableManpages [
# Note: we intentionally use `python3Packages` instead of `python3.pkgs`;
# splicing does *not* work with the latter. (TODO: fix)
python3Packages.sphinx
python3Packages.myst-parser
];
buildInputs = [
libxml2
libffi
]
++ optional enablePFM libpfm; # exegesis
propagatedBuildInputs = [
ncurses
zlib
];
nativeCheckInputs = [
which
]
++ lib.optional stdenv.hostPlatform.isDarwin sysctl;
postPatch =
optionalString stdenv.hostPlatform.isDarwin (
''
substituteInPlace cmake/modules/AddLLVM.cmake \
--replace-fail 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)"
''
+
# 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-fail '/usr/bin/sw_vers' "${(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 and FreeBSD.
#
# 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
#
# TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it
# pass there?
''
substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
--replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
--replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
''
+
# fails when run in sandbox
optionalString (!stdenv.hostPlatform.isx86) ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''
)
+
# dup of above patch with different conditions
optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86)
# fails when run in sandbox
(
''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''
+
# 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-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
''
+
# This test fails with a `dysmutil` crash; have not yet dug into what's
# going on here (TODO(@rrbutani)).
lib.optionalString (lib.versionOlder release_version "19") ''
rm test/tools/dsymutil/ARM/obfuscated.test
''
)
+
# FileSystem permissions tests fail with various special bits
''
substituteInPlace unittests/Support/CMakeLists.txt \
--replace-fail "Path.cpp" ""
rm unittests/Support/Path.cpp
substituteInPlace unittests/IR/CMakeLists.txt \
--replace-fail "PassBuilderCallbacksTest.cpp" ""
rm unittests/IR/PassBuilderCallbacksTest.cpp
rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
''
+
# Fails in the presence of anti-virus software or other intrusion-detection software that
# modifies the atime when run. See #284056.
''
rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
''
+
# valgrind unhappy with musl or glibc, but fails w/musl only
optionalString stdenv.hostPlatform.isMusl ''
patch -p1 -i ${./TLI-musl.patch}
substituteInPlace unittests/Support/CMakeLists.txt \
--replace-fail "add_subdirectory(DynamicLibrary)" ""
rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
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-objcopy/MachO/universal-object.test
''
+
# Seems to require certain floating point hardware (NEON?)
optionalString (stdenv.hostPlatform.system == "armv6l-linux") ''
rm test/ExecutionEngine/frem.ll
''
+
# 1. TODO: Why does this test fail on FreeBSD?
# It seems to reference /usr/local/lib/libfile.a, which is clearly a problem.
# 2. This test fails for the same reason it fails on MacOS, but the fix is
# not trivial to apply.
optionalString stdenv.hostPlatform.isFreeBSD ''
rm test/tools/llvm-libtool-darwin/L-and-l.test
rm test/ExecutionEngine/Interpreter/intrinsics.ll
# Fails in sandbox
substituteInPlace unittests/Support/LockFileManagerTest.cpp --replace-fail "Basic" "DISABLED_Basic"
''
+
# https://github.com/llvm/llvm-project/issues/149616
optionalString stdenv.hostPlatform.isLoongArch64 ''
substituteInPlace unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp \
--replace-fail \
"TEST_F(X86SnippetRepetitorTest, Loop)" \
"TEST_F(X86SnippetRepetitorTest, DISABLED_Loop)"
''
+ ''
patchShebangs test/BugPoint/compile-custom.ll.py
'';
# Workaround for configure flags that need to have spaces
preConfigure = ''
cmakeFlagsArray+=(
-DLLVM_LIT_ARGS="--verbose -j''${NIX_BUILD_CORES}"
)
'';
# 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 uses the build-id as a cache key (see #93946):
LDFLAGS = optionalString (
enableSharedLibraries && !stdenv.hostPlatform.isDarwin
) "-Wl,--build-id=sha1";
cmakeBuildType = "Release";
cmakeFlags =
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 = [
(lib.cmakeFeature "LLVM_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/llvm")
(lib.cmakeBool "LLVM_ENABLE_RTTI" true)
(lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" enableSharedLibraries)
(lib.cmakeFeature "LLVM_TABLEGEN" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
];
in
flagsForLlvmConfig
++ [
(lib.cmakeBool "LLVM_INSTALL_UTILS" true) # Needed by rustc
(lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_FFI" true)
(lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeBool "LLVM_ENABLE_DUMP" true)
(lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo)
(lib.cmakeBool "LLVM_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
]
++ optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper
(lib.cmakeBool "LLVM_ENABLE_PIC" false)
(lib.cmakeBool "CMAKE_SKIP_INSTALL_RPATH" true)
(lib.cmakeBool "LLVM_BUILD_STATIC" true)
# 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
(lib.cmakeBool "LLVM_ENABLE_LIBXML2" false)
]
++ optionals enableManpages [
(lib.cmakeBool "LLVM_BUILD_DOCS" true)
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
++ optionals (libbfd != null) [
# LLVM depends on binutils only through libbfd/include/plugin-api.h, which
# is meant to be a stable interface. Depend on that file directly rather
# than through a build of BFD to break the dependency of clang on the target
# triple. The result of this is that a single clang build can be used for
# multiple targets.
(lib.cmakeFeature "LLVM_BINUTILS_INCDIR" "${libbfd.plugin-api-header}/include")
]
++ optionals stdenv.hostPlatform.isDarwin [
(lib.cmakeBool "LLVM_ENABLE_LIBCXX" true)
(lib.cmakeBool "CAN_TARGET_i386" false)
]
++
optionals
(
(stdenv.hostPlatform != stdenv.buildPlatform)
&& !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)
)
[
(lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
(
let
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
nativeBintools = nativeCC.bintools.bintools;
nativeToolchainFlags = [
(lib.cmakeFeature "CMAKE_C_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}cc")
(lib.cmakeFeature "CMAKE_CXX_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}c++")
(lib.cmakeFeature "CMAKE_AR" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ar")
(lib.cmakeFeature "CMAKE_STRIP" "${nativeBintools}/bin/${nativeBintools.targetPrefix}strip")
(lib.cmakeFeature "CMAKE_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 = [
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" (placeholder "out"))
(lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "${placeholder "out"}/bin")
(lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "${placeholder "dev"}/include")
(lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "${placeholder "lib"}/lib")
(lib.cmakeFeature "CMAKE_INSTALL_LIBEXECDIR" "${placeholder "lib"}/libexec")
];
in
lib.cmakeOptionType "list" "CROSS_TOOLCHAIN_FLAGS_NATIVE" (
lib.concatStringsSep ";" (
lib.concatLists [
flagsForLlvmConfig
nativeToolchainFlags
nativeInstallFlags
]
)
)
)
]
++ devExtraCmakeFlags;
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-${lib.toLower finalAttrs.finalPackage.cmakeBuildType}.cmake" \
--replace-fail "$out/bin/llvm-config" "$dev/bin/llvm-config"
substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
--replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
''
+ optionalString (stdenv.hostPlatform.isDarwin && enableSharedLibraries) ''
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
''
+ optionalString (stdenv.buildPlatform != stdenv.hostPlatform) (
if stdenv.buildPlatform.canExecute stdenv.hostPlatform then
''
ln -s $dev/bin/llvm-config $dev/bin/llvm-config-native
''
else
''
cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native
''
);
doCheck =
!isDarwinBootstrap
&& !stdenv.hostPlatform.isAarch32
&& (
!stdenv.hostPlatform.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl)
&& !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian)
&& (stdenv.hostPlatform == stdenv.buildPlatform);
checkTarget = "check-all";
passthru = {
# For the update script:
inherit monorepoSrc;
tests.withoutOptionalFeatures = libllvm.override {
enablePFM = false;
enablePolly = false;
enableTerminfo = false;
};
};
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://llvm.org/";
description = "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".
'';
};
}
// lib.optionalAttrs enableManpages {
pname = "llvm-manpages";
propagatedBuildInputs = [ ];
ninjaFlags = [ "docs-llvm-man" ];
installTargets = [ "install-docs-llvm-man" ];
doCheck = false;
postPatch = null;
postInstall = null;
outputs = [ "out" ];
meta = llvm_meta // {
description = "man pages for LLVM ${version}";
};
}
)

View File

@@ -0,0 +1,95 @@
{
lib,
stdenv,
llvm_meta,
release_version,
buildLlvmTools,
monorepoSrc,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
version,
devExtraCmakeFlags ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
pname = "mlir";
inherit version;
doCheck =
(
!stdenv.hostPlatform.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl);
# Blank llvm dir just so relative path works
src = runCommand "${finalAttrs.pname}-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out/third-party"
mkdir -p "$out/llvm"
'';
sourceRoot = "${finalAttrs.src.name}/mlir";
patches = [
./gnu-install-dirs.patch
];
nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeBool "LLVM_BUILD_TOOLS" true)
# Install headers as well
(lib.cmakeBool "LLVM_INSTALL_TOOLCHAIN_ONLY" false)
(lib.cmakeFeature "MLIR_TOOLS_INSTALL_DIR" "${placeholder "out"}/bin/")
(lib.cmakeBool "LLVM_ENABLE_IDE" false)
(lib.cmakeFeature "MLIR_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/mlir")
(lib.cmakeFeature "MLIR_INSTALL_CMAKE_DIR" "${placeholder "dev"}/lib/cmake/mlir")
(lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_FFI" true)
(lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeBool "LLVM_ENABLE_DUMP" true)
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
(lib.cmakeFeature "MLIR_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/mlir-tblgen")
(lib.cmakeBool "LLVM_BUILD_LLVM_DYLIB" (!stdenv.hostPlatform.isStatic))
]
++ lib.optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper
(lib.cmakeBool "LLVM_ENABLE_PIC" false)
(lib.cmakeBool "LLVM_BUILD_STATIC" true)
(lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" false)
]
++ devExtraCmakeFlags;
outputs = [
"out"
"dev"
];
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://mlir.llvm.org/";
description = "Multi-Level IR Compiler Framework";
longDescription = ''
The MLIR project is a novel approach to building reusable and extensible
compiler infrastructure. MLIR aims to address software fragmentation,
improve compilation for heterogeneous hardware, significantly reduce
the cost of building domain specific compilers, and aid in connecting
existing compilers together.
'';
};
})

View File

@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c91e9cd93dc8..23b6032a46b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,8 +32,8 @@ if(MLIR_STANDALONE_BUILD)
endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
- "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
+ "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}")
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}")
set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
endif()

View File

@@ -0,0 +1,111 @@
{
lib,
stdenv,
llvm_meta,
release_version,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
ninja,
llvm,
targetLlvm,
lit,
clang-unwrapped,
perl,
pkg-config,
python3,
version,
devExtraCmakeFlags ? [ ],
ompdSupport ? true,
ompdGdbSupport ? ompdSupport,
getVersionFile,
fetchpatch,
}:
assert lib.assertMsg (ompdGdbSupport -> ompdSupport) "OMPD GDB support requires OMPD support!";
stdenv.mkDerivation (finalAttrs: {
pname = "openmp";
inherit version;
src =
if monorepoSrc != null then
runCommand "openmp-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/openmp "$out"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/openmp";
outputs = [
"out"
"dev"
];
# TODO: Remove on `staging`.
patchFlags = null;
patches =
lib.optional (lib.versionOlder release_version "19") (getVersionFile "openmp/fix-find-tool.patch")
++ [
(getVersionFile "openmp/run-lit-directly.patch")
];
nativeBuildInputs = [
cmake
python3.pythonOnBuildForHost
perl
ninja
pkg-config
lit
];
buildInputs = [
(if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
]
++ lib.optionals (ompdSupport && ompdGdbSupport) [
python3
];
cmakeFlags = [
(lib.cmakeBool "LIBOMP_ENABLE_SHARED" (
!stdenv.hostPlatform.isStatic && stdenv.hostPlatform.hasSharedLibraries
))
(lib.cmakeBool "LIBOMP_OMPD_SUPPORT" ompdSupport)
(lib.cmakeBool "LIBOMP_OMPD_GDB_SUPPORT" ompdGdbSupport)
(lib.cmakeFeature "CLANG_TOOL" "${clang-unwrapped}/bin/clang")
(lib.cmakeFeature "OPT_TOOL" "${llvm}/bin/opt")
(lib.cmakeFeature "LINK_TOOL" "${llvm}/bin/llvm-link")
]
++ devExtraCmakeFlags;
doCheck = false;
checkTarget = "check-openmp";
preCheck = ''
patchShebangs ../tools/archer/tests/deflake.bash
'';
meta = llvm_meta // {
homepage = "https://openmp.llvm.org/";
description = "Support for the OpenMP language";
longDescription = ''
The OpenMP subproject of LLVM contains the components required to build an
executable OpenMP program that are outside the compiler itself.
Contains the code for the runtime library against which code compiled by
"clang -fopenmp" must be linked before it can run and the library that
supports offload to target devices.
'';
# "All of the code is dual licensed under the MIT license and the UIUC
# License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
};
})

View File

@@ -0,0 +1,119 @@
{
"clang/gnu-install-dirs.patch" = [
{
after = "19";
path = ../19;
}
];
"clang/purity.patch" = [
{
path = ../18;
}
];
"lld/gnu-install-dirs.patch" = [
{
path = ../18;
}
];
"llvm/gnu-install-dirs.patch" = [
{
after = "22";
path = ../22;
}
{
after = "21";
before = "22";
path = ../21;
}
{
after = "20";
before = "21";
path = ../20;
}
{
before = "20";
path = ../18;
}
];
"llvm/gnu-install-dirs-polly.patch" = [
{
after = "20";
path = ../20;
}
{
before = "20";
path = ../18;
}
];
"llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch" = [
{
path = ../18;
}
];
"llvm/lit-shell-script-runner-set-dyld-library-path.patch" = [
{
path = ../18;
}
];
"llvm/polly-lit-cfg-add-libs-to-dylib-path.patch" = [
{
path = ../18;
}
];
"compiler-rt/X86-support-extension.patch" = [
{
path = ../18;
}
];
"compiler-rt/armv6-scudo-libatomic.patch" = [
{
after = "19";
path = ../19;
}
{
before = "19";
path = ../18;
}
];
"compiler-rt/normalize-var.patch" = [
{
path = ../18;
}
];
"openmp/fix-find-tool.patch" = [
{
before = "19";
path = ../18;
}
];
"openmp/run-lit-directly.patch" = [
{
path = ../18;
}
];
"libclc/use-default-paths.patch" = [
{
after = "20";
path = ../20;
}
{
after = "19";
before = "20";
path = ../19;
}
{
after = "20";
path = ../20;
}
];
"libclc/gnu-install-dirs.patch" = [
{
before = "21";
path = ../18;
}
{
after = "21";
path = ../21;
}
];
}

View File

@@ -0,0 +1,116 @@
{
cmake,
devExtraCmakeFlags ? [ ],
lib,
llvm_meta,
monorepoSrc ? null,
ninja,
patches ? [ ],
python3,
updateAutotoolsGnuConfigScriptsHook,
release_version,
runCommand,
src ? null,
stdenv,
version,
clangPatches,
}:
let
# This is a synthetic package which is not an official part of the llvm-project.
# See https://github.com/NixOS/nixpkgs/pull/362384 for discussion.
#
# LLVM has tools that run at build time. In native builds, these are
# built as a part of the usual build, but in cross builds they need to
# come from buildPackages.
#
# In many scenarios this is a small problem because LLVM from
# buildPackages is already available as a build; but if cross building a
# version of LLVM which is not available (e.g. a new git commit of LLVM)
# this results in two builds of LLVM and clang, one native and one for the
# cross.
#
# Full builds of LLVM are expensive; and unnecessary in this scenario. We
# don't need a native LLVM, only a native copy of the tools which run at
# build time. This is only tablegen and related tooling, which are cheap
# to build.
pname = "llvm-tblgen";
src' =
if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/third-party "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/clang "$out"
cp -r ${monorepoSrc}/clang-tools-extra "$out"
cp -r ${monorepoSrc}/mlir "$out"
''
else
src;
# List of tablegen targets.
targets = [
"clang-tblgen"
"llvm-tblgen"
"clang-tidy-confusable-chars-gen"
"mlir-tblgen"
]
++ lib.optionals (lib.versionOlder release_version "20") [
"clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935.
];
self = stdenv.mkDerivation (finalAttrs: {
inherit pname version patches;
src = src';
sourceRoot = "${finalAttrs.src.name}/llvm";
__structuredAttrs = true;
postPatch = ''
(
cd ../clang
chmod u+rwX -R .
for p in ${toString clangPatches}
do
patch -p1 < $p
done
)
'';
nativeBuildInputs = [
cmake
ninja
python3
# while this is not an autotools build, it still includes a config.guess
# this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native
updateAutotoolsGnuConfigScriptsHook
];
cmakeFlags = [
# Projects with tablegen-like tools.
"-DLLVM_ENABLE_PROJECTS=${
lib.concatStringsSep ";" [
"llvm"
"clang"
"clang-tools-extra"
"mlir"
]
}"
]
++ devExtraCmakeFlags;
ninjaFlags = targets;
inherit targets;
installPhase = ''
mkdir -p $out/bin
cp "''${targets[@]/#/bin/}" $out/bin
'';
});
in
self

View File

@@ -0,0 +1,83 @@
{
lib,
callPackage,
stdenvAdapters,
buildPackages,
targetPackages,
stdenv,
pkgs,
recurseIntoAttrs,
# This is the default binutils, but with *this* version of LLD rather
# than the default LLVM version's, if LLD is the choice. We use these for
# the `useLLVM` bootstrapping below.
bootBintoolsNoLibc ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintoolsNoLibc,
bootBintools ? if stdenv.targetPlatform.linker == "lld" then null else pkgs.bintools,
llvmVersions ? { },
patchesFn ? lib.id,
# Allows passthrough to packages via newScope in ./common/default.nix.
# This makes it possible to do
# `(llvmPackages.override { <someLlvmDependency> = bar; }).clang` and get
# an llvmPackages whose packages are overridden in an internally consistent way.
...
}@packageSetArgs:
let
versions = {
"18.1.8".officialRelease.sha256 = "sha256-iiZKMRo/WxJaBXct9GdAcAT3cz9d9pnAcO1mmR6oPNE=";
"19.1.7".officialRelease.sha256 = "sha256-cZAB5vZjeTsXt9QHbP5xluWNQnAHByHtHnAhVDV0E6I=";
"20.1.8".officialRelease.sha256 = "sha256-ysyB/EYxi2qE9fD5x/F2zI4vjn8UDoo1Z9ukiIrjFGw=";
"21.1.1".officialRelease.sha256 = "sha256-IB9Z3bIMwfgw2W2Vxo89CmtCM9DfOyV2Ei64nqgHrgc=";
"22.0.0-git".gitRelease = {
rev = "550b2ef041ba16ee8b5f55b5f2307f501b2c15a0";
rev-version = "22.0.0-unstable-2025-10-05";
sha256 = "sha256-K3wjvVFCjFpEDLdLWGWvAoAFGWWAKoD8a6xgXDslC7M=";
};
}
// llvmVersions;
mkPackage =
{
name ? null,
officialRelease ? null,
gitRelease ? null,
monorepoSrc ? null,
version ? null,
}@args:
let
inherit
(import ./common/common-let.nix {
inherit lib;
inherit gitRelease officialRelease version;
})
releaseInfo
;
inherit (releaseInfo) release_version;
attrName =
args.name or (if (gitRelease != null) then "git" else lib.versions.major release_version);
in
lib.nameValuePair attrName (
recurseIntoAttrs (
callPackage ./common (
{
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages."llvmPackages_${attrName}".tools;
targetLlvmLibraries =
# Allow overriding targetLlvmLibraries; this enables custom runtime builds.
packageSetArgs.targetLlvmLibraries or targetPackages."llvmPackages_${attrName}".libraries
or llvmPackages."${attrName}".libraries;
targetLlvm = targetPackages."llvmPackages_${attrName}".llvm or llvmPackages."${attrName}".llvm;
inherit
officialRelease
gitRelease
monorepoSrc
version
patchesFn
;
}
// packageSetArgs # Allow overrides.
)
)
);
llvmPackages = lib.mapAttrs' (version: args: mkPackage (args // { inherit version; })) versions;
in
llvmPackages // { inherit mkPackage versions; }

View File

@@ -0,0 +1,68 @@
{
runCommand,
clang,
gcc64,
gcc32,
glibc_multi,
}:
let
combine =
basegcc:
runCommand "combine-gcc-libc" { } ''
mkdir -p $out
cp -r ${basegcc.cc}/lib $out/lib
chmod u+rw -R $out/lib
cp -r ${basegcc.libc}/lib/* $(ls -d $out/lib/gcc/*/*)
'';
gcc_multi_sysroot =
runCommand "gcc-multi-sysroot"
{
passthru = {
inherit (gcc64) version;
lib = gcc_multi_sysroot;
};
}
''
mkdir -p $out/lib{,64}/gcc
ln -s ${combine gcc64}/lib/gcc/* $out/lib64/gcc/
ln -s ${combine gcc32}/lib/gcc/* $out/lib/gcc/
# XXX: This shouldn't be needed, clang just doesn't look for "i686-unknown"
ln -s $out/lib/gcc/i686-unknown-linux-gnu $out/lib/gcc/i686-pc-linux-gnu
# includes
mkdir -p $out/include
ln -s ${glibc_multi.dev}/include/* $out/include
ln -s ${gcc64.cc}/include/c++ $out/include/c++
# dynamic linkers
mkdir -p $out/lib/32
ln -s ${glibc_multi.out}/lib/ld-linux* $out/lib
ln -s ${glibc_multi.out}/lib/32/ld-linux* $out/lib/32/
'';
clangMulti = clang.override {
# Only used for providing expected structure re:dynamic linkers, AFAIK Most
# of the magic is done by setting the --gcc-toolchain option via
# `gccForLibs`.
libc = gcc_multi_sysroot;
bintools = clang.bintools.override {
libc = gcc_multi_sysroot;
};
gccForLibs = gcc_multi_sysroot // {
inherit (glibc_multi) libgcc;
langCC =
assert
(gcc64.cc.langCC != gcc32.cc.langCC)
-> throw "(gcc64.cc.langCC=${gcc64.cc.langCC}) != (gcc32.cc.langCC=${gcc32.cc.langCC})";
gcc64.cc.langCC;
};
};
in
clangMulti

View File

@@ -0,0 +1,89 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 nix
import csv
import fileinput
import json
import os
import re
import subprocess
import sys
from codecs import iterdecode
from datetime import datetime
from urllib.request import urlopen, Request
DEFAULT_NIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'default.nix')
def get_latest_chromium_build():
RELEASES_URL = 'https://versionhistory.googleapis.com/v1/chrome/platforms/linux/channels/dev/versions/all/releases?filter=endtime=none&order_by=version%20desc'
print(f'GET {RELEASES_URL}')
with urlopen(RELEASES_URL) as resp:
return json.load(resp)['releases'][0]
def get_file_revision(revision, file_path):
"""Fetches the requested Git revision of the given Chromium file."""
url = f'https://raw.githubusercontent.com/chromium/chromium/{revision}/{file_path}'
with urlopen(url) as http_response:
return http_response.read().decode()
def get_commit(ref):
url = f'https://api.github.com/repos/llvm/llvm-project/commits/{ref}'
headers = {'Accept': 'application/vnd.github.v3+json'}
request = Request(url, headers=headers)
with urlopen(request) as http_response:
return json.loads(http_response.read().decode())
def get_current_revision():
"""Get the current revision of llvmPackages_git."""
with open(DEFAULT_NIX) as f:
for line in f:
rev = re.search(r'^ rev = "(.*)";', line)
if rev:
return rev.group(1)
sys.exit(1)
def nix_prefetch_url(url, algo='sha256'):
"""Prefetches the content of the given URL."""
print(f'nix-prefetch-url {url}')
out = subprocess.check_output(['nix-prefetch-url', '--type', algo, '--unpack', url])
return out.decode('utf-8').rstrip()
chromium_build = get_latest_chromium_build()
chromium_version = chromium_build['version']
print(f'chromiumDev version: {chromium_version}')
print('Getting LLVM commit...')
clang_update_script = get_file_revision(chromium_version, 'tools/clang/scripts/update.py')
clang_revision = re.search(r"^CLANG_REVISION = '(.+)'$", clang_update_script, re.MULTILINE).group(1)
clang_commit_short = re.search(r"llvmorg-[0-9]+-init-[0-9]+-g([0-9a-f]{8})", clang_revision).group(1)
release_version = re.search(r"^RELEASE_VERSION = '(.+)'$", clang_update_script, re.MULTILINE).group(1)
commit = get_commit(clang_commit_short)
if get_current_revision() == commit["sha"]:
print('No new update available.')
sys.exit(0)
date = datetime.fromisoformat(commit['commit']['committer']['date'].rstrip('Z')).date().isoformat()
version = f'unstable-{date}'
print('Prefetching source tarball...')
hash = nix_prefetch_url(f'https://github.com/llvm/llvm-project/archive/{commit["sha"]}.tar.gz')
print('Updating default.nix...')
with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f:
for line in f:
if match := re.search(r'^ rev-version = "unstable-(.+)";', line):
old_date = match.group(1)
result = line
result = re.sub(r'^ version = ".+";', f' version = "{release_version}";', result)
result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result)
result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result)
result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result)
print(result, end='')
# Commit the result:
commit_message = f"llvmPackages_git: {old_date} -> {date}"
subprocess.run(['git', 'add', DEFAULT_NIX], check=True)
subprocess.run(['git', 'commit', '--file=-'], input=commit_message.encode(), check=True)

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eu
# Example usage: ./pkgs/development/compilers/llvm/update.sh 12.0.0-rc4
readonly VERSION="$1"
readonly VERSION_MAJOR="${VERSION%%.*}"
readonly VERSION_MAIN="${VERSION%%-*}"
declare VERSION_PATCH="${VERSION/$VERSION_MAIN/}"
readonly VERSION_PATCH="${VERSION_PATCH/-/}"
readonly DIR="pkgs/development/compilers/llvm/$VERSION_MAJOR"
readonly FILE="$DIR/default.nix"
sed -Ei \
-e "s/release_version = \".+\";/release_version = \"$VERSION_MAIN\";/" \
-e "s/candidate = \".*\";/candidate = \"$VERSION_PATCH\";/" \
"$FILE"
readonly ATTRSET="llvmPackages_$VERSION_MAJOR"
echo "Updating the hash of llvm.monorepoSrc:"
declare ATTR="$ATTRSET.llvm.monorepoSrc"
declare OLD_HASH="$(nix --extra-experimental-features nix-command eval -f . $ATTR.outputHash)"
declare NEW_HASH="\"$(nix-prefetch-url -A $ATTR)\""
find "$DIR" -type f -exec sed -i "s/$OLD_HASH/$NEW_HASH/" {} +
echo OK