godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.89k stars 20.15k forks source link

[linux] use_llvm cross compile failure #96011

Open jwinarske opened 3 weeks ago

jwinarske commented 3 weeks ago

Tested versions

4.3-stable

System information

Yocto scarthgap running on Fedora 40

Issue description

Using externally set CC and CXX will incorrectly be overwritten when using use_llvm.

Example external values for a cross compile:

export CC="riscv64-poky-linux-clang -target riscv64-poky-linux     -mlittle-endian --dyld-prefix=/usr -Qunused-arguments -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/raid10/yocto/master/visionfive2/tmp/work/riscv64-poky-linux/godot/4.3/recipe-sysroot"
export CXX="riscv64-poky-linux-clang++ -target riscv64-poky-linux     -mlittle-endian --dyld-prefix=/usr -Qunused-arguments -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/raid10/yocto/master/visionfive2/tmp/work/riscv64-poky-linux/godot/4.3/recipe-sysroot"

Build setup/compile run.do_compile.txt

This patch resolves the issue:

diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index d1de760f34..04f4662ed2 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -110,9 +110,6 @@ def configure(env: "SConsEnvironment"):
         env["use_llvm"] = True

     if env["use_llvm"]:
-        if "clang++" not in os.path.basename(env["CXX"]):
-            env["CC"] = "clang"
-            env["CXX"] = "clang++"
         env.extra_suffix = ".llvm" + env.extra_suffix

     if env["linker"] != "default":
-- 
2.46.0

It seems that os.path.basename(env["CXX"]) is not correctly reading the external environment.

Steps to reproduce

Set CC and CXX to something other than clang and clang++. e.g.

export CC="riscv64-poky-linux-clang -target riscv64-poky-linux     -mlittle-endian --dyld-prefix=/usr -Qunused-arguments -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/raid10/yocto/master/visionfive2/tmp/work/riscv64-poky-linux/godot/4.3/recipe-sysroot"
export CXX="riscv64-poky-linux-clang++ -target riscv64-poky-linux     -mlittle-endian --dyld-prefix=/usr -Qunused-arguments -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/raid10/yocto/master/visionfive2/tmp/work/riscv64-poky-linux/godot/4.3/recipe-sysroot"

Minimal reproduction project (MRP)

This is solely a build issue

akien-mga commented 2 weeks ago

env["CXX"] reads from the SCons Environment object, not from the OS environment. Godot's buildsystem doesn't read OS environment variables, by design to ensure builds are reproducible and configurations intentional. You should pass those values as argument to the scons command:

scons CC="..." CXX="..."
jwinarske commented 2 weeks ago

@akien-mga This is what I'm passing

scons p=linuxbsd target=editor arch=${TARGET_ARCH_NAME} \
    use_llvm=yes \
    use_static_cpp=yes \
    optimize=speed \
    lto=thin \
    progress=yes \
    no_editor_splash=yes \
    num_jobs=${BB_NUMBER_THREADS} \
    ${PACKAGECONFIG_CONFARGS} \
    CC="${CC}" cflags="${CFLAGS}" \
    CXX="${CXX}" cxxflags="${CXXFLAGS}" \
    AS="${AS}" AR="${AR}" RANLIB="${RANLIB}" \
    LINK="${CXX} ${LDFLAGS} -fuse-ld=lld" \
    import_env_vars=PATH,PKG_CONFIG_DIR,PKG_CONFIG_DISABLE_UNINSTALLED,PKG_CONFIG_LIBDIR,PKG_CONFIG_PATH,PKG_CONFIG_SYSROOT_DIR,PKG_CONFIG_SYSTEM_INCLU>
jwinarske commented 2 weeks ago

@Miftachul-Huda please don't high jack this issue. It is unrelated to yours.