Skip to content

Implement use_static_cpp flag for Linux #1747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions cmake/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ function(linux_options)
Not implemented as compiler selection is managed by CMake. Look to
doc/cmake.rst for examples.
]]
option(GODOTCPP_USE_STATIC_CPP "Link libgcc and libstdc++ statically for better portability" ON)
endfunction()

#[===========================[ Target Generation ]===========================]
function(linux_generate)
set(STATIC_CPP "$<BOOL:${GODOTCPP_USE_STATIC_CPP}>")

target_compile_definitions(godot-cpp PUBLIC LINUX_ENABLED UNIX_ENABLED)

# gersemi: off
target_link_options(
godot-cpp
PUBLIC
$<${STATIC_CPP}:
-static-libgcc
-static-libstdc++
>
)
# gersemi: on

common_compiler_flags()
endfunction()
5 changes: 5 additions & 0 deletions tools/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

def options(opts):
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux", False))
opts.Add(BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True))
Comment on lines 7 to +8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps also adding - only effective when targeting Linux here makes sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is worth noting. It's weird that we get the option twice, but I don't think having an extra note in the option makes that any clearer.

Also, I think this is basically a GCC option, and doesn't really have anything to do with Linux. If we were to try to consolidate the options (which I'm not necessarily saying we should), it would probably be to add this option when the compiler is GCC

Honestly, I think I'm personally fine merging this without solving the duplicate option situation. I think we could tackle that in a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering only adding the option once and consolidating the messaging. But there is a difference in behavior. When targeting Windows, it also adds -static in addition to the other two. The help text there is "Link MinGW/MSVC C++ runtime libraries statically".

I agree that it's okay to have them twice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

given that, then have no problems with the changes, just trying to figure out how to approve them now.



def exists(env):
Expand Down Expand Up @@ -37,6 +38,10 @@ def generate(env):
env.Append(CCFLAGS=["-march=rv64gc"])
env.Append(LINKFLAGS=["-march=rv64gc"])

# Link statically for portability
if env["use_static_cpp"]:
env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])

env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"])

# Refer to https://github.com/godotengine/godot/blob/master/platform/linuxbsd/detect.py
Expand Down