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

Add support for building CoreCLR for MacCatalyst/iOS simulator #109928

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

filipnavara
Copy link
Member

Re-open and rebase of #98127

Build instructions:

  • Build the runtime pack and tools: ./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
  • Run the sample app: ./dotnet.sh publish src/mono/sample/iOS/Program.csproj -c Release /p:TargetOS=maccatalyst /p:TargetArchitecture=arm64 /p:DeployAndRun=true /p:UseMonoRuntime=false /p:RunAOTCompilation=false /p:MonoForceInterpreter=false

Related work:

Notably, this doesn't include CI scripts to build this or the runtime packs. I am open to suggestions on how to better split this into more digestible/reviewable chunks.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 18, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 18, 2024
src/coreclr/hosts/inc/coreclrhost.h Outdated Show resolved Hide resolved
src/coreclr/pal/src/CMakeLists.txt Outdated Show resolved Hide resolved
@@ -494,7 +494,7 @@ if new_level is -1, the nesting level will not be modified
--*/
int DBG_change_entrylevel(int new_level);

#ifdef __APPLE__
#ifdef TARGET_OSX
Copy link
Member

Choose a reason for hiding this comment

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

Is TARGET_OSX a subset of TARGET_APPLE?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is.

src/coreclr/pal/src/map/virtual.cpp Outdated Show resolved Hide resolved
src/native/corehost/hostpolicy/hostpolicy_context.cpp Outdated Show resolved Hide resolved
src/native/libs/System.Native/entrypoints.c Outdated Show resolved Hide resolved
@@ -228,6 +228,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)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to install this?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

src/coreclr/hosts/inc/coreclrhost.h Outdated Show resolved Hide resolved
src/coreclr/pal/src/exception/seh-unwind.cpp Outdated Show resolved Hide resolved
src/coreclr/pal/src/map/virtual.cpp Outdated Show resolved Hide resolved
src/coreclr/pal/src/map/virtual.cpp Outdated Show resolved Hide resolved
src/coreclr/pal/src/misc/dbgmsg.cpp Show resolved Hide resolved
src/native/corehost/apphost/static/CMakeLists.txt Outdated Show resolved Hide resolved
src/native/libs/System.Globalization.Native/CMakeLists.txt Outdated Show resolved Hide resolved
src/native/libs/System.Native/entrypoints.c Outdated Show resolved Hide resolved
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@janvorli
Copy link
Member

@filipnavara can you please resolve the conflicts so that we can merge the change in?

@filipnavara
Copy link
Member Author

@filipnavara can you please resolve the conflicts so that we can merge the change in?

Done.

@janvorli
Copy link
Member

@filipnavara there are some test failures, I think that I've seen some of them in the previous runs already. Could you please take a look to see if they could possibly be related to this change?

@filipnavara
Copy link
Member Author

filipnavara commented Jan 15, 2025

  • The tvOS failures seems to be [Apple-mobile] System.Tests.StringTests.[Starts,Ends]WithNoMatch_StringComparison test failure #108832 / [Apple][x64] EndsWithNoMatch_StringComparison test failure #108747. The issue is closed but without any link to a resolution. The failure is happening with MonoVM and not in any code that this PR touched.
  • wasi-wasm is infrastructure issue.
  • osx-arm64 failed with The process cannot access the file '/Users/runner/work/1/s/artifacts/bin/Microsoft.NETCore.App.MonoCrossAOT/Release/net10.0/osx-arm64/Microsoft.NETCore.App.MonoCrossAOT.deps.json' because it is being used by another process.. I think it would succeed on a re-run. I don't see an open issue for this.
  • windows-x64 failed with Could not read lines from file "D:\a\_work\1\s\artifacts\obj\Microsoft.NETCore.App.MonoCrossAOT\Release\net10.0\win-x64\Microsoft.NETCore.App.MonoCrossAOT.sfxproj.FileListAbsolute.txt". The process cannot access the file 'D:\a\_work\1\s\artifacts\obj\Microsoft.NETCore.App.MonoCrossAOT\Release\net10.0\win-x64\Microsoft.NETCore.App.MonoCrossAOT.sfxproj.FileListAbsolute.txt' because it is being used by another process.. Seems similar enough to the above?

I don't think any of that is related to this PR but it may be worth re-running the affected pipelines.

@filipnavara
Copy link
Member Author

Issue was filed for the MonoCrossAOT build errors - #111474. It happened in an unrelated PR.

@jkotas
Copy link
Member

jkotas commented Jan 18, 2025

@filipnavara Could you please resolve the conflict?

@filipnavara
Copy link
Member Author

@filipnavara Could you please resolve the conflict?

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Infrastructure-coreclr community-contribution Indicates that the PR has been added by a community member os-maccatalyst MacCatalyst OS
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants