Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,31 @@ def configure(env: "SConsEnvironment"):
# gdb works fine without it though, so maybe our crash handler could too.
env.Append(LINKFLAGS=["-rdynamic"])

# Cross-compilation
# TODO: Support cross-compilation on architectures other than x86.
host_is_64_bit = sys.maxsize > 2**32
if host_is_64_bit and env["arch"] == "x86_32":
env.Append(CCFLAGS=["-m32"])
env.Append(LINKFLAGS=["-m32"])
elif not host_is_64_bit and env["arch"] == "x86_64":
env.Append(CCFLAGS=["-m64"])
env.Append(LINKFLAGS=["-m64"])

# CPU architecture flags.
if env["arch"] == "rv64":
# TODO: Support cross-compilation on architectures other than x86.
if env["arch"] == "x86_64":
# CFLAGS and CXXFLAGS have a lower priority than CCFLAGS, so don't use CCFLAGS, instead
# use duplicate CFLAGS and CXXFLAGS, allowing the user to override the arch flags if needed.
env.Prepend(CFLAGS=["-m64", "-march=x86-64"])
env.Prepend(CXXFLAGS=["-m64", "-march=x86-64"])
Comment on lines +91 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CCFLAGS for those if it's the same for C and C++.

Copy link
Member

@akien-mga akien-mga Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see #64366 (comment). This should be documented with a comment.

But this is also exactly why I haven't fully been able to approve this PR, as I'm worried about exactly these implications of forcing some defaults which may not be what users want to use. We already have similar issues with use_llvm=yes forcing CC=clang CXX=clang++ which can also be problematic, so it's not new to be clear.

But there are implications to explicitly spelling out default values like this. That being said I also see value in being explicit about what we expect to be used by default.

I started some WIP in the same area but didn't have time to continue. The scope is bigger than just Linux, and it includes an option to skip setting these defaults:

akien-mga@1e4aef2 (branch https://github.com/akien-mga/godot/tree/scons-explicit-march-mtune)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your branch, why is it needed to have a env["default_arch_flags"] bool to disable the default arch flags? If users desire specific arch flags, they should be able to override it as @MonterraByte mentioned.

Copy link
Contributor

@MonterraByte MonterraByte Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. In this case, it's fine to always set -march, because if the user sets -march a second time, it will override the first value. This is true for both GCC and Clang. (Not for MSVC, but that's not relevant here.)

You can verify this with gcc -march=x86-64 -march=x86-64-v3 -dM -E - < /dev/null | grep AVX.

env.Prepend(LINKFLAGS=["-m64", "-march=x86-64"])
elif env["arch"] == "x86_32":
env.Prepend(CFLAGS=["-m32", "-march=i686"])
env.Prepend(CXXFLAGS=["-m32", "-march=i686"])
env.Prepend(LINKFLAGS=["-m32", "-march=i686"])
elif env["arch"] == "arm64":
env.Prepend(CFLAGS=["-march=armv8-a"])
env.Prepend(CXXFLAGS=["-march=armv8-a"])
env.Prepend(LINKFLAGS=["-march=armv8-a"])
elif env["arch"] == "arm32":
env.Prepend(CFLAGS=["-march=armv7-a"])
env.Prepend(CXXFLAGS=["-march=armv7-a"])
env.Prepend(LINKFLAGS=["-march=armv7-a"])
elif env["arch"] == "rv64":
# G = General-purpose extensions, C = Compression extension (very common).
env.Append(CCFLAGS=["-march=rv64gc"])
env.Prepend(CFLAGS=["-march=rv64gc"])
env.Prepend(CXXFLAGS=["-march=rv64gc"])
env.Prepend(LINKFLAGS=["-march=rv64gc"])

## Compiler configuration

Expand Down