diff options
| author | Stefan Boberg <[email protected]> | 2026-03-04 14:00:34 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-04 14:00:34 +0100 |
| commit | 794f093057c58c4909a0653edb54fdf869560596 (patch) | |
| tree | a730072e40f7eb60c7761ffb44c939aa1ad981bb /xmake.lua | |
| parent | IterateChunks callback is multithreaded - make sure AttachmentsSize can handl... (diff) | |
| download | zen-794f093057c58c4909a0653edb54fdf869560596.tar.xz zen-794f093057c58c4909a0653edb54fdf869560596.zip | |
native xmake toolchain definition for UE-clang (#805)
This change is meant to provide a smoother experience when working on Linux. After this change, the toolchain setup process is now simply
```bash
$ scripts/ue_build_linux/get_ue_toolchain.sh
```
and then at config time the toolchain is automatically detected if you downloaded it to the default location or have the `UE_TOOLCHAIN_DIR` environment variable set
```bash
xmake config --mode=debug
```
Compared to the old script-based approach this configures the toolchain more precisely, avoiding leakage into unrelated build processes such as when a package manager decides to build something like Ninja locally etc.
Diffstat (limited to 'xmake.lua')
| -rw-r--r-- | xmake.lua | 42 |
1 files changed, 32 insertions, 10 deletions
@@ -101,16 +101,17 @@ if is_plat("windows") then add_requires("7z") end --- If we're using the UE cross-compile toolchain, we need to ensure we link statically --- against the toolchain libc++ and libc++abi, as the system ones can differ in ABI --- leading to nasty crashes - -if is_plat("linux") and os.getenv("UE_TOOLCHAIN_DIR") then - add_ldflags("-static-libstdc++") - add_ldflags("$(projectdir)/thirdparty/ue-libcxx/lib64/libc++.a") - add_ldflags("$(projectdir)/thirdparty/ue-libcxx/lib64/libc++abi.a") - set_toolset("objcopy", "$(env UE_TOOLCHAIN_DIR)/bin/llvm-objcopy") +-- When using the UE clang toolchain, statically link the toolchain's libc++ and +-- libc++abi to avoid ABI mismatches with system libraries at runtime. +-- These are project-level flags (not in the toolchain definition) so they don't +-- propagate into cmake package builds. +if is_plat("linux") and get_config("toolchain") == "ue-clang" then + add_ldflags("-static-libstdc++", {force = true}) + add_ldflags("$(projectdir)/thirdparty/ue-libcxx/lib64/libc++.a", {force = true}) + add_ldflags("$(projectdir)/thirdparty/ue-libcxx/lib64/libc++abi.a", {force = true}) + add_ldflags("-lpthread", {force = true}) end + if has_config("zensentry") and not use_asan then if is_plat("linux") then add_requires("sentry-native 0.12.1", {configs = {backend = "crashpad"}}) @@ -276,6 +277,25 @@ set_languages("cxx20") -- always generate debug information set_symbols("debug") +includes("toolchains") + +-- Auto-select the UE clang toolchain on Linux when the SDK is available +if is_plat("linux") and not get_config("toolchain") then + local ue_sdk = os.getenv("UE_TOOLCHAIN_DIR") + if not ue_sdk or ue_sdk == "" then + local home = os.getenv("HOME") + if home then + local default_path = path.join(home, ".ue-toolchain") + if os.isdir(default_path) then + ue_sdk = default_path + end + end + end + if ue_sdk and ue_sdk ~= "" and os.isdir(ue_sdk) then + set_toolchains("ue-clang") + end +end + includes("thirdparty") includes("src/transports") includes("src/zenbase") @@ -459,7 +479,9 @@ task("test") -- Only reconfigure if current config doesn't already match if config.get("mode") ~= "debug" or config.get("plat") ~= plat or config.get("arch") ~= arch then - os.exec("xmake config -c -m debug -p %s -a %s", plat, arch) + local toolchain_flag = config.get("toolchain") and ("--toolchain=" .. config.get("toolchain")) or "" + local sdk_flag = config.get("sdk") and ("--sdk=" .. config.get("sdk")) or "" + os.exec("xmake config -c -m debug -p %s -a %s %s %s", plat, arch, toolchain_flag, sdk_flag) end -- Build targets we're going to run |