Files
serenity/Toolchain/CMake/ClangToolchain.txt.in
T
Lucas Chollet cc0939a666 Everywhere: Stop using pc in our target triples
While `pc` is not particularly wrong on x86_64, it's nonsensical on
other supported platforms, namely aarch64 and riscv64.

For consistency, we now don't use this vendor anymore, regardless of the
platform.

Within the LLVM project, we now build as `$arch-serenity`. This is
enough in most cases, the only place where we have to specify a vendor
is the target .cfg file where we use `$arch-unknown-serenity`.

When building GCC and friends, again we simply identify as
`$arch-serenity` and this is enough.

As a result, the tools in Toolchain/Local/$arch/bin are now named after
this pattern: `$arch-serenity-$tool`.

These changes affect the toolchain build scripts, serenity's build
scripts and the Ports.

The last place where we should see `x86_64-pc-serenity` is the output of
`config.sub`, which assume the vendor is `pc` on vendor-less `x86*`
triples. So `x86_64-serenity` is expanded to `x86_64-pc-serenity`,
luckily enough and AFAICT, the whole GNU ecosystem considers `pc`,
`unknown` and vendor-less target triples the same. So `configure`
shouldn't have an issue finding the right tools anyway.

The gn files were edited with sed and are not tested.

This commit also includes a check in `Meta/serenity.sh` to give a nicer
error message when trying to build the system with an old toolchain.

----

To test this patch, on a clean tree I:
 - Ran `./Meta/serenity.sh x86_64 GNU`
 - Ran `./Toolchain/BuildJakt.sh`
 - Tested these ports: python3(configure based), libjxl(cmake based) and
   rizin(meson based)
 - Also booted on aarch64 and risv64

I also repeated the steps above with a Clang toolchain.

On a working tree I tested all the affected ports, the results are:
 - tinycc build fine but can't compile programs, I observed the same on
   master.
 - gdb and epsilon don't build but report the same errors as on master.
 - I manually edited the libgpg-error, and it builds fine.
 - The gcc port works fine.
2026-03-13 20:59:49 +01:00

56 lines
2.5 KiB
Plaintext

set(CMAKE_SYSTEM_NAME SerenityOS)
set(CMAKE_SYSTEM_PROCESSOR "@SERENITY_ARCH@")
set(triple @SERENITY_ARCH@-serenity)
set(TOOLCHAIN_ROOT @SERENITY_SOURCE_DIR@/Toolchain/Local/clang/)
set(TOOLCHAIN_PATH ${TOOLCHAIN_ROOT}/bin)
# where to read from/write to
set(CMAKE_SYSROOT @SERENITY_BUILD_DIR@/Root)
set(CMAKE_STAGING_PREFIX @SERENITY_BUILD_DIR@/Root/usr/local)
set(CMAKE_INSTALL_PREFIX /usr/local)
set(CMAKE_INSTALL_DATAROOTDIR share)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/clang)
set(CMAKE_ASM_COMPILER_TARGET ${triple})
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/ld.lld)
set(CMAKE_AR ${TOOLCHAIN_PATH}/llvm-ar)
set(CMAKE_NM ${TOOLCHAIN_PATH}/llvm-nm)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH}/llvm-objcopy)
set(CMAKE_RANLIB ${TOOLCHAIN_PATH}/llvm-ranlib)
set(CMAKE_STRIP ${TOOLCHAIN_PATH}/llvm-strip)
set(SERENITY_CXXFILT ${TOOLCHAIN_PATH}/llvm-cxxfilt)
# FIXME: We could eliminate this setting by building LibC and support asm files (crti.o, crtn.o)
# in a separate build stage before the main build to ensure that LibC is available
# for the try_compile check for the main build.
# Note that `set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)` is not a suitable replacement,
# since applications might try and use `try_compile()` to detect which library a symbol is in,
# which doesn't work when using static linking.
# Instead, just tell CMake directly that the compiler works fine, so that it doesn't have to run
# a compile check before the build.
# This also means that the "Detecting C{,XX} compiler ABI info" step fails, so we need to set
# some variables manually. There may be more variables that aren't set, but those don't seem to be
# necessary at the time of writing this. We only support 64-bit little endian systems, so set the
# values accordingly.
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_C_SIZEOF_DATA_PTR 8)
set(CMAKE_C_BYTE_ORDER LITTLE_ENDIAN)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
set(CMAKE_CXX_BYTE_ORDER LITTLE_ENDIAN)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
# Sets a common default architecture for all toolchains. Be sure to update this in GNUToolchain as well!
if("${SERENITY_ARCH}" STREQUAL "riscv64")
add_compile_options(-march=rv64gc)
endif()