-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add support for building CoreCLR for MacCatalyst/iOS simulator #109928
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
Changes from all commits
c4d5ca2
7e6d3bd
0de957b
d0e5ed7
b5a298d
05aa0e6
b98a4cd
d43265c
e3b4af9
02389e7
e4251b1
3ff9213
d2fcf82
5098d47
f6aae30
7686181
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Cross Compilation for iOS Simulator on macOS | ||
|
||
## Requirements | ||
|
||
Build requirements are the same as for building native CoreCLR on macOS. iPhone SDK has to be enabled in Xcode installation. | ||
|
||
## Cross compiling CoreCLR | ||
|
||
Build the runtime pack and tools with | ||
|
||
``` | ||
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release | ||
``` | ||
|
||
## Running the sample iOS app | ||
|
||
Build and run the sample app with | ||
|
||
``` | ||
./dotnet.sh publish src/mono/sample/iOS/Program.csproj -c Release /p:TargetOS=iossimulator /p:TargetArchitecture=arm64 /p:DeployAndRun=true /p:UseMonoRuntime=false /p:RunAOTCompilation=false /p:MonoForceInterpreter=false | ||
``` | ||
|
||
The command also produces an XCode project that can be opened with `open ./src/mono/sample/iOS/bin/iossimulator-arm64/Bundle/HelloiOS/HelloiOS.xcodeproj` and debugged in Xcode. | ||
|
||
## Running the runtime tests | ||
|
||
Build the runtime tests with | ||
|
||
``` | ||
./src/tests/build.sh -os iossimulator arm64 Release -p:UseMonoRuntime=false | ||
``` | ||
|
||
Running the tests is not implemented yet. It will likely need similar app bundle infrastructure as NativeAOT/iOS uses. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,10 +47,10 @@ target_link_libraries(daccess PRIVATE cdacreader_api) | |
|
||
add_dependencies(daccess eventing_headers) | ||
|
||
if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) | ||
if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hoyosjs, I think it was this change that broke debugging/diagnostics repo tests on MacOS x64. Adding CLR_CMAKE_HOST_APPLE here will cause the runtime DAC table to be generated in the old "rva" way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the change was intentional. I traced it back to the first commit on my previous branch but it could have been a result of some rebase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to remove/fix this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like at some point after the initial patch the conditional compilation of machoreader.cpp was added. This still uses the old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks Mike for drawing attention to this! Which pipeline is running these tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These failing tests are part of the diagnostics repo. There is a manual way of running them against a local runtime build, but there currently no way for the runtime repo to use them. There is Jeremy created this issue dotnet/diagnostics#5213 to track this work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for the pointers. |
||
add_definitions(-DUSE_DAC_TABLE_RVA) | ||
|
||
set(args $<$<NOT:$<BOOL:${CLR_CMAKE_HOST_OSX}>>:--dynamic> $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h) | ||
set(args $<$<NOT:$<BOOL:${CLR_CMAKE_HOST_APPLE}>>:--dynamic> $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h) | ||
|
||
add_custom_command( | ||
OUTPUT ${GENERATED_INCLUDE_DIR}/dactablerva.h | ||
|
@@ -72,4 +72,4 @@ if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) | |
) | ||
|
||
add_dependencies(daccess dactablerva_header) | ||
endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) | ||
endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,9 @@ else(CLR_CMAKE_HOST_WIN32) | |
# Add dependency on export file | ||
add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE}) | ||
|
||
if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU) | ||
if(CLR_CMAKE_HOST_APPLE OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU) | ||
generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) | ||
endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU) | ||
endif(CLR_CMAKE_HOST_APPLE OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_HAIKU) | ||
|
||
if(CORECLR_SET_RPATH AND CLR_CMAKE_HOST_OSX AND CLR_CMAKE_HOST_ARCH_ARM64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has CLR_CMAKE_HOST_OSX been completed replaced by CLR_CMAKE_HOST_APPLE? If so, then the RPATH in the DAC isn't be added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind. CLR_CMAKE_HOST_OSX is still defined if not maccatalyst. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to use same parameters for all Apple platforms (macOS, iOS, tvOS) whenever possible. RPATH may still need some tweaks for each platform due to different bundle structure on macOS/MacCatalyst and iOS/tvOS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll need to do another pass over the |
||
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,9 @@ endif(CLR_CMAKE_TARGET_WIN32) | |
|
||
# add the install targets | ||
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime) | ||
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS) | ||
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to install this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS generally restricts linking to static libraries or dynamic frameworks distributed with the app itself. The aim was to include statically built CoreCLR in the runtime pack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if that means that the single file is the only deployment mechanism on iOS. If it is the case, then I am not sure what would be the scenario where developers would explicitly use the static version of coreclr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linking with a static library typically results in smaller apps, which is why we've always linked Mono statically by default. Linking dynamically can make the build a little bit faster (from past experience in Xamarin, we never ported this to .NET when we migrated due to time constraints). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The single file is a host statically linked to all the native libraries including coreclr. The scenario when the developers would need static coreclr library would be when they want to use their own host. Thinking about it more, I guess distributing the static coreclr version actually makes sense to enable such scenarios. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that sounds like what we want. Note that .dylib won't do (Apple doesn't allow them in iOS apps), each dynamic library has to be made into a .framework (which works). FWIW Apple has recommended using no more than 6-8 .frameworks because otherwise it affects startup performance. |
||
endif() | ||
|
||
# Enable profile guided optimization | ||
add_pgo(coreclr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc: @steveisok