Skip to content

Linux: Remove unused code from standard C++ libraries with use_static_cpp=yes (reduces binary size by 1.3mb!) - #2066

Open
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:binary-size-use-static-cpp
Open

dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:binary-size-use-static-cpp

Conversation

@dsnopek

@dsnopek dsnopek commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

When building the test project on Linux with scons use_static_cpp=yes (which is the default!) this will generate a binary that is ~1.3mb smaller!

Platform / Compiler Size Before Size After Change
Linux / GCC 13 2,866 KB 1,548 KB -1,318 KB (-46.0%)
Linux / Clang 18 3,063 KB 1,247 KB -1,816 KB (-59.3%)

I've done a bunch of experimenting and investigation on Windows, and I don't think there's a similar gain to be had there. We don't support the use_static_cpp=yes option on any other platforms (only Linux and Windows)

I've made the same changes in CMake as well, and they seem to work in my testing

@dsnopek dsnopek added this to the 10.x milestone Oct 7, 2026
@dsnopek
dsnopek requested a review from a team as a code owner October 7, 2026 17:24
@dsnopek dsnopek added enhancement This is an enhancement on the current functionality cmake topic:buildsystem Related to the buildsystem or CI setup labels Oct 7, 2026
@dsnopek dsnopek changed the title Linux: Remove unused code from standard C++ libraries with use_static_cpp=yes (reduces binary size by 1.3kb!) Linux: Remove unused code from standard C++ libraries with use_static_cpp=yes (reduces binary size by 1.3mb!) Oct 7, 2026
@dsnopek
dsnopek force-pushed the binary-size-use-static-cpp branch from 8de4a67 to c4a382e Compare October 7, 2026 17:25
@Ivorforce
Ivorforce requested a review from a team October 7, 2026 17:26

@Ivorforce Ivorforce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought there was some problem with use_static_cpp (compat depending on who builds it), but it seems like upstream Godot also does use it for linux.

I can't really judge the build flags; I'm not familiar with them. If the buildsystem team doesn't review I can give a yolo approval in a few days

@dsnopek

dsnopek commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

I thought there was some problem with use_static_cpp (compat depending on who builds it), but it seems like upstream Godot also does use it for linux.

use_static_cpp can actually help solve compatibility problems: it allows your extension to work on other Linux distros with incompatible versions of the standard C++ libraries (by statically linking them, rather than using the dynamic library from the system)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake enhancement This is an enhancement on the current functionality topic:buildsystem Related to the buildsystem or CI setup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants