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 handling of platform-specific tools, notably mingw #101726

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented Jan 17, 2025

Redo of #99762 on top of #101715, aiming to fix various issues we have with the fact that we need to know the selected platform to define the right SCons "tools" to enable when creating the environment, but we need the environment to register command line options that help set said platform.

Using two environments with env.Clone() seems to help solve the problems in #101715, and fixing the detection of when mingw should be set as tool via #99762 seems to make it work out of the box for Linux+mingw at least.

SConstruct Outdated Show resolved Hide resolved
SConstruct Outdated
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 Author

Choose a reason for hiding this comment

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

I moved this further down because there's more options overrides below, notably platform flags, and we likely want to respect them before calling detect.get_tools(env) so that this can make full use of the configuration so far.

…egister custom tools

This helps move this logic out of SConstruct, keeping platforms more self
contained, and helping thirdparty platforms define their own custom tools.

This logic was also unreliable (the `use_mingw` one would only work if
passed manually on the command line, not in e.g. `get_flags`).
@akien-mga akien-mga force-pushed the scons-platform-custom-tools-v2 branch from 832383d to ed96da7 Compare January 17, 2025 23:23
@akien-mga akien-mga marked this pull request as draft January 17, 2025 23:23
Comment on lines +422 to +424
tmppath = "./platform/" + env["platform"]
sys.path.insert(0, tmppath)
import detect
Copy link
Member Author

Choose a reason for hiding this comment

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

This had to move up, otherwise detect here was actually the one of the last platform we checked when parsing all of them... i.e. windows, so Linux and macOS were getting mingw registered and ending with .exe binary extensions :p

SConstruct Outdated Show resolved Hide resolved
SConstruct Outdated Show resolved Hide resolved
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