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

SCons: Fix platform tool integration #101715

Closed

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Jan 17, 2025

This PR removes a later mingw tool call by having the call handled in SConstruct instead. It turns out that mingw as a tool was already declared in that file, but wasn't always being processed thanks to these platform arguments being parsed before validation. While this PR fixes that by moving the tools a bit further down, it's still hacky by necessity; we will eventually need a much broader refactor of our SCons structure.

@Repiteo Repiteo added this to the 4.4 milestone Jan 17, 2025
@Repiteo Repiteo requested a review from a team as a code owner January 17, 2025 20:17
SConstruct Show resolved Hide resolved
Comment on lines -110 to -120
custom_tools = ["default"]

platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))

if platform_arg == "android":
custom_tools = ["clang", "clang++", "as", "ar", "link"]
elif platform_arg == "web":
# Use generic POSIX build toolchain for Emscripten.
custom_tools = ["cc", "c++", "ar", "link", "textfile", "zip"]
elif os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
custom_tools = ["mingw"]
Copy link
Member

@akien-mga akien-mga Jan 17, 2025

Choose a reason for hiding this comment

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

Changing the order of this stuff is pretty risky and regression prone. We've been bitten by this multiple times, we'd need to be extremely cautious here. That's sadly too risky for a bugfix PR IMO, we should go back to the previous working stage if that's the only option.

Copy link
Member

Choose a reason for hiding this comment

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

Could you investigate instead whether #99762 can be used as a base to solve the issue in a better way? I'm more confident in that change, it's just a draft because I wanted to do more testing.

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 suppose I could turn this on its head by making the platform evaluation happen earlier instead of the tool assignment. That's certainly more isolated, so it wouldn't have that same risk of regression. Gonna give that a shot

That PR could be a base, but at the same time I think a lot of the platform/module specific setup should be reimplemented as SCons-native tools. Gonna have to whip up a proposal at some point that consolidates a lot of these ideas for further discussion

Copy link
Member

Choose a reason for hiding this comment

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

In second thought I think there's merit in doing this change indeed, the current logic that relies on querying ARGUMENTS to know the selected platform before having env["platform"] is very brittle.

I'd like to combine this PR and #99762 somehow and see if we can make it safe.

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 agree there's merit to it, but now I'm not sold on it being worth digging into in isolation. There's plenty of areas here that use ARGUMENTS incorrectly, and trying to address all of them would go out of scope

@akien-mga akien-mga dismissed their stale review January 17, 2025 22:27

Not breaking as I thought it was.

Comment on lines +344 to +355
# FIXME: Tool assignment happening at this stage is a direct consequence of getting the platform logic AFTER the SCons
# environment was already been constructed. Fixing this would require a broader refactor where all options are setup
# ahead of time with native validator/converter functions.
custom_tools = []
if env["platform"] == "android":
custom_tools += ["clang", "clang++", "as", "ar", "link"]
elif env["platform"] == "web":
custom_tools += ["cc", "c++", "ar", "link", "textfile", "zip"]
elif env["platform"] == "windows" and methods.get_cmdline_bool("use_mingw", False):
custom_tools += ["mingw"]
for tool in custom_tools:
env.Tool(tool)
Copy link
Member

Choose a reason for hiding this comment

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

What's the actual consequence on the SCons environment of late-registering tools like this?

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'm not 100% certain, which is why I'm now a bit more hesitant. But my testing has made it seem like it's functionally identical, at least this early on in the environment's lifetime.

Copy link
Member

Choose a reason for hiding this comment

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

As I feared:

$ scons p=windows
/home/akien/.local/bin/scons p=windows 2>&1 | tee -a build.log
scons: Reading SConscript files ...
Auto-detected 16 CPU cores available for build parallelism. Using 15 cores by default. You can override it with the `-j` or `num_jobs` arguments.
Using MinGW, arch x86_64
Building for platform "windows", architecture "x86_64", target "editor".
AttributeError: 'SConsEnvironment' object has no attribute 'RES':
  File "/home/akien/Godot/godot/SConstruct", line 1072:
    SConscript("platform/" + env["platform"] + "/SCsub")  # Build selected platform.
  File "/home/akien/.local/lib/python3.13/site-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/home/akien/.local/lib/python3.13/site-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/akien/.local/lib/python3.13/site-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/akien/Godot/godot/platform/windows/SCsub", line 54:
    res_obj = env.RES(res_target, res_file)

That's with mingw-w64 on Linux, building for Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gaaaaaaah

Change of plans, I'm shrinking this PR to add the missing checks like LINKFLAGS explicitly. Everything else can be handled in another PR

Copy link
Member

@akien-mga akien-mga Jan 17, 2025

Choose a reason for hiding this comment

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

Gaaaaaaah

Change of plans, I'm shrinking this PR to add the missing checks like LINKFLAGS explicitly. Everything else can be handled in another PR

I'd prefer to revert the PR that created the regression instead. We shouldn't add hacks on top of hacks.

There's potentially a lot of configuration we're losing in the process by re-setting the mingw tool, and we shouldn't try to play whack-a-mole with it.

This comment was marked as outdated.

Copy link
Contributor Author

@Repiteo Repiteo Jan 17, 2025

Choose a reason for hiding this comment

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

Wait wait, don't revert it. That PR already fixed other, existing hacks elsewhere, like needing to append .exe to filesystems in #98968. I'll cook up a proper solution here after all

EDIT: Ahh, I see the PR that's gonna "solve" this; that might do the trick

SConstruct Show resolved Hide resolved
@Repiteo Repiteo marked this pull request as draft January 17, 2025 23:02
@Repiteo Repiteo modified the milestones: 4.4, 4.x Jan 17, 2025
@Repiteo
Copy link
Contributor Author

Repiteo commented Jan 18, 2025

Superseded by #101726

@Repiteo Repiteo closed this Jan 18, 2025
@Repiteo Repiteo deleted the scons/platform-tool-fixes branch January 18, 2025 15:17
@Repiteo Repiteo removed this from the 4.x milestone Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCons detect configure removes LINKFLAGS added beforehand (eg. command line)
2 participants