Skip to content
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

Add lto scons option #1601

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add lto scons option #1601

wants to merge 5 commits into from

Conversation

Ivorforce
Copy link
Contributor

@Ivorforce Ivorforce commented Sep 21, 2024

The behavior mimics almost the exact behavior (minus "progress" options) of Godot scons:

This is an active change (edit: not anymore, defaults to 'none' by default now): Once merged, all projects depending on godot-cpp (and updating the submodule) will gain LTO for release builds. I tested a similar setup in my own project, not the exact same though (because I don't have all combinations of windows, msvc, mingw and use_llvm available). However, since that it mimics what Godot does already, it should be good, given I did not make mistakes.

One important difference is that in my implementation (edit: not anymore, consistently 'none' by default now), "auto" is consistent across platforms ("full" in production, "none" in dev). I saw small, but consistent gains in all platforms, and don't see why LTO should be avoided in some platforms by default.

@Ivorforce Ivorforce requested a review from a team as a code owner September 21, 2024 10:57
@Ivorforce
Copy link
Contributor Author

Not sure why the windows builds are failing. I don't have this problem with any of my git runners. If this is related to the PR, we can default to no LTO on windows. Let me know what you think.

Copy link
Contributor

@Faless Faless left a comment

Choose a reason for hiding this comment

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

Looking good overall 🚀 (haven't tested a build yet).

Some changes are needed to match the default values with upstream godot.

tools/common_compiler_flags.py Show resolved Hide resolved
tools/common_compiler_flags.py Outdated Show resolved Hide resolved
tools/common_compiler_flags.py Outdated Show resolved Hide resolved
tools/common_compiler_flags.py Outdated Show resolved Hide resolved
Comment on lines +78 to +87
env.Append(CCFLAGS=["-flto=thin"])
env.Append(LINKFLAGS=["-flto=thin"])
elif env["lto"] == "full":
if env["use_llvm"]:
env.Append(CCFLAGS=["-flto"])
env.Append(LINKFLAGS=["-flto"])
else:
env.AppendUnique(CCFLAGS=["/GL"])
env.AppendUnique(ARFLAGS=["/LTCG"])
env.AppendUnique(LINKFLAGS=["/LTCG"])
Copy link
Contributor

Choose a reason for hiding this comment

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

This mixes up parameter flags a bit, more importantly, use_llvm and is_msvc is not a real scenario.

if env.get("is_msvc", False), use_llvm is ignored, you might want to check use_clang_cl instead ("Use the clang driver instead of MSVC"), and use windows format for flags (/opt).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I thought as well, but I'm mirroring what Godot does: https://github.com/godotengine/godot/blob/master/platform/windows/detect.py#L620
(note it's the MSVC branch this is in)

If you think this is not a real scenario, maybe this is worth a PR into the main repository as well? Let me know if I should still change it according to your suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Mmmhhh.. the - vs / flags upstream is suspicious, but I think more importantly there's a discrepancy between godot-cpp and godot where we use use_clang_cl instead of use_llvm in godot-cpp for the llvm msvc driver.

So currently, that scenario can never happen in godot-cpp, but I think we should unify the use_clang_cl flag with use_llvm and, like upstream godot does(?), use the llvm MSVC backend unless use_mingw is also specified.

But we should probably double check this with someone more into the windows part of the build system.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've opened #1602 to discuss that change specifically.

tools/godotcpp.py Outdated Show resolved Hide resolved
tools/godotcpp.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants