Skip to content

Commit 717d3b1

Browse files
filipnavaraAaronRobinsonMSFTkotlarmilos
authored
Add support for building CoreCLR for MacCatalyst/iOS simulator (#109928)
* Make it possible to compile CoreCLR on iOS-like platforms with './build.sh clr+clr.nativeaotlibs+libs+packs -os [iossimulator/maccatalyst/ios] -arch arm64 -cross' Build the singlefilehost even if we don't currently use it Make coreclrhost.h compatible v C(not++) Fix TargetOS::IsMacOS WIP: AppleAppBuilder support for CoreCLR Make the sample app working: dotnet publish src/mono/sample/iOS/Program.csproj -c Release /p:TargetOS=iossimulator /p:TargetArchitecture=arm64 /p:AppleAppBuilderRuntime=CoreCLR /p:DeployAndRun=true /p:UseMonoRuntime=false /p:RunAOTCompilation=false /p:MonoForceInterpreter=false Cleanup Update src/tasks/AppleAppBuilder/AppleAppBuilder.csproj Co-authored-by: Adeel Mujahid <[email protected]> Use sys_icache_invalidate for all iOS-like platforms Consolidate macOS-only entrypoints in a single #if block Apply feedback Fix jitinterface cross-build Infer AppleAppBuilderRuntime from UseMonoRuntime and UseNativeAOTRuntime Minor changes to test infrastructure Add basic documentation Add nearly complete support for building runtime tests Fix building seh-unwind with older iOS SDK Use enum for TargetRuntime in AppleAppBuilder Fix LibraryBuilder build Cleanup Fix after rebase Revert accidental change Fix tvOS build Drop CoreCLR tvOS Simulator support for now * Fix rpath on MacCatalyst * Apply suggestions from code review Co-authored-by: Aaron Robinson <[email protected]> * Use CORECLR_HOSTING_API_LINKAGE for extern 'C' * Remove extra #include * Drop ICU linkage (not needed with Hybrid Globalization) * Move jit_write_protect_np initialization * Use __APPLE__ in PAL instead of TARGET_APPLE for consistency * Revert changes to native libs and exclude singlefilehost * Revert more singlefilehost changes * Remove excessive -D_XOPEN_SOURCE * Fix build with FEATURE_PERFTRACING_STANDALONE_PAL (debug libs) * Build with FEATURE_STANDALONE_GC=0 * Remove extra NativeDependencies property (bad merge) * Add back the UseNativeAOTRuntime property to unblock CI --------- Co-authored-by: Aaron Robinson <[email protected]> Co-authored-by: Milos Kotlar <[email protected]>
1 parent 0a477a8 commit 717d3b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+568
-203
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Cross Compilation for iOS Simulator on macOS
2+
3+
## Requirements
4+
5+
Build requirements are the same as for building native CoreCLR on macOS. iPhone SDK has to be enabled in Xcode installation.
6+
7+
## Cross compiling CoreCLR
8+
9+
Build the runtime pack and tools with
10+
11+
```
12+
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
13+
```
14+
15+
## Running the sample iOS app
16+
17+
Build and run the sample app with
18+
19+
```
20+
./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
21+
```
22+
23+
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.
24+
25+
## Running the runtime tests
26+
27+
Build the runtime tests with
28+
29+
```
30+
./src/tests/build.sh -os iossimulator arm64 Release -p:UseMonoRuntime=false
31+
```
32+
33+
Running the tests is not implemented yet. It will likely need similar app bundle infrastructure as NativeAOT/iOS uses.

eng/Subsets.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
</PropertyGroup>
8383

8484
<PropertyGroup Condition="'$(RuntimeFlavor)' == ''">
85-
<RuntimeFlavor Condition="'$(TargetsMobile)' == 'true' and !$(_subset.Contains('+clr.nativeaotlibs+'))">Mono</RuntimeFlavor>
86-
<RuntimeFlavor Condition="('$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and $(_subset.Contains('+clr.nativeaotlibs+'))">CoreCLR</RuntimeFlavor>
85+
<RuntimeFlavor Condition="('$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and ($(_subset.Contains('+clr.nativeaotlibs+')) or $(_subset.Contains('+clr.runtime+')))">CoreCLR</RuntimeFlavor>
86+
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and '$(TargetsMobile)' == 'true'">Mono</RuntimeFlavor>
8787
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and ($(_subset.Contains('+mono+')) or $(_subset.Contains('+mono.runtime+'))) and (!$(_subset.Contains('+clr+')) and !$(_subset.Contains('+clr.runtime+')) and !$(_subset.Contains('+clr.corelib+')))">Mono</RuntimeFlavor>
8888
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">$(PrimaryRuntimeFlavor)</RuntimeFlavor>
8989
</PropertyGroup>
@@ -92,7 +92,7 @@
9292
<DefaultCoreClrSubsets>clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools+host.native</DefaultCoreClrSubsets>
9393
<DefaultCoreClrSubsets Condition="'$(PackageRID)' == 'linux-armel'">clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
9494
<!-- Even on platforms that do not support the CoreCLR runtime, we still want to build ilasm/ildasm. -->
95-
<DefaultCoreClrSubsets Condition="'$(PrimaryRuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>
95+
<DefaultCoreClrSubsets Condition="'$(RuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>
9696

9797
<DefaultNativeAotSubsets>clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime</DefaultNativeAotSubsets>
9898

src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageFile Include="$(RuntimeBinDir)R2RDump\ILCompiler.Reflection.ReadyToRun.dll">
14+
<PackageFile Include="$(RuntimeBinDir)ILCompiler.Reflection.ReadyToRun.dll">
1515
<TargetPath>\lib\netstandard2.0\</TargetPath>
1616
</PackageFile>
1717
<Dependency Include="System.Reflection.Metadata">

src/coreclr/CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ include(components.cmake)
5959
#---------------------------
6060
# Build the single file host
6161
#---------------------------
62-
if(NOT CLR_CROSS_COMPONENTS_BUILD)
62+
if(NOT CLR_CROSS_COMPONENTS_BUILD AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS)
6363
set(CLR_SINGLE_FILE_HOST_ONLY 1)
6464
add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static)
6565
add_dependencies(runtime singlefilehost)
@@ -101,8 +101,10 @@ if(CLR_CMAKE_HOST_UNIX)
101101
add_linker_flag(-Wl,-z,notext)
102102
endif()
103103

104-
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
104+
if(NOT CLR_CMAKE_HOST_TVOS)
105105
add_subdirectory(pal)
106+
endif()
107+
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
106108
add_subdirectory(hosts)
107109
endif()
108110
else()
@@ -129,7 +131,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
129131
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
130132
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)
131133

132-
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
134+
if(NOT CLR_CMAKE_HOST_TVOS)
133135
add_subdirectory(debug/debug-pal)
134136
endif()
135137

@@ -243,7 +245,7 @@ if(CLR_CMAKE_HOST_UNIX)
243245
add_subdirectory(nativeresources)
244246
endif(CLR_CMAKE_HOST_UNIX)
245247

246-
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
248+
if(NOT CLR_CMAKE_HOST_TVOS)
247249
add_subdirectory(utilcode)
248250
add_subdirectory(inc)
249251

@@ -257,11 +259,14 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H
257259
add_subdirectory(binder)
258260
add_subdirectory(classlibnative)
259261
add_subdirectory(dlls)
260-
add_subdirectory(tools)
261262
add_subdirectory(unwinder)
262263
add_subdirectory(interop)
264+
endif()
263265

264-
if(CLR_CMAKE_HOST_WIN32)
265-
add_subdirectory(hosts)
266-
endif(CLR_CMAKE_HOST_WIN32)
266+
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
267+
add_subdirectory(tools)
267268
endif(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
269+
270+
if(CLR_CMAKE_HOST_WIN32)
271+
add_subdirectory(hosts)
272+
endif(CLR_CMAKE_HOST_WIN32)

src/coreclr/debug/daccess/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ target_link_libraries(daccess PRIVATE cdacreader_api)
4747

4848
add_dependencies(daccess eventing_headers)
4949

50-
if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS)
50+
if(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE)
5151
add_definitions(-DUSE_DAC_TABLE_RVA)
5252

53-
set(args $<$<NOT:$<BOOL:${CLR_CMAKE_HOST_OSX}>>:--dynamic> $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h)
53+
set(args $<$<NOT:$<BOOL:${CLR_CMAKE_HOST_APPLE}>>:--dynamic> $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h)
5454

5555
add_custom_command(
5656
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)
7272
)
7373

7474
add_dependencies(daccess dactablerva_header)
75-
endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS)
75+
endif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS OR CLR_CMAKE_HOST_APPLE)

src/coreclr/dlls/mscordac/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ else(CLR_CMAKE_HOST_WIN32)
3131
# Add dependency on export file
3232
add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE})
3333

34-
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)
34+
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)
3535
generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE})
36-
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)
36+
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)
3737

3838
if(CORECLR_SET_RPATH AND CLR_CMAKE_HOST_OSX AND CLR_CMAKE_HOST_ARCH_ARM64)
3939
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ endif(CLR_CMAKE_TARGET_WIN32)
227227

228228
# add the install targets
229229
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
230+
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
231+
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
232+
endif()
230233

231234
# Enable profile guided optimization
232235
add_pgo(coreclr)

src/coreclr/hosts/inc/coreclrhost.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
#define CORECLR_CALLING_CONVENTION
1515
#endif
1616

17+
#ifdef __cplusplus
18+
#define CORECLR_HOSTING_API_LINKAGE extern "C"
19+
#else
20+
#define CORECLR_HOSTING_API_LINKAGE
21+
#endif
22+
1723
#include <stdint.h>
1824

1925
// For each hosting API, we define a function prototype and a function pointer
2026
// The prototype is useful for implicit linking against the dynamic coreclr
2127
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
2228
#define CORECLR_HOSTING_API(function, ...) \
23-
extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
29+
CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
2430
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
2531

2632
//

src/coreclr/inc/crosscomp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define MAKE_TARGET_DLLNAME_W(name) name W(".dll")
1818
#define MAKE_TARGET_DLLNAME_A(name) name ".dll"
1919
#else // TARGET_WINDOWS
20-
#ifdef TARGET_OSX
20+
#ifdef TARGET_APPLE
2121
#define MAKE_TARGET_DLLNAME_W(name) W("lib") name W(".dylib")
2222
#define MAKE_TARGET_DLLNAME_A(name) "lib" name ".dylib"
2323
#else
@@ -686,9 +686,9 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
686686

687687
#if defined(TARGET_OSX) && defined(TARGET_X86)
688688
#define DAC_CS_NATIVE_DATA_SIZE 76
689-
#elif defined(TARGET_OSX) && defined(TARGET_AMD64)
689+
#elif defined(TARGET_APPLE) && defined(TARGET_AMD64)
690690
#define DAC_CS_NATIVE_DATA_SIZE 120
691-
#elif defined(TARGET_OSX) && defined(TARGET_ARM64)
691+
#elif defined(TARGET_APPLE) && defined(TARGET_ARM64)
692692
#define DAC_CS_NATIVE_DATA_SIZE 120
693693
#elif defined(TARGET_FREEBSD) && defined(TARGET_X86)
694694
#define DAC_CS_NATIVE_DATA_SIZE 12

src/coreclr/inc/executableallocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class ExecutableWriterHolder
285285

286286
void Unmap()
287287
{
288-
#if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
288+
#if defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
289289
if (m_addressRX != NULL)
290290
{
291291
PAL_JitWriteProtect(false);
@@ -321,7 +321,7 @@ class ExecutableWriterHolder
321321
ExecutableWriterHolder(T* addressRX, size_t size, ExecutableAllocator::CacheableMapping cacheMapping = ExecutableAllocator::AddToCache)
322322
{
323323
m_addressRX = addressRX;
324-
#if defined(HOST_OSX) && defined(HOST_ARM64)
324+
#if defined(HOST_APPLE) && defined(HOST_ARM64)
325325
m_addressRW = addressRX;
326326
PAL_JitWriteProtect(true);
327327
#else

0 commit comments

Comments
 (0)