Skip to content

[aot] Build cross compilers targeting x64/x86 hosted on osx-arm64 #89027

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

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Jul 17, 2023

This PR allows an osx-arm64 or osx-x64 machine to produce a mono-aot-cross compiler that will run on the following host and create AOT images for the following targets:

Host Target Test App runs
osx-arm64 iossimulator-x64
osx-arm64 android-x64
osx-arm64 android-x86 ✅ - depends on a hack for #89039

Additionally a linux-x64 or linux-arm64 machine can build a mono-aot-cross compiler for these host/target pairs:

Host Target Test App runs
linux-arm64 android-x64
linux-arm64 linux_musl-x64
linux-arm64 android-x86

Related to #82495

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 17, 2023
@ghost ghost assigned lambdageek Jul 17, 2023
@lambdageek
Copy link
Member Author

/cc @ivanpovazan @directhex

@lambdageek lambdageek added area-Codegen-AOT-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 17, 2023
@lambdageek
Copy link
Member Author

% uname -m
arm64
% file /Users/alklig/work/dotnet-runtime/runtime-review/src/mono/sample/iOS/bin/iossimulator-x64/Bundle/HelloiOS/Debug-iphonesimulator/HelloiOS.app/HelloiOS
/Users/alklig/work/dotnet-runtime/runtime-review/src/mono/sample/iOS/bin/iossimulator-x64/Bundle/HelloiOS/Debug-iphonesimulator/HelloiOS.app/HelloiOS: Mach-O 64-bit executable x86_64
Screenshot 2023-07-17 at 12 34 45

@ivanpovazan
Copy link
Member

/cc: @akoeplinger

@lambdageek
Copy link
Member Author

host: osx-arm64 target: android-x64 also works with this PR

I probably will need to try host: linux-arm64 target: android-x64 separately since some of the changes here were in the __APPLE__ ifdef...

@lambdageek lambdageek changed the title [aot][ios] Build cross compiler targeting x64 hosted on arm64 [aot] Build cross compilers targeting x64/x86 hosted on osx-arm64 Jul 17, 2023
@lambdageek
Copy link
Member Author

host osx-arm64 target android-x86 is also now part of this PR

@lambdageek
Copy link
Member Author

Getting the linux-arm64 stuff working depends on me re-learning how to build stuff using Docker images

@lambdageek
Copy link
Member Author

Oh, the android-x86 build depends on a hack to work around #89039

diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake
index 97947fe8879..a31a1de3f23 100644
--- a/eng/native/tryrun.cmake
+++ b/eng/native/tryrun.cmake
@@ -48,7 +48,7 @@ elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h)
 endif()
 
 if(DARWIN)
-  if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$")
+  if(TARGET_ARCH_NAME MATCHES "^(arm64|x64|x86)$")
     set_cache_value(FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL_EXITCODE 1)
     set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1)
     set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)

@directhex
Copy link
Contributor

Android Linux host repro command is:

docker run -e ROOTFS_DIR=/crossrootfs/arm64 -w $(pwd) --platform linux/amd64 -v $(pwd):$(pwd) -it mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-arm64 ./build.sh -subset mono+packs -c release -arch arm64 -ci  /p:MonoCrossAOTTargetOS=android /p:SkipMonoCrossJitConfigure=true /p:BuildMonoAOTCrossCompilerOnly=true /bl

Relies on offset files from the most recent build of https://dev.azure.com/dnceng-public/public/_build?definitionId=129&branchFilter=331 being in artifacts/obj/mono/offsetfiles/ (e.g. artifacts/obj/mono/offsetfiles/android.x64.Release/cross/offsets-x64-android.h should exist)

@lambdageek
Copy link
Member Author

lambdageek commented Jul 17, 2023

So as I understand it, I built the exact opposite of what we wanted for our CI.

We want an osx-x64 build machine to (for example) create a mono-aot-cross that runs on osx-arm64 and is capable of producing android-x64.

@lambdageek lambdageek added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jul 17, 2023
@directhex
Copy link
Contributor

Linux fix:

diff --git a/src/mono/mono/utils/mono-context.h b/src/mono/mono/utils/mono-context.h
index aa444a2f980..9ce932575b1 100644
--- a/src/mono/mono/utils/mono-context.h
+++ b/src/mono/mono/utils/mono-context.h
@@ -47,7 +47,12 @@ typedef __uint128_t MonoContextSimdReg;
 #endif
 #elif defined(__linux__) && defined(__GLIBC__)
 #define MONO_HAVE_SIMD_REG
+#if !defined(MONO_CROSS_COMPILE)
 typedef struct _libc_xmmreg MonoContextSimdReg;
+#else
+/* if building for an arm64 host machine, a cross compiler that produces x64 modules, fake a MonoContextSimdReg */
+typedef __uint128_t MonoContextSimdReg;
+#endif
 #elif defined(HOST_WIN32)
 #define MONO_HAVE_SIMD_REG
 //#define MONO_HAVE_SIMD_REG_AVX

@directhex
Copy link
Contributor

I think this covers yaml changes https://gist.github.com/directhex/6af1d74199084a992dad250294aa876e

Workloads generally need some finesse to deal with all the new native arm64 stuff we have going in lots of places

@lambdageek
Copy link
Member Author

@directhex Applied both of your patches, thanks! The x64 CI machines should be building the arm64 packages now, I believe.

@steveisok @akoeplinger please take a look

@lambdageek lambdageek removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jul 18, 2023
@lambdageek lambdageek merged commit dc6f9b4 into dotnet:main Jul 18, 2023
steveisok pushed a commit to steveisok/runtime that referenced this pull request Aug 3, 2023
…, and android where possible

As a result of dotnet#89027 and dotnet#74715, we can now build native arm64 cross compilers on linux and macos. This change adds the right references to the workload manifest so that they can be installed with maui and the mobile SDK's.

win-arm64 is the only arm64 platform left and that is a work in progress.

Contributes to dotnet#82495

Fixes dotnet/maui#4476
steveisok added a commit that referenced this pull request Aug 4, 2023
…, and android where possible (#89961)

As a result of #89027 and #74715, we can now build native arm64 cross compilers on linux and macos. This change adds the right references to the workload manifest so that they can be installed with maui and the mobile SDK's.

win-arm64 is the only arm64 platform left and that is a work in progress.

Contributes to #82495

Fixes dotnet/maui#4476
@ghost ghost locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants