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: Implement get_mingw_tool to fix mingw prefix ambiguity (reverted) #85319

Merged
merged 1 commit into from
May 7, 2024

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Nov 24, 2023

Expands upon the #79871 fix. Instead of separately checking for if a tool exists with/without a prefix, and using that to manually check for a tool, this PR consolidates that logic into a single function: get_mingw_tool. Now it returns a path outright to whatever tool it finds, or an empty path if no tool was found whatsoever. Because an empty string will function as False in conditionals, this was sufficent to remove the need for get_mingw_bin_prefix in isolation & replace try_cmd outright

The primary change compared to try_cmd is that only the leading argument needs to be supplied; as such, the argument was renamed from "test" to "tool". --version is now implicitly what gets tested, but can be changed if needed via a new argument. This new function was applied to all the areas where get_mingw_bin_prefix and/or try_cmd were directly called, consolidating the relevant code in the process

@Repiteo Repiteo requested a review from a team as a code owner November 24, 2023 17:44
@Calinou Calinou added bug topic:buildsystem cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Nov 24, 2023
@Calinou Calinou added this to the 4.3 milestone Nov 24, 2023
@saierXP
Copy link

saierXP commented Nov 25, 2023

By the way I’d like you to add the example of mingw_prefix when mingw is not found. Last month when I was using mingw to compile a third party module, I ran into the problem of not being able to find the compiler when mingw_prefix was set to mingw\bin.

Note: MINGW_PREFIX should point to your MinGW installation, if you installed MSYS2 with default settings this directory will be “C:/msys64/mingw64”11.

print(
"""
No valid compilers found, use MINGW_PREFIX environment variable to set MinGW path.
"""
)

image

Footnotes

  1. https://devblogs.microsoft.com/cppblog/using-mingw-and-cygwin-with-visual-cpp-and-open-folder/

@YuriSizov YuriSizov requested a review from a team December 4, 2023 13:47
@akien-mga akien-mga requested a review from bruvzg January 9, 2024 11:59
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. Haven't tested yet.

platform/windows/detect.py Outdated Show resolved Hide resolved
platform/windows/detect.py Show resolved Hide resolved
@Repiteo Repiteo force-pushed the scons-mingw-prefix-fixes branch from cca85db to 59d32eb Compare May 6, 2024 22:17
 • Replaces "try_cmd" entirely and removes need for "get_mingw_bin_prefix" in isolation
@Repiteo Repiteo force-pushed the scons-mingw-prefix-fixes branch from 59d32eb to ecebe0b Compare May 6, 2024 22:33
@akien-mga akien-mga merged commit 570220b into godotengine:master May 7, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@Repiteo Repiteo deleted the scons-mingw-prefix-fixes branch May 7, 2024 14:36
@TokageItLab
Copy link
Member

TokageItLab commented May 8, 2024

After this fix, I can't build Godot on windows... Am I missing something in MinGW? It was buildable until one of the commits prior to this PR, so does this PR cause it to check and block anything?

 *  Executing task: scons platform=windows target=editor -j 16 

scons: Reading SConscript files ...
Using MinGW, arch x86_64
Building for platform "windows", architecture "x86_64", target "editor".
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[Initial build] build_res_file(["platform\windows\godot_res_wrap.windows.editor.x86_64.o"], ["platform\windows\godot_res_wrap.rc"])
[Initial build] Compiling platform\windows\os_windows.cpp ...
[Initial build] Compiling platform\windows\display_server_windows.cpp ...
[Initial build] Compiling platform\windows\native_menu_windows.cpp ...
[Initial build] build_res_file(["platform\windows\godot_res.windows.editor.x86_64.o"], ["platform\windows\godot_res.rc"])
[Initial build] Compiling main\main.cpp ...
[Initial build] Compiling main\performance.cpp ...
[Initial build] Compiling modules\ktx\register_types.cpp ...
[Initial build] Compiling modules\ktx\texture_loader_ktx.cpp ...
[Initial build] Compiling modules\theora\register_types.cpp ...
[Initial build] Compiling modules\theora\video_stream_theora.cpp ...
[Initial build] Compiling modules\vorbis\audio_stream_ogg_vorbis.cpp ...
[Initial build] Compiling modules\vorbis\register_types.cpp ...
[Initial build] Compiling modules\vorbis\resource_importer_ogg_vorbis.cpp ...
[Initial build] Compiling modules\astcenc\image_compress_astcenc.cpp ...
[Initial build] scons: *** [platform\windows\godot_res_wrap.windows.editor.x86_64.o] Error -1
Compiling modules\astcenc\register_types.cpp ...
scons: *** [platform\windows\godot_res.windows.editor.x86_64.o] Error -1
scons: building terminated because of errors.

@bruvzg
Copy link
Member

bruvzg commented May 8, 2024

This probably should be reverted since it's based on wrong assumption about prefixes (it's checking for empty arch, but always adding path part of the prefix), a lot of tool chains have some prefixed (compilers, etc.) and some non-prefixed tools (generic stuff like windres), and have them in the different locations.

@bruvzg
Copy link
Member

bruvzg commented May 8, 2024

This probably should be reverted

Or I guess an extra case can be added to the get_mingw_tool to keep the cleanup part, something like (not tested):

diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index ccf889f1a3..22b2d90fdb 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -40,6 +40,19 @@ def get_mingw_tool(tool, prefix="", arch="", test="--version"):
                 return path
         except Exception:
             pass
+    try:
+        path = f"{tool}"
+        out = subprocess.Popen(
+            f"{path} {test}",
+            shell=True,
+            stderr=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+        )
+        out.communicate()
+        if out.returncode == 0:
+            return path
+    except Exception:
+        pass
 
     return ""
 

@akien-mga
Copy link
Member

This probably should be reverted

Or I guess an extra case can be added to the get_mingw_tool to keep the cleanup part.

My understanding from the PR is that it tries first arch-prefixed binaries, and then the tool without prefix as final fallback. So I would expect it to still be able to call a windres in PATH.

@bruvzg
Copy link
Member

bruvzg commented May 8, 2024

Currently, if prefix is set to something like /mingw32, it will try /mingw32/bin/i686-w64-mingw32-windres (usual for cross building) and /mingw32/bin/windres (unlikely to be valid), but it might be just /bin/windres (usual for MSYS), so it should have an extra step for windres without any prefix to look in PATH.

@bruvzg
Copy link
Member

bruvzg commented May 8, 2024

But checking for all tools, like gcc and clang in PATH will cause it to wrongly report Windows as a supported platform when it's not. So it should be applied only to extra tools like windres, strip, and objdump as it was before.

@akien-mga akien-mga changed the title SCons: Implement get_mingw_tool to fix mingw prefix ambiguity SCons: Implement get_mingw_tool to fix mingw prefix ambiguity (reverted) May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release platform:windows topic:buildsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants