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 iOS/tvOS simulator #98127

Closed
wants to merge 24 commits into from

Conversation

filipnavara
Copy link
Member

Build instructions:

  • Build the runtime pack and tools: ./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
  • Run the sample app in iOS simulator: ./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

Additional work outside of dotnet/runtime:

Obligatory screenshot:
image

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Feb 7, 2024
@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 Feb 7, 2024
@filipnavara filipnavara added the os-ios Apple iOS label Feb 7, 2024
@ghost
Copy link

ghost commented Feb 7, 2024

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

Issue Details

Build instructions:

  • Build the runtime pack and tools: ./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
  • Run the sample app in iOS simulator: ./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

Additional work outside of dotnet/runtime:

Obligatory screenshot:
image

Author: filipnavara
Assignees: -
Labels:

os-ios, community-contribution, needs-area-label

Milestone: -

@teo-tsirpanis
Copy link
Contributor

For my own curiosity, will CoreCLR iOS apps be possible to be shipped in the third-party app stores that will come to the EU?

@jkotas jkotas added area-Infrastructure-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 8, 2024
@ghost
Copy link

ghost commented Feb 8, 2024

Tagging subscribers to this area: @hoyosjs
See info in area-owners.md if you want to be subscribed.

Issue Details

Build instructions:

  • Build the runtime pack and tools: ./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
  • Run the sample app in iOS simulator: ./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

Additional work outside of dotnet/runtime:

Obligatory screenshot:
image

Author: filipnavara
Assignees: -
Labels:

area-Infrastructure-coreclr, os-ios, community-contribution, needs-area-label

Milestone: -

@ryujit-bot
Copy link

Diff results for #98127

Throughput diffs

Throughput diffs for windows/arm64 ran on windows/x64

MinOpts (-0.00% to +0.01%)
Collection PDIFF
libraries.pmi.windows.arm64.checked.mch +0.01%

Details here


@@ -34,6 +34,7 @@
static const Entry s_sysNative[] =
{
DllImportEntry(SystemNative_FStat)
#if !defined(TARGET_APPLE) || defined(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.

src/native/libs are shared with Mono. How does this work on iOS - why are these changes not needed for Mono/iOS?

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is used only for the static entrypoint resolution in apphost. Technically we would not need it here either if I removed the (unused) apphost build.

@filipnavara
Copy link
Member Author

For my own curiosity, will CoreCLR iOS apps be possible to be shipped in the third-party app stores that will come to the EU?

Probably not. I was hoping that there would be a change to allow deployment to your own device for debugging purposes, but you still need a restricted entitlement (JIT) for that and Apple won’t let you get it for signing.

@filipnavara
Copy link
Member Author

Unfortunately, the debugger doesn't work yet (CORDBG_E_DEBUG_COMPONENT_MISSING). I think I didn't compile all the components. I'll drop the tvOS part with next rebase, it's not polished...

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

mono_ios_runtime_init (void)
{
#if INVARIANT_GLOBALIZATION
setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE);
Copy link
Member

Choose a reason for hiding this comment

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

Would it work if these were passed via runtime properties? It feels wrong to pollute the process env. variable space like 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.

FWIW this is preexisting code from

#if INVARIANT_GLOBALIZATION
setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE);
#endif
.

I didn't really think it matters when the AppleAppBuilder was used only for tests and samples. However, it got productized as part of shared library building tooling, so maybe we should revisit it.

Copy link
Member

Choose a reason for hiding this comment

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

yes this could use runtimeconfig now, I think this was added way back when we didn't have support for parsing it and this was just used for tests

}

void
mono_ios_runtime_init (void)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe once this is merged, we should followup with some naming cleanup in the samples and rename this to just ios_runtime_init...

@vitek-karas vitek-karas requested a review from kotlarmilos March 11, 2024 12:07
Copy link
Member

@kotlarmilos kotlarmilos left a comment

Choose a reason for hiding this comment

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

Thanks, looks great! Could we add some test coverage to this PR? Is it possible to enable functional tests?

Build the runtime pack and tools with

```
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to JIT on arm64 simulators?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically yes. You need to call the one API to enable it which is not allowed in headers. I would not do that in production, but I think it's okay for local debugging.

#if !HAVE_MACH_EXCEPTIONS
#if defined(TARGET_TVOS)

static bool SwitchStackAndExecuteHandler(int code, siginfo_t *siginfo, void *context, size_t sp)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this tvOS-specific?

Copy link
Member Author

Choose a reason for hiding this comment

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

tvOS arbitrarily lacks some of the Mach APIs. I was planning to rebase and drop the tvOS part for now.

@@ -588,7 +588,7 @@ namespace CorUnix
m_pNext = pNext;
};

#if !HAVE_MACH_EXCEPTIONS
#if !HAVE_MACH_EXCEPTIONS && !defined(TARGET_TVOS)
Copy link
Member

Choose a reason for hiding this comment

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

What scenarios would apply here, if not tvOS-related?

@@ -190,10 +190,10 @@ private static string SetArch(string arch)
string? diagnosticPorts,
IEnumerable<string> runtimeComponents,
string? nativeMainSource = null,
bool useNativeAOTRuntime = false,
TargetRuntime targetRuntime = TargetRuntime.MonoVM,
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for introducing TargetRuntime enum.

@kotlarmilos
Copy link
Member

kotlarmilos commented Mar 27, 2024

Can we integrate this into the official build pipeline and run a functional test in runtime-ioslikesimulator pipeline?

@filipnavara
Copy link
Member Author

Sorry for not caring enough about this PR. I hope to give it some attention next week.

Can we integrate this into the official build pipeline and run a functional test in runtime-ioslikesimulator pipeline?

I'll check what would it take but the YAML pipelines are not exactly my strength.

@filipnavara
Copy link
Member Author

filipnavara commented Jun 12, 2024

I'll rebase the PR again.

I don't have much time to work on this at the moment. Last time I tried to get the debugger working. First problem is that the app gets native DAC instead of the cross-build DAC and the cross-built one is not signed as part of the build process. I managed to manually copy the right binaries into the deployed app bundle. I proceeded to test with the Samsung .NET Debugger so I can get more info about the errors. The next thing that failed was opening the debug pipe (timeout). Unfortunately, I didn't take notes at that point, so I don't have more details to share.

@akoeplinger
Copy link
Member

I wonder if we should get the straightforward changes like TARGET_OSX -> TARGET_APPLE extracted to a separate PR?

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-coreclr community-contribution Indicates that the PR has been added by a community member os-ios Apple iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants