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

C#: iOS and Apple Silicon fixes #49248

Merged
merged 6 commits into from
Jun 2, 2021
Merged

Conversation

neikeq
Copy link
Contributor

@neikeq neikeq commented Jun 1, 2021

Supersedes #45499 (cherry-picks the commit)

Fixes #40757
Fixes #42960
Likely fixes #45421

…xcframework`.

Build and export iOS Mono libs as `.xcframework`s, for Apple Silicon iOS simulator support.
Replaced obsolete preprocessor check for simulator/device in C code.
Architecture can no longer be used to determine this with Apple Silicon.
The new code uses `TARGET_OS_SIMULATOR` from `TargetConditionals.h`.

We have some mono libs which can only be used in devide builds.
We were adding them as static libs. Previously it was only causing
warnings because missing arch for the simulator, but now this
is treated as an error.

To fix this we turn them into xcframeworks with dummy static libs
for the simulator and the actual ones for devices.
We use `Mono.Cecil` to search for P/Invoke methods in assemblies in
order to collect symbols that we must prevent from being stripped.

We could pass the symbols as `-u` linker arguments (`-Wl,-u,symbol`)
for the native target (not for the project), but it was simpler to
generate referencing code and avoid changes to Godot's iOS exporter.
Added `SystemConfiguration.framework` to the Xcode project to fix
undefined symbols errors building without the interpreter, like:
`_SCNetworkReachabilityScheduleWithRunLoop`.

Added explicit static constructors to the generated `NativeCalls`
class to avoid a `TypeInitializationException` at startup when
Godot attempts to read the static fields (like `godot_api_hash`)
from this class.
This seems to be an issue with Mono's AOT compiler and classes
with the `beforefieldinit` attribute. Not sure if it only happens
when the fields are only accessed via reflection as was our case.
Explicitly declaring the static constructor makes the C# compiler
not add the `beforefieldinit` attribute to the class.
@akien-mga akien-mga merged commit 7887ff4 into godotengine:3.x Jun 2, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

@neikeq @bruvzg What changes do I need to make in official build scripts to use this?

I guess godotengine/godot-build-scripts#16 and godotengine/build-containers#68 need to be finalized and merged, and I guess the new iphone-mono-libs need to be copied somewhere too?

@bruvzg
Copy link
Member

bruvzg commented Jun 2, 2021

I guess godotengine/godot-build-scripts#16 and godotengine/build-containers#68 need to be finalized and merged, and I guess the new iphone-mono-libs need to be copied somewhere too?

Yes, iphone-mono-libs should be extracted, libmono-ee-interp, libmono-icall-table and libmono-ilgen static libs should go into frameworks and added to template. godotengine/build-containers#68 and godotengine/build-containers#68 may need some extra changes, but I'm not sure OSXCross is capable of building arm64 simulator libs at all (it was not able to do it last time I have checked).

@neikeq
Copy link
Contributor Author

neikeq commented Jun 2, 2021

Sorry, I forgot to mention this depends on godotengine/godot-mono-builds#39 and godotengine/godot-mono-builds#40, which I just proceeded to merge.

I commented on both godotengine/godot-build-scripts#16 and godotengine/build-containers#68 with the changes that should be needed.

but I'm not sure OSXCross is capable of building arm64 simulator libs at all (it was not able to do it last time I have checked).

AFAIK this is the reason #45480 was reverted. I talked about this with @akien-mga and he agreed to the cherry-pick of those changes, so this may have changed.

@akien-mga
Copy link
Member

AFAIK this is the reason #45480 was reverted. I talked about this with @akien-mga and he agreed to the cherry-pick of those changes, so this may have changed.

I haven't tested in the last 5 months so... I guess we'll see :)

@Lectamenop
Copy link

Lectamenop commented Sep 3, 2023

Hello, I still encounter issues #40757
with godot mono 3.5.1 stable
Anybody knows how to fix this ?

@AThousandShips
Copy link
Member

Please open a new issue report for this

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.

5 participants