Toolchain: Use Platform/SerenityOS.cmake in LLVM toolchain build

By setting CMAKE_MODULE_PATH in the LLVM initial cache scripts, we can
make the "SerenityOS" CMAKE_SYSTEM_NAME usable in the builds of
compiler-rt, libunwind, libcxxabi and libcxx.

This simplifies some toolchain patches and brings the cross-compiler
patches closer to the Port's patches, and closer to something
upstreamable.
This commit is contained in:
Andrew Kaster 2022-01-02 21:51:27 -07:00 committed by Brian Gianforcaro
parent af31253a16
commit c5898806d2
4 changed files with 34 additions and 14 deletions

View file

@ -285,6 +285,7 @@ pushd "$DIR/Build/clang"
-DSERENITY_x86_64-pc-serenity_SYSROOT="$BUILD/x86_64clang/Root" \
-DSERENITY_aarch64-pc-serenity_SYSROOT="$BUILD/aarch64clang/Root" \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
-DSERENITY_MODULE_PATH="$DIR/CMake" \
-C "$DIR/CMake/LLVMConfig.cmake" \
${dev:+"-DLLVM_CCACHE_BUILD=ON"} \
${ci:+"-DLLVM_CCACHE_BUILD=ON"} \
@ -318,6 +319,7 @@ pushd "$DIR/Build/clang"
-DSERENITY_TOOLCHAIN_ARCH="$arch" \
-DSERENITY_TOOLCHAIN_ROOT="$PREFIX" \
-DSERENITY_BUILD_DIR="$BUILD/${arch}clang/" \
-DSERENITY_MODULE_PATH="$DIR/CMake" \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
-C "$DIR/CMake/LLVMRuntimesConfig.cmake"

View file

@ -1,5 +1,9 @@
# This file specifies the options used for building the Clang compiler, LLD linker and the compiler builtins library
# Note: We force the cmake module path for all dependent projects to include our custom directory
# That has the Platform/SerenityOS.cmake definition
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${SERENITY_MODULE_PATH}" CACHE STRING "Modules for CMake")
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD "X86;AArch64" CACHE STRING "")
@ -35,10 +39,14 @@ foreach(target i686-pc-serenity;x86_64-pc-serenity;aarch64-pc-serenity)
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME SerenityOS CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CACHE STRING "")
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(BUILTINS_${target}_CMAKE_SYSROOT ${SERENITY_${target}_SYSROOT} CACHE PATH "")
set(BUILTINS_${target}_COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN OFF CACHE BOOL "")
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME SerenityOS CACHE STRING "")
set(BUILTINS_${target}_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CACHE STRING "")
endforeach()
set(LLVM_TOOLCHAIN_TOOLS

View file

@ -1,9 +1,14 @@
# This file specifies the options used for building the various LLVM runtime libraries
# Note: We force the cmake module path for all dependent projects to include our custom directory
# That has the Platform/SerenityOS.cmake definition
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${SERENITY_MODULE_PATH}" CACHE STRING "Modules for CMake")
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "libcxx;libcxxabi;libunwind" CACHE STRING "")
set(CMAKE_SYSTEM_NAME SerenityOS CACHE STRING "")
set(target_triple ${SERENITY_TOOLCHAIN_ARCH}-pc-serenity)
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")

View file

@ -592,6 +592,19 @@ index ba9f96384..4aecfeee2 100644
return;
case llvm::Triple::Win32:
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 39b9120f0..1a49ac3e5 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -684,7 +684,7 @@ endif()
# TODO: Add builtins support.
-if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER)
+if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER)
set(COMPILER_RT_HAS_CRT TRUE)
else()
set(COMPILER_RT_HAS_CRT FALSE)
diff --git a/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake b/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
index ad2820b32..deaa2c380 100644
--- a/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
@ -736,26 +749,18 @@ index d5ab8fb3b..5039c1987 100644
// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
return _ctype_ + 1;
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 0c3419390..75f8b552b 100644
index 0c3419390..7673b9183 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -228,11 +228,11 @@ endif()
@@ -228,7 +228,7 @@ endif()
# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
# build might work on ELF but fail on MachO/COFF.
-if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390" OR
- WIN32 OR CYGWIN) AND
- NOT LLVM_USE_SANITIZER)
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
-endif()
+#if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390" OR
+# WIN32 OR CYGWIN) AND
+# NOT LLVM_USE_SANITIZER)
+# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
+#endif()
# Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded
# by dlclose(). We need that since the CLI API relies on cross-references
+if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390|SerenityOS" OR
WIN32 OR CYGWIN) AND
NOT LLVM_USE_SANITIZER)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index 76f351405..b81556c55 100644
--- a/llvm/include/llvm/ADT/Triple.h