diff --git a/eng/Subsets.props b/eng/Subsets.props index 24b4bd26110aa7..89520bd0aeefe2 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -38,11 +38,12 @@ Mono Mono - CoreCLR + CoreCLR - clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages + clr.native+clr.corelib + $(DefaultCoreClrSubsets)+linuxdac+clr.tools+clr.nativecorelib+clr.packages mono.llvm+ mono.llvm+ diff --git a/eng/install-native-dependencies.sh b/eng/install-native-dependencies.sh index b32774a68a7f07..9390ae6c2a7884 100755 --- a/eng/install-native-dependencies.sh +++ b/eng/install-native-dependencies.sh @@ -28,7 +28,7 @@ if [ "$1" = "Linux" ]; then if [ "$?" != "0" ]; then exit 1; fi -elif [ "$1" = "OSX" ] || [ "$1" = "tvOS" ] || [ "$1" = "iOS" ]; then +elif [ "$1" = "OSX" ] || [ "$1" = "MacCatalyst" ] || [ "$1" = "tvOS" ] || [ "$1" = "iOS" ]; then engdir=$(dirname "${BASH_SOURCE[0]}") if [ "$3" = "azDO" ]; then @@ -47,7 +47,7 @@ elif [ "$1" = "OSX" ] || [ "$1" = "tvOS" ] || [ "$1" = "iOS" ]; then exit 1; fi else - echo "Must pass \"Linux\", \"tvOS\", \"iOS\" or \"OSX\" as first argument." + echo "Must pass \"Linux\", \"tvOS\", \"iOS\", \"MacCatalyst\" or \"OSX\" as first argument." exit 1 fi diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 5b72dedeb1a3bb..aac50b787296d4 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -85,7 +85,9 @@ + @@ -102,6 +104,8 @@ runtime/$(CoreCLRCrossTargetComponentDirName)_$(TargetArchitecture)/native true + @@ -111,7 +115,7 @@ - diff --git a/eng/pipelines/common/platform-matrix.yml b/eng/pipelines/common/platform-matrix.yml index 6e92936ffca301..3d69d0ef6859f8 100644 --- a/eng/pipelines/common/platform-matrix.yml +++ b/eng/pipelines/common/platform-matrix.yml @@ -381,7 +381,7 @@ jobs: targetRid: maccatalyst-x64 platform: MacCatalyst_x64 jobParameters: - runtimeFlavor: mono + runtimeFlavor: ${{ parameters.runtimeFlavor }} stagedBuild: ${{ parameters.stagedBuild }} buildConfig: ${{ parameters.buildConfig }} ${{ if eq(parameters.passPlatforms, true) }}: @@ -402,7 +402,7 @@ jobs: targetRid: maccatalyst-arm64 platform: MacCatalyst_arm64 jobParameters: - runtimeFlavor: mono + runtimeFlavor: ${{ parameters.runtimeFlavor }} stagedBuild: ${{ parameters.stagedBuild }} buildConfig: ${{ parameters.buildConfig }} ${{ if eq(parameters.passPlatforms, true) }}: diff --git a/eng/pipelines/coreclr/templates/build-job.yml b/eng/pipelines/coreclr/templates/build-job.yml index a3567fe88ef2a1..c5cd79dc856957 100644 --- a/eng/pipelines/coreclr/templates/build-job.yml +++ b/eng/pipelines/coreclr/templates/build-job.yml @@ -96,7 +96,7 @@ jobs: - name: compilerArg value: '' # AppleClang has different version scheme, so we let complier introspection pick up the available clang from PATH - - ${{ if eq(parameters.osGroup, 'OSX') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'MacCatalyst') }}: - name: compilerArg value: '' - ${{ if and(ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) }}: @@ -149,7 +149,7 @@ jobs: # Linux builds use docker images with dependencies preinstalled, # and FreeBSD builds use a build agent with dependencies # preinstalled, so we only need this step for OSX and Windows. - - ${{ if eq(parameters.osGroup, 'OSX') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'MacCatalyst') }}: - script: $(Build.SourcesDirectory)/eng/install-native-dependencies.sh $(osGroup) ${{ parameters.archType }} azDO displayName: Install native dependencies - ${{ if eq(parameters.osGroup, 'windows') }}: @@ -175,7 +175,7 @@ jobs: continueOnError: false condition: and(succeeded(), in(variables['SignType'], 'real', 'test')) - - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS', 'MacCatalyst') }}: - script: | du -sh $(Build.SourcesDirectory)/* df -h @@ -194,15 +194,19 @@ jobs: - script: set __TestIntermediateDir=int&&$(Build.SourcesDirectory)/src/coreclr/build-runtime$(scriptExt) $(buildConfig) $(archType) -ci $(enforcePgoArg) $(pgoInstrumentArg) $(officialBuildIdArg) $(clrInterpreterBuildArg) displayName: Build CoreCLR Runtime - - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS', 'MacCatalyst') }}: - script: | du -sh $(Build.SourcesDirectory)/* df -h displayName: Disk Usage after Build # Build CoreCLR Managed Components - - script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.paltestlist $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(pgoInstrumentArg) $(officialBuildIdArg) -ci - displayName: Build managed product components and packages + - ${{ if ne(parameters.osGroup, 'MacCatalyst') }}: + - script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.paltestlist $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(pgoInstrumentArg) $(officialBuildIdArg) -ci + displayName: Build managed product components and packages + - ${{ if eq(parameters.osGroup, 'MacCatalyst') }}: + - script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.corelib $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(pgoInstrumentArg) $(officialBuildIdArg) -ci + displayName: Build managed product components # Run CoreCLR Tools unit tests - ${{ if eq(parameters.testGroup, 'clrTools') }}: @@ -216,7 +220,7 @@ jobs: # Sign and add entitlements to these MacOS binaries - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - - ${{ if eq(parameters.osGroup, 'OSX') }}: + - ${{ if in(parameters.osGroup, 'OSX', 'MacCatalyst') }}: - template: /eng/pipelines/common/macos-sign-with-entitlements.yml parameters: diff --git a/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml b/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml index e3200502b7060d..93c91d8eee3128 100644 --- a/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml +++ b/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml @@ -156,4 +156,8 @@ jobs: - name: osArg value: -os FreeBSD + - ${{ if eq(parameters.osGroup, 'MacCatalyst') }}: + - name: osArg + value: -os MacCatalyst + steps: ${{ parameters.steps }} diff --git a/eng/pipelines/libraries/base-job.yml b/eng/pipelines/libraries/base-job.yml index bea30446deed64..65cf60c312d51a 100644 --- a/eng/pipelines/libraries/base-job.yml +++ b/eng/pipelines/libraries/base-job.yml @@ -70,7 +70,7 @@ jobs: - _runtimeOSArg: /p:RuntimeOS=ubuntu.16.04 # force a value for OS when cross-building - - ${{ if in(parameters.osGroup, 'Browser', 'iOS', 'tvOS', 'Android', 'FreeBSD') }}: + - ${{ if in(parameters.osGroup, 'Browser', 'iOS', 'MacCatalyst', 'tvOS', 'Android', 'FreeBSD') }}: - _osArg: -os ${{ parameters.osGroup }} - ${{ if ne(parameters.framework, '') }}: diff --git a/eng/pipelines/libraries/build-job.yml b/eng/pipelines/libraries/build-job.yml index ee0c0fc938f696..18c814642034a2 100644 --- a/eng/pipelines/libraries/build-job.yml +++ b/eng/pipelines/libraries/build-job.yml @@ -73,7 +73,7 @@ jobs: # If platform is in testBuildPlatforms we build tests as well. - ${{ if or(eq(parameters.runTests, true), containsValue(parameters.testBuildPlatforms, parameters.platform)) }}: - _subset: libs+libs.tests - - _additionalBuildArguments: /p:ArchiveTests=true + - _additionalBuildArguments: /p:ArchiveTests=true /p:RuntimeFlavor=${{ parameters.runtimeFlavor }} - ${{ parameters.variables }} diff --git a/eng/pipelines/libraries/helix-queues-setup.yml b/eng/pipelines/libraries/helix-queues-setup.yml index a54f7ff17da50d..2015d5c09d8e41 100644 --- a/eng/pipelines/libraries/helix-queues-setup.yml +++ b/eng/pipelines/libraries/helix-queues-setup.yml @@ -99,6 +99,14 @@ jobs: - OSX.1014.Amd64.Open - OSX.1015.Amd64.Open + # Mac Catalyst arm64 + - ${{ if eq(parameters.platform, 'MacCatalyst_arm64') }}: + - OSX.1100.ARM64.Open + + # Mac Catalyst x64 + - ${{ if eq(parameters.platform, 'MacCatalyst_x64') }}: + - OSX.1015.Amd64.Open + # Android - ${{ if in(parameters.platform, 'Android_x86', 'Android_x64') }}: - Ubuntu.1804.Amd64.Android.Open diff --git a/eng/pipelines/runtime-staging.yml b/eng/pipelines/runtime-staging.yml index 35a3fd9f9bc21d..8f6caa54e95ef8 100644 --- a/eng/pipelines/runtime-staging.yml +++ b/eng/pipelines/runtime-staging.yml @@ -334,6 +334,34 @@ jobs: buildArgs: -subset mono+libs+host+packs+libs.tests -c $(_BuildConfig) timeoutInMinutes: 120 +# +# CoreCLR Build for running Mac Catalyst libraries-innerloop +# +- template: /eng/pipelines/common/platform-matrix.yml + parameters: + jobTemplate: /eng/pipelines/coreclr/templates/build-job.yml + buildConfig: release + platforms: + - MacCatalyst_x64 + jobParameters: + testGroup: innerloop +# +# Libraries Build for running Mac Catalyst libraries-innerloop +# +- template: /eng/pipelines/common/platform-matrix.yml + parameters: + jobTemplate: /eng/pipelines/libraries/build-job.yml + buildConfig: Release + platforms: + - MacCatalyst_x64 + helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml + jobParameters: + isOfficialBuild: ${{ variables['isOfficialBuild'] }} + isFullMatrix: ${{ variables['isFullMatrix'] }} + runTests: true + testScope: innerloop + liveRuntimeBuildConfig: release + # # CoreCLR Build for running Apple Silicon libraries-innerloop # diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index aea51ddee8c283..72ce9309580f2d 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -10,6 +10,9 @@ true true BundleTestAppleApp;BundleTestAndroidApp + mono + $(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0 + $(CoreCLRArtifactsPath)inc @@ -190,7 +193,7 @@ TargetOS="$(TargetOS)" Arch="$(TargetArchitecture)" ProjectName="$(AssemblyName)" - MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0" + RuntimeHeaders="$(HeadersPath)" Assemblies="@(BundleAssemblies)" MainLibraryFileName="$(MainLibraryFileName)" ForceAOT="$(RunAOTCompilation)" @@ -202,7 +205,8 @@ Optimized="$(Optimized)" DevTeamProvisioning="$(DevTeamProvisioning)" OutputDirectory="$(BundleDir)" - AppDir="$(PublishDir)"> + AppDir="$(PublishDir)" + RuntimeFlavor="$(RuntimeFlavor)"> diff --git a/eng/testing/xunit/xunit.console.targets b/eng/testing/xunit/xunit.console.targets index 7710a05b5a37db..77d7363a22f4ee 100644 --- a/eng/testing/xunit/xunit.console.targets +++ b/eng/testing/xunit/xunit.console.targets @@ -2,7 +2,7 @@ true testResults.xml - true + true diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 8f82d83fa4b735..9b68f71c77f774 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -55,14 +55,6 @@ include(pgosupport.cmake) #--------------------------------------------------- include(components.cmake) -#--------------------------- -# Build the single file host -#--------------------------- -if(NOT CLR_CROSS_COMPONENTS_BUILD) - set(CLR_SINGLE_FILE_HOST_ONLY 1) - add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static) - add_dependencies(runtime singlefilehost) -endif() #------------------------- # Enable C++ EH with SEH #------------------------- @@ -143,6 +135,15 @@ endif(CLR_CMAKE_HOST_WIN32) #---------------------------------- include(clrdefinitions.cmake) +#--------------------------- +# Build the single file host +#--------------------------- +if(NOT CLR_CROSS_COMPONENTS_BUILD) + set(CLR_SINGLE_FILE_HOST_ONLY 1) + add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static) + add_dependencies(runtime singlefilehost) +endif() + if(FEATURE_STANDALONE_GC) add_definitions(-DFEATURE_STANDALONE_GC) add_subdirectory(gc) diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index d841ffc7287cbb..87137219570645 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -20,6 +20,8 @@ $(MSBuildThisFileDirectory)src\ILLink\ true + + true @@ -287,6 +289,12 @@ + + + + Common\Interop\OSX\Interop.SearchPath.cs + + diff --git a/src/coreclr/System.Private.CoreLib/src/System/Environment.iOS.cs b/src/coreclr/System.Private.CoreLib/src/System/Environment.iOS.cs new file mode 100644 index 00000000000000..372805e70086e2 --- /dev/null +++ b/src/coreclr/System.Private.CoreLib/src/System/Environment.iOS.cs @@ -0,0 +1,105 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; +using System.Threading; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using NSSearchPathDirectory = Interop.Sys.NSSearchPathDirectory; + +namespace System +{ + public static partial class Environment + { + private static Dictionary? s_specialFolders; + + private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option) + { + if (s_specialFolders == null) + { + Interlocked.CompareExchange(ref s_specialFolders, new Dictionary(), null); + } + + string? path; + lock (s_specialFolders) + { + if (!s_specialFolders.TryGetValue(folder, out path)) + { + path = GetSpecialFolder(folder) ?? string.Empty; + s_specialFolders[folder] = path; + } + } + return path; + } + + private static string? GetSpecialFolder(SpecialFolder folder) + { + switch (folder) + { + // TODO: fix for tvOS (https://github.com/dotnet/runtime/issues/34007) + // The "normal" NSDocumentDirectory is a read-only directory on tvOS + // and that breaks a lot of assumptions in the runtime and the BCL + + case SpecialFolder.Personal: + case SpecialFolder.LocalApplicationData: + return Interop.Sys.SearchPath(NSSearchPathDirectory.NSDocumentDirectory); + + case SpecialFolder.ApplicationData: + // note: at first glance that looked like a good place to return NSLibraryDirectory + // but it would break isolated storage for existing applications + return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, ".config"); + + case SpecialFolder.Resources: + return Interop.Sys.SearchPath(NSSearchPathDirectory.NSLibraryDirectory); // older (8.2 and previous) would return String.Empty + + case SpecialFolder.Desktop: + case SpecialFolder.DesktopDirectory: + return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Desktop"); + + case SpecialFolder.MyMusic: + return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Music"); + + case SpecialFolder.MyPictures: + return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Pictures"); + + case SpecialFolder.Templates: + return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, "Templates"); + + case SpecialFolder.MyVideos: + return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Videos"); + + case SpecialFolder.CommonTemplates: + return "/usr/share/templates"; + + case SpecialFolder.Fonts: + return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, ".fonts"); + + case SpecialFolder.Favorites: + return CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, "Favorites"); + + case SpecialFolder.ProgramFiles: + return Interop.Sys.SearchPath(NSSearchPathDirectory.NSApplicationDirectory); + + case SpecialFolder.InternetCache: + return Interop.Sys.SearchPath(NSSearchPathDirectory.NSCachesDirectory); + + case SpecialFolder.UserProfile: + return GetEnvironmentVariable("HOME"); + + case SpecialFolder.CommonApplicationData: + return "/usr/share"; + + default: + return string.Empty; + } + + static string CombineSearchPath(NSSearchPathDirectory searchPath, string subdirectory) + { + string? path = Interop.Sys.SearchPath(searchPath); + return path != null ? + Path.Combine(path, subdirectory) : + string.Empty; + } + } + } +} diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props index cd6569b48b21af..183a002558e947 100644 --- a/src/coreclr/clr.featuredefines.props +++ b/src/coreclr/clr.featuredefines.props @@ -13,7 +13,7 @@ - true + true true true diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake index 115031ff49b6ca..181fdfd9f4b562 100644 --- a/src/coreclr/clrdefinitions.cmake +++ b/src/coreclr/clrdefinitions.cmake @@ -220,6 +220,10 @@ if(CLR_CMAKE_TARGET_OSX) add_definitions(-DFEATURE_WRITEBARRIER_COPY) endif(CLR_CMAKE_TARGET_OSX) +if(CLR_CMAKE_TARGET_MACCATALYST) + add_definitions(-DTARGET_MACCATALYST) +endif(CLR_CMAKE_TARGET_MACCATALYST) + if (NOT CLR_CMAKE_TARGET_ARCH_I386 OR NOT CLR_CMAKE_TARGET_WIN32) add_compile_definitions($<$>>:FEATURE_EH_FUNCLETS>) endif (NOT CLR_CMAKE_TARGET_ARCH_I386 OR NOT CLR_CMAKE_TARGET_WIN32) diff --git a/src/coreclr/dlls/mscoree/CMakeLists.txt b/src/coreclr/dlls/mscoree/CMakeLists.txt index 4571b196aaa942..a3b2de2f3c84d9 100644 --- a/src/coreclr/dlls/mscoree/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/CMakeLists.txt @@ -15,6 +15,10 @@ list(APPEND CLR_SOURCES Native.rc ) +if(CLR_CMAKE_TARGET_MACCATALYST) + add_definitions(-DTARGET_MACCATALYST) +endif(CLR_CMAKE_TARGET_MACCATALYST) + set (DEF_SOURCES mscorwks_ntdef.src ) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index fae55ecdc3ea50..3b8bf9f6cb7f94 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -50,11 +50,11 @@ else(CLR_CMAKE_HOST_WIN32) set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive) endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) - if(CLR_CMAKE_TARGET_OSX) + if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST) # These options are used to force every object to be included even if it's unused. set(START_WHOLE_ARCHIVE -force_load) set(END_WHOLE_ARCHIVE ) - endif(CLR_CMAKE_TARGET_OSX) + endif(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST) set_exports_linker_option(${EXPORTS_FILE}) diff --git a/src/coreclr/hosts/CMakeLists.txt b/src/coreclr/hosts/CMakeLists.txt index f3a3b0c8fbd0e3..3e7db3020b2fc5 100644 --- a/src/coreclr/hosts/CMakeLists.txt +++ b/src/coreclr/hosts/CMakeLists.txt @@ -7,3 +7,4 @@ else(CLR_CMAKE_HOST_WIN32) endif(CLR_CMAKE_HOST_WIN32) add_subdirectory(corerun) +add_subdirectory(inc) diff --git a/src/coreclr/hosts/inc/CMakeLists.txt b/src/coreclr/hosts/inc/CMakeLists.txt new file mode 100644 index 00000000000000..f8298b8a257db3 --- /dev/null +++ b/src/coreclr/hosts/inc/CMakeLists.txt @@ -0,0 +1,2 @@ +install (FILES coreclrhost.h + DESTINATION inc) diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 46a3119d628de0..5f892f5a3ef446 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -14,13 +14,19 @@ #define CORECLR_CALLING_CONVENTION #endif +#ifndef __OBJC__ +#define CORECLR_EXTERN_C extern "C" +#else +#define CORECLR_EXTERN_C +#endif + #include // For each hosting API, we define a function prototype and a function pointer // The prototype is useful for implicit linking against the dynamic coreclr // library and the pointer for explicit dynamic loading (dlopen, LoadLibrary) #define CORECLR_HOSTING_API(function, ...) \ - extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ + CORECLR_EXTERN_C int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) // diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index b33141771fd912..b62658d17f6dad 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -465,7 +465,7 @@ endif (FEATURE_MERGE_JIT_AND_ENGINE) # Creates a static library "clrjit_static" to link into the VM. add_subdirectory(static) -if (CLR_CMAKE_TARGET_OSX AND CLR_CMAKE_TARGET_ARCH_ARM64) +if ((CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST) AND CLR_CMAKE_TARGET_ARCH_ARM64) set(TARGET_OS_NAME unix_osx) # Apple Arm64 has a special ABI, distinguish it. elseif (CLR_CMAKE_TARGET_UNIX) set(TARGET_OS_NAME unix) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 0c2021dab02d92..6357c8a89e4425 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -55,6 +55,10 @@ if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) add_definitions(-DFEATURE_USE_SYSTEM_LIBUNWIND) endif(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) +if(CLR_CMAKE_TARGET_MACCATALYST) + add_definitions(-DTARGET_MACCATALYST) +endif(CLR_CMAKE_TARGET_MACCATALYST) + if(CLR_CMAKE_TARGET_OSX) add_definitions(-DTARGET_OSX) if(CLR_CMAKE_TARGET_ARCH_AMD64) diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index ee4a3241196eaa..24649b335d2639 100644 --- a/src/coreclr/pal/src/configure.cmake +++ b/src/coreclr/pal/src/configure.cmake @@ -14,7 +14,7 @@ elseif(CLR_CMAKE_TARGET_SUNOS) set(CMAKE_REQUIRED_INCLUDES /opt/local/include) endif() -if(CLR_CMAKE_TARGET_OSX) +if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST) set(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE) elseif(NOT CLR_CMAKE_TARGET_FREEBSD AND NOT CLR_CMAKE_TARGET_NETBSD) set(CMAKE_REQUIRED_DEFINITIONS "-D_BSD_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L") @@ -1321,7 +1321,17 @@ if(NOT CLR_CMAKE_HOST_ARCH_ARM AND NOT CLR_CMAKE_HOST_ARCH_ARM64) set(CMAKE_REQUIRED_LIBRARIES) endif() -if(CLR_CMAKE_TARGET_OSX) +if(CLR_CMAKE_TARGET_MACCATALYST) + set(HAVE__NSGETENVIRON 1) + set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1) + set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))") + set(PAL_PT_ATTACH PT_ATTACH) + set(PAL_PT_DETACH PT_DETACH) + set(PAL_PT_READ_D PT_READ_D) + set(PAL_PT_WRITE_D PT_WRITE_D) + set(HAS_FTRUNCATE_LENGTH_ISSUE 1) + set(HAVE_SCHED_OTHER_ASSIGNABLE 1) +elseif(CLR_CMAKE_TARGET_OSX) set(HAVE__NSGETENVIRON 1) set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1) set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))") @@ -1331,7 +1341,6 @@ if(CLR_CMAKE_TARGET_OSX) set(PAL_PT_WRITE_D PT_WRITE_D) set(HAS_FTRUNCATE_LENGTH_ISSUE 1) set(HAVE_SCHED_OTHER_ASSIGNABLE 1) - elseif(CLR_CMAKE_TARGET_FREEBSD) set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0) set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))") @@ -1374,7 +1383,7 @@ else() # Anything else is Linux set(PAL_PT_WRITE_D PTRACE_POKEDATA) set(HAS_FTRUNCATE_LENGTH_ISSUE 0) set(HAVE_SCHED_OTHER_ASSIGNABLE 1) -endif(CLR_CMAKE_TARGET_OSX) +endif(CLR_CMAKE_TARGET_MACCATALYST) check_struct_has_member( "struct statfs" diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index cea55e86e2538f..a9e72f6820d801 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -1760,7 +1760,7 @@ VirtualProtect( return bRetVal; } -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(TARGET_MACCATALYST) bool PAL_JITWriteEnableHolder::JITWriteEnable(bool writeEnable) { @@ -1777,6 +1777,14 @@ PAL_JITWriteEnableHolder::JITWriteEnable(bool writeEnable) } #endif +#if defined(HOST_ARM64) && defined(TARGET_MACCATALYST) +bool +PAL_JITWriteEnableHolder::JITWriteEnable(bool writeEnable) +{ + return false; +} +#endif + #if HAVE_VM_ALLOCATE //--------------------------------------------------------------------------------------- // diff --git a/src/coreclr/pal/src/misc/dbgmsg.cpp b/src/coreclr/pal/src/misc/dbgmsg.cpp index a41d2d1036b47d..7d01d12953708c 100644 --- a/src/coreclr/pal/src/misc/dbgmsg.cpp +++ b/src/coreclr/pal/src/misc/dbgmsg.cpp @@ -821,6 +821,7 @@ void PAL_DisplayDialog(const char *szTitle, const char *szText) if (cfsText != NULL) { CFOptionFlags response; +#if !defined(TARGET_MACCATALYST) CFUserNotificationDisplayAlert(0, // Never time-out, wait for user to hit 'OK' 0, // No flags NULL, // Default icon @@ -832,6 +833,7 @@ void PAL_DisplayDialog(const char *szTitle, const char *szText) NULL, // No alternate button NULL, // No third button &response); // User's response (discarded) +#endif CFRelease(cfsText); } CFRelease(cfsTitle); diff --git a/src/coreclr/pal/src/misc/msgbox.cpp b/src/coreclr/pal/src/misc/msgbox.cpp index 9a76cc8b5c8cb5..70e472ab46da61 100644 --- a/src/coreclr/pal/src/misc/msgbox.cpp +++ b/src/coreclr/pal/src/misc/msgbox.cpp @@ -311,7 +311,9 @@ MessageBoxA( cfsButton1 = CFSTR("Abort"); cfsButton2 = CFSTR("Retry"); cfsButton3 = CFSTR("Ignore"); +#if !defined(TARGET_MACCATALYST) alertFlags = kCFUserNotificationCautionAlertLevel; +#endif break; case MB_YESNO: @@ -330,6 +332,7 @@ MessageBoxA( break; } +#if !defined(TARGET_MACCATALYST) CFUserNotificationDisplayAlert(0 /* no time out */, alertFlags, NULL /* iconURL */, NULL /* soundURL */, NULL /* localizationURL */, cfsTitle, cfsText, cfsButton1, cfsButton2, cfsButton3, &response); @@ -390,8 +393,10 @@ MessageBoxA( } break; } +#endif } else + { // We're not in a login session, e.g., running via ssh, and so bringing // up a message box would be bad form. diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj index ab62ea2c383ada..bf4c643069305f 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj @@ -81,7 +81,7 @@ runtimes/$(RuntimeIdentifier)/native/cross/%(RecursiveDir) runtimes/$(RuntimeIdentifier)/native/include/%(RecursiveDir) diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index 8ebce76af457da..35f96dc321e60b 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -253,7 +253,9 @@ add_subdirectory(System.Native) if(CLR_CMAKE_TARGET_BROWSER) # skip for now elseif(CLR_CMAKE_TARGET_MACCATALYST) + add_subdirectory(System.Globalization.Native) add_subdirectory(System.Net.Security.Native) + add_subdirectory(System.Security.Cryptography.Native) # System.Security.Cryptography.Native is intentionally disabled on iOS # it is only used for interacting with OpenSSL which isn't useful there elseif(CLR_CMAKE_TARGET_IOS) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt index 148197a6b9258a..103eb310ef86e8 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt @@ -69,7 +69,7 @@ if (NOT CLR_CMAKE_TARGET_BROWSER) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) endif() -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} entrypoints.c) endif() diff --git a/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt index 6fbe18f76872ef..569a01d286475f 100644 --- a/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt @@ -11,6 +11,10 @@ set(NATIVEGSS_SOURCES pal_gssapi.c ) +if (CLR_CMAKE_TARGET_MACCATALYST) + add_definitions(-DTARGET_MACCATALYST) +endif() + if (GEN_SHARED_LIB) add_library(System.Net.Security.Native SHARED @@ -19,7 +23,7 @@ if (GEN_SHARED_LIB) ) endif() -if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) set(NATIVEGSS_SOURCES ${NATIVEGSS_SOURCES} entrypoints.c) endif() @@ -35,7 +39,7 @@ if (GEN_SHARED_LIB) ${NATIVE_LIBS_EXTRA} ) - if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) + if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER) add_custom_command(TARGET System.Net.Security.Native POST_BUILD COMMENT "Verifying System.Net.Security.Native entry points against entrypoints.c " COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-entrypoints.sh diff --git a/src/libraries/externals.csproj b/src/libraries/externals.csproj index daf84fb3ae2d39..ca8e2c5b39c271 100644 --- a/src/libraries/externals.csproj +++ b/src/libraries/externals.csproj @@ -86,7 +86,7 @@ - diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index d326ebfae53103..35e3f510b732df 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -25,7 +25,7 @@ '$(Scenario)' == 'gcstress0xc_jitstress1' or '$(Scenario)' == 'gcstress0xc_jitstress2' or '$(Scenario)' == 'gcstress0xc_jitminopts_heapverify1'">01:30:00 - <_workItemTimeout Condition="'$(_workItemTimeout)' == '' and ('$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator' or '$(TargetOS)' == 'Android')">00:30:00 + <_workItemTimeout Condition="'$(_workItemTimeout)' == '' and ('$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator' or '$(TargetOS)' == 'MacCatalyst' or '$(TargetOS)' == 'Android')">00:30:00 <_workItemTimeout Condition="'$(Scenario)' == '' and '$(_workItemTimeout)' == '' and ('$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm')">00:45:00 <_workItemTimeout Condition="'$(Scenario)' != '' and '$(_workItemTimeout)' == '' and ('$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm')">01:00:00 <_workItemTimeout Condition="'$(Scenario)' == 'BuildWasmApps' and '$(_workItemTimeout)' == ''">01:00:00 @@ -70,7 +70,7 @@ test/functional/packaging/ - + true @@ -164,6 +164,14 @@ + + + maccatalyst + $(_workItemTimeout) + $(_workItemTimeout) + + + ios-device @@ -211,20 +219,21 @@ - + ios-simulator-64 tvos-simulator ios-device tvos-device + maccatalyst - + $(AppleTestTarget) - + false @@ -277,7 +286,7 @@ - + @@ -315,8 +324,8 @@ - - + + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 89e3e91d508e50..ff89f0f6a8134b 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -79,7 +79,7 @@ - + diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 580d61cf70fb98..4ebe9647814584 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -73,7 +73,7 @@ TargetOS="$(TargetOS)" Arch="$(TargetArchitecture)" ProjectName="HelloiOS" - MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackDir)native\include\mono-2.0" + RuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackDir)native\include\mono-2.0" Assemblies="@(BundleAssemblies)" MainLibraryFileName="Program.dll" GenerateXcodeProject="True" diff --git a/src/mono/sample/mbr/apple/AppleDelta.csproj b/src/mono/sample/mbr/apple/AppleDelta.csproj index 2b040dab21f005..993666733c33db 100644 --- a/src/mono/sample/mbr/apple/AppleDelta.csproj +++ b/src/mono/sample/mbr/apple/AppleDelta.csproj @@ -63,7 +63,7 @@ TargetOS="$(TargetOS)" Arch="$(TargetArchitecture)" ProjectName="AppleDelta" - MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackDir)native\include\mono-2.0" + RuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackDir)native\include\mono-2.0" Assemblies="@(BundleAssemblies)" NativeMainSource="$(MSBuildThisFileDirectory)\main.m" MainLibraryFileName="AppleDelta.dll" diff --git a/src/native/corehost/CMakeLists.txt b/src/native/corehost/CMakeLists.txt index d7784410ed03d1..b92417bae0e2cf 100644 --- a/src/native/corehost/CMakeLists.txt +++ b/src/native/corehost/CMakeLists.txt @@ -27,7 +27,7 @@ add_subdirectory(hostcommon) add_subdirectory(fxr) add_subdirectory(hostpolicy) -if (NOT RUNTIME_FLAVOR STREQUAL Mono) +if ((NOT RUNTIME_FLAVOR STREQUAL Mono) AND (NOT CLR_CMAKE_TARGET_MACCATALYST)) add_subdirectory(apphost) add_subdirectory(dotnet) add_subdirectory(nethost) diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 2b9a953e28d533..5628d3aaca43a8 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -70,10 +70,12 @@ namespace return SecurityResolveDllImport(entrypointName); } +#if !defined(TARGET_MACCATALYST) if (strcmp(libraryName, "libSystem.Native") == 0) { return SystemResolveDllImport(entrypointName); } +#endif if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.OpenSsl") == 0) { @@ -81,7 +83,7 @@ namespace } #endif -#if defined(TARGET_OSX) +#if defined(TARGET_OSX) && !defined(TARGET_MACCATALYST) if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.Apple") == 0) { return CryptoAppleResolveDllImport(entrypointName); diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 85efde52b045fa..7007bc39c8f9d2 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -44,10 +44,10 @@ public string TargetOS public string AppDir { get; set; } = ""!; /// - /// Path to Mono public headers (*.h) + /// Path to public headers (*.h) /// [Required] - public string MonoRuntimeHeaders { get; set; } = ""!; + public string RuntimeHeaders { get; set; } = ""!; /// /// This library will be used as an entry-point (e.g. TestRunner.dll) @@ -146,6 +146,11 @@ public string TargetOS /// public bool EnableRuntimeLogging { get; set; } + /// + /// Specifies whether to try and use Mono or CoreCLR runtime + /// + public string? RuntimeFlavor { get; set; } + public override bool Execute() { Utils.Logger = Log; @@ -204,7 +209,7 @@ public override bool Execute() generator.EnableRuntimeLogging = EnableRuntimeLogging; XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, - AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, StaticLinkedComponentNames, NativeMainSource); + AppDir, binDir, RuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, StaticLinkedComponentNames, NativeMainSource, RuntimeFlavor); if (BuildAppBundle) { diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index e7eeb4de247a88..de20f928456981 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -11,7 +11,7 @@ add_executable( %ProjectName% %MainSource% runtime.h - runtime.m + %RuntimeDotM% %AotModulesSource% ${APP_RESOURCES} ) @@ -20,7 +20,7 @@ add_executable( %Defines% -include_directories("%MonoInclude%") +include_directories("%RuntimeInclude%") set_target_properties(%ProjectName% PROPERTIES MACOSX_BUNDLE TRUE @@ -35,6 +35,10 @@ set(HARDENED_RUNTIME %HardenedRuntime% ) +set(RPATH_RESOURCES +%RpathResources% +) + set(HARDENED_RUNTIME_USE_ENTITLEMENTS_FILE %HardenedRuntimeUseEntitlementsFile% ) @@ -46,6 +50,12 @@ if("${HARDENED_RUNTIME}") endif() endif() + +if("${RPATH_RESOURCES}") + set_target_properties(%ProjectName% PROPERTIES XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/../Resources") +endif() + + # FIXME: `XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING` should not be NO target_link_libraries( diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m new file mode 100644 index 00000000000000..dbdaa59095e42c --- /dev/null +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -0,0 +1,164 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#import +#include +#include +#import +#include +#include +#include +#include +#include + +static char *bundle_path; +static char *tpa_list; + +#define APPLE_RUNTIME_IDENTIFIER "//%APPLE_RUNTIME_IDENTIFIER%" + +const char * +get_bundle_path (void) +{ + if (bundle_path) + return bundle_path; + NSBundle* main_bundle = [NSBundle mainBundle]; + NSString* path = [main_bundle bundlePath]; + +#if TARGET_OS_MACCATALYST + path = [path stringByAppendingString:@"/Contents/Resources"]; +#endif + + bundle_path = strdup ([path UTF8String]); + + return bundle_path; +} + +const char * +get_tpa_list (const char *bundle) +{ + if (tpa_list) + return tpa_list; + NSString *path = @(bundle_path); + NSArray *dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL]; + NSMutableArray *assemblies = [[NSMutableArray alloc] init]; + [dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + NSString *filename = (NSString *)obj; + NSString *extension = [[filename pathExtension] lowercaseString]; + if ([extension isEqualToString:@"dll"]) { + [assemblies addObject:[path stringByAppendingPathComponent:filename]]; + } + }]; + + NSString *ns_tpa_list = [assemblies componentsJoinedByString:@":"]; + tpa_list = strdup ([ns_tpa_list UTF8String]); + + return tpa_list; +} + +char * +strdup_printf (const char *msg, ...) +{ + va_list args; + char *formatted = NULL; + va_start (args, msg); + vasprintf (&formatted, msg, args); + va_end (args); + return formatted; +} + +void +log_callback (const char *log_domain, const char *log_level, const char *message, bool fatal, void *user_data) +{ + os_log_info (OS_LOG_DEFAULT, "(%s %s) %s", log_domain, log_level, message); + if (fatal) { + os_log_info (OS_LOG_DEFAULT, "Exit code: %d.", 1); + exit (1); + } +} + +void * +pinvoke_override (const char *libraryName, const char *entrypointName) +{ + void *symbol = NULL; + + if (strcmp (libraryName, "__Internal") == 0) { + symbol = dlsym (RTLD_DEFAULT, entrypointName); + } + return symbol; +} + +void +mono_ios_runtime_init (void) +{ +#if INVARIANT_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); +#endif + + id args_array = [[NSProcessInfo processInfo] arguments]; + assert ([args_array count] <= 128); + const char *managed_argv [128]; + int argi; + for (argi = 0; argi < [args_array count]; argi++) { + NSString* arg = [args_array objectAtIndex: argi]; + managed_argv[argi] = [arg UTF8String]; + } + + const char* bundle = get_bundle_path (); + chdir (bundle); + + const char* tpa = get_tpa_list (bundle); + + char icu_dat_path [1024]; + int res; + + res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt.dat"); + assert (res > 0); + + char *pinvokeOverride = strdup_printf ("%p", &pinvoke_override); + + void* hostHandle; + unsigned int domainId; + const char* propertyKeys[] = { + "PINVOKE_OVERRIDE", + "TRUSTED_PLATFORM_ASSEMBLIES", + "RUNTIME_IDENTIFIER", + "APP_CONTEXT_BASE_DIRECTORY", +#if !defined(INVARIANT_GLOBALIZATION) && !TARGET_OS_MACCATALYST + "ICU_DAT_FILE_PATH" +#endif + }; + const char* propertyValues[] = { + pinvokeOverride, + tpa, + APPLE_RUNTIME_IDENTIFIER, + bundle, +#if !defined(INVARIANT_GLOBALIZATION) && !TARGET_OS_MACCATALYST + icu_dat_path +#endif + }; + + coreclr_initialize ( + bundle, + APPLE_RUNTIME_IDENTIFIER, + sizeof(propertyKeys) / sizeof(char*), + propertyKeys, + propertyValues, + &hostHandle, + &domainId); + + const char* executable = "%EntryPointLibName%"; + + coreclr_execute_assembly ( + hostHandle, + domainId, + argi, + managed_argv, + executable, + (unsigned int*)&res); + os_log_info (OS_LOG_DEFAULT, "Executable: %s", executable); + + // Print this so apps parsing logs can detect when we exited + os_log_info (OS_LOG_DEFAULT, "Exit code: %d.", res); + + exit (res); +} diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index a414d47a9bb607..bbc81df7323dd6 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -46,7 +46,7 @@ public string GenerateXCode( IEnumerable asmFiles, string workspace, string binDir, - string monoInclude, + string runtimeInclude, bool preferDylibs, bool useConsoleUiTemplate, bool forceAOT, @@ -54,10 +54,12 @@ public string GenerateXCode( bool invariantGlobalization, bool stripDebugSymbols, string? staticLinkedComponentNames=null, - string? nativeMainSource = null) + string? nativeMainSource = null, + string? runtimeFlavor = "mono") { + var runtimedotm = "coreclr".Equals(runtimeFlavor, StringComparison.OrdinalIgnoreCase) ? "runtime-coreclr.m" : "runtime.m"; // bundle everything as resources excluding native files - var excludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib" }; + var excludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib" }; if (stripDebugSymbols) { excludes.Add(".pdb"); @@ -100,8 +102,9 @@ public string GenerateXCode( .Replace("%ProjectName%", projectName) .Replace("%AppResources%", string.Join(Environment.NewLine, resources.Select(r => " " + r))) .Replace("%MainSource%", nativeMainSource) - .Replace("%MonoInclude%", monoInclude) - .Replace("%HardenedRuntime%", hardenedRuntime ? "TRUE" : "FALSE"); + .Replace("%RuntimeInclude%", runtimeInclude) + .Replace("%HardenedRuntime%", hardenedRuntime ? "TRUE" : "FALSE") + .Replace("%RuntimeDotM%", runtimedotm); string toLink = ""; @@ -167,6 +170,12 @@ public string GenerateXCode( } } + if ("coreclr".Equals(runtimeFlavor, StringComparison.OrdinalIgnoreCase)) + { + var libcoreclrpath = Array.Find (dylibs, element => element.EndsWith("libcoreclr.dylib")); + toLink += $" \"{libcoreclrpath}\"{Environment.NewLine}"; + } + string aotSources = ""; foreach (string asm in asmFiles) { @@ -186,6 +195,7 @@ public string GenerateXCode( cmakeLists = cmakeLists.Replace("%NativeLibrariesToLink%", toLink); cmakeLists = cmakeLists.Replace("%AotSources%", aotSources); cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); + cmakeLists = cmakeLists.Replace("%RpathResources%", "coreclr".Equals(runtimeFlavor, StringComparison.OrdinalIgnoreCase) ? "TRUE" : "FALSE"); var defines = new StringBuilder(); if (forceInterpreter) @@ -274,8 +284,8 @@ public string GenerateXCode( dllMap.AppendLine($" mono_dllmap_insert (NULL, \"System.Globalization.Native\", NULL, \"__Internal\", NULL);"); - File.WriteAllText(Path.Combine(binDir, "runtime.m"), - Utils.GetEmbeddedResource("runtime.m") + File.WriteAllText(Path.Combine(binDir, runtimedotm), + Utils.GetEmbeddedResource(runtimedotm) .Replace("//%DllMap%", dllMap.ToString()) .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier) .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));