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

Unify bits, arch, and android_arch into env["arch"] #55778

Merged
merged 1 commit into from
Aug 25, 2022

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Dec 10, 2021

This PR addresses part of godotengine/godot-proposals#1416

In the master branch before this PR, we have several arguments for specifying the architecture: bits, arch, and android_arch. This is a bit of a mess, so this PR replaces all three of these with a single unified arch. Note that env["bits"] still exists internally for now (or it could be kept forever).

The list of valid architectures is ["auto", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]. The names were chosen to be explicit such that each architecture always includes the bitness in the name (except for "auto").

If "auto", then it will automatically determine the architecture. It will use arm64 for Android and iOS, wasm32 for JavaScript, and otherwise it will use the host architecture, so arm64 on modern ARM devices, x86_64 on a typical modern desktop, and x86_32 on an old 32-bit desktop.

For macOS, iOS, JavaScript, and Android, it will throw an error if trying to build for an invalid architecture. The same should be done for Windows and Linux but I'm not sure how to get cross-compiling working in all cases where it should exist or how to show an error when the necessary libs etc are missing. There's also several places in both Windows and Linux that are hard-coded for x86. I left some TODOs in the Windows and Linux code for future PRs.

I've tested this PR compiling on an arm64 macOS host for x86_64 and arm64 macOS and for arm64 iOS, on an arm64 Ubuntu VM for arm64 Linux, on a rv64 Ubuntu VM for rv64 Linux, on an x86_64 Ubuntu host for x86_64 Linux, on an x86_32 Ubuntu VM for x86_32 Linux (fails linking, but happens on master too), on an x86_64 Windows host for x86_32 and x86_64 Windows using MSVC and x86_64 using MinGW, on both an x86_64 Windows and x86_64 Ubuntu host for x86_32, x86_64, arm32, and arm64 Android (x86 Android fails linking on Ubuntu but this happens on master too, and I only tested if the arm64 Android build runs), and on an x86_64 Windows host for wasm32 JavaScript. Still, it needs further testing. Most of the platforms I've tested on have revealed bugs (some of which exist on master too).

This PR also simplifies a lot of architecture checks (such as the ones in the denoise module).

@q66 Can you test if this works as expected on PowerPC?

platform/iphone/detect.py Outdated Show resolved Hide resolved
@neikeq
Copy link
Contributor

neikeq commented Dec 10, 2021

I think the drop of 32bit support on iOS should go into its own commit.
It's much better to have Drop iOS 32-bit support commit than for these changes to be hidden in an unrelated commit.

@akien-mga
Copy link
Member

I think the drop of 32bit support on iOS should go into its own commit. It's much better to have Drop iOS 32-bit support commit than for these changes to be hidden in an unrelated commit.

Yes, and similarly I would put the actual build fixes in a dedicated PR too. This should only focus on buildsystem changes.
(In the same vein, I didn't comment as I didn't want to delay further, but for #55572 I would also have preferred separate PRs for actually fixing the double build and adding it to the CI.)

@aaronfranke
Copy link
Member Author

aaronfranke commented Dec 10, 2021

Opened #55792 and #55793 which take pieces out of this PR.

@aaronfranke aaronfranke force-pushed the use-arch-btw branch 2 times, most recently from 5428d42 to 9735747 Compare December 11, 2021 03:50
SConstruct Outdated Show resolved Hide resolved
Comment on lines 631 to 643
if (file.find("/data.mono.osx.64.release_debug/") != -1) {
if (file.find("/data.mono.osx.x86_64.release_debug/") != -1) {
if (!p_debug) {
ret = unzGoToNextFile(src_pkg_zip);
continue; // skip
}
file = file.replace("/data.mono.osx.64.release_debug/", "/GodotSharp/");
file = file.replace("/data.mono.osx.x86_64.release_debug/", "/GodotSharp/");
}
if (file.find("/data.mono.osx.64.release/") != -1) {
if (file.find("/data.mono.osx.x86_64.release/") != -1) {
if (p_debug) {
ret = unzGoToNextFile(src_pkg_zip);
continue; // skip
}
file = file.replace("/data.mono.osx.64.release/", "/GodotSharp/");
file = file.replace("/data.mono.osx.x86_64.release/", "/GodotSharp/");
Copy link
Member

Choose a reason for hiding this comment

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

This should stay 64 or skip architecture at all, usually this path point to the Universal (x86_64 + arm64) binaries.

Copy link
Member Author

@aaronfranke aaronfranke Dec 16, 2021

Choose a reason for hiding this comment

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

Since this is supposed to point to universal, I reverted this part for this PR, but I think it would make sense to remove the architecture in the future for universal things, or use the word "universal".

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think it can be left out for this PR, but that's something that needs more work later.

We can indeed remove the bits/arch part which is currently irrelevant. But we have to think about whether we want to actually make it possibility to support different architectures with this like we do on other platforms, and thus have:

data.mono.osx.x86_64.release
data.mono.osx.arm64.release
data.mono.osx.universal.release

Official builds would use the latter, but users who want to ship separate x86_64 and arm64 builds for some reason would still have the option to do it with pre-defined names. Currently you'd have to use data.mono.osx.64.release regardless of what the actual native binaries inside are compiled for.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aaronfranke aaronfranke marked this pull request as ready for review August 13, 2022 19:31
Comment on lines +89 to 92
if env["arch"] == "x86_32":
cmdbase = env["mingw_prefix_32"]
else:
cmdbase = env["mingw_prefix_64"]
Copy link
Member

Choose a reason for hiding this comment

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

I guess it should be simply a single mingw_prefix that can be set alongside arch.

platform/windows/detect.py Outdated Show resolved Hide resolved
"Failed to manually detect MSVC compiler architecture version... Defaulting to 32bit executable settings"
" (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this"
"Failed to manually detect MSVC compiler architecture version... Defaulting to x86 32-bit executable settings"
" (forcing arch=x86_32). Compilation attempt will continue, but SCons can not detect for what architecture this"
" build is compiled for. You should check your settings/compilation setup, or avoid setting VCINSTALLDIR."
)
Copy link
Member

Choose a reason for hiding this comment

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

This should just fail, there's no point to continue if compiler is not present.

Copy link
Member

Choose a reason for hiding this comment

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

The print is no longer accurate then, since it says explicitly that it's falling back to x86 32-bit settings.

platform/windows/detect.py Outdated Show resolved Hide resolved
Comment on lines +388 to +390
# TODO: This doesn't seem to be working, or maybe I just have
# MinGW set up incorrectly. It always gives me x86_64 builds,
# even though arch == "x86_32" and the file name has x86_32 in it.
Copy link
Member

@bruvzg bruvzg Aug 16, 2022

Choose a reason for hiding this comment

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

Depending on setup, MinGW can have either prefixed binaries (e.g. x86_64-w64-mingw32-gcc) or everything in the subfolder (gcc) in this case which one used is determined by path. I'm not sure how to detect arch in this case, we can do something like detect_visual_c_compiler_version, but MinGW path is not standard (might work for MSYS2 - https://www.msys2.org/docs/environments/).

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Using -march= seems to work fine with MinGW, but x86-64 for example only available if running from 64-bit MSYS2 environment.

So I guess the best way is to, try to set prefix based on arch if it's not set (ignore it otherwise since it can be something line /mingw/bin/ without arch name). Always set -march to make sure it's building for the correct one. Plus check MSYS2 env variables and warn if trying to use 64-bit arch in 32-bit env.

For MSVC, I think we can always force compilers path based on arch, even if it's started from wrong environment (maybe with a warning as well).

In any case, this should be good to merge as is (after rebase), and I'll add both checks / -march for Windows cross compile when implementing ARM support for Windows.

@aaronfranke aaronfranke force-pushed the use-arch-btw branch 2 times, most recently from a556b4e to 1ae98cc Compare August 24, 2022 20:11
@akien-mga
Copy link
Member

akien-mga commented Aug 25, 2022

I'm pretty happy with the state of this PR now, I'll do a final review and squash the commits so we can merge.

My only remaining concern is the same as expressed by @m4gr3d, there's potential confusion between the values we use for arch and the values with have to use for ABI names/folders in Android.

Fully removes the `bits` option and adapts the code that relied on it.

Co-authored-by: Rémi Verschelde <[email protected]>
@akien-mga
Copy link
Member

I reviewed the changes again and amended a couple nitpicks.

I tested an Android build with:

scons p=android arch=arm64 tools=no target=release_debug
cd platform/android/java
./gradlew generateGodotTemplates

And it seems to work fine. I could use the resulting APK and source templates to do both APK and Custom Build/AAB exports to my arm64 Poco F1, which ran fine.

I still have some concerns about the Android+Mono changes, and I think some renaming might be in order to make a clear separation between the arch as used by Godot SCons and the abi as expected by Gradle/Android. We should avoid assigning Godot's env["arch"] names to variables named abi IMO. But I think this can be cleaned up in future PRs together with testing and if needed fixing the Android+Mono export code.

@akien-mga akien-mga dismissed m4gr3d’s stale review August 25, 2022 09:23

Original concerns seem to have been addressed. Needs re-review/testing.

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.

Amazing work!

@akien-mga akien-mga merged commit c7eb423 into godotengine:master Aug 25, 2022
@akien-mga
Copy link
Member

Thanks!

Zylann added a commit to Zylann/godot_voxel that referenced this pull request Aug 26, 2022
@aaronfranke aaronfranke deleted the use-arch-btw branch September 6, 2022 00:28
akien-mga added a commit to godotengine/godot-build-scripts that referenced this pull request Sep 7, 2022
Needed after godotengine/godot#55778.
Not sure how alpha15 built properly without this :O
@raulsntos raulsntos mentioned this pull request Mar 4, 2023
3 tasks
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.

8 participants