diff --git a/docs/workflow/building/coreclr/ios.md b/docs/workflow/building/coreclr/ios.md new file mode 100644 index 00000000000000..9061fd17da438c --- /dev/null +++ b/docs/workflow/building/coreclr/ios.md @@ -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. \ No newline at end of file diff --git a/eng/Subsets.props b/eng/Subsets.props index 41f63f11bbd795..656ca0c08568bd 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -55,8 +55,8 @@ - Mono - CoreCLR + CoreCLR + Mono Mono $(PrimaryRuntimeFlavor) @@ -65,7 +65,7 @@ clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools+host.native clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools - clr.iltools+clr.packages + clr.iltools+clr.packages clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime diff --git a/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj b/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj index b2945e29260152..0480327017db55 100644 --- a/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj +++ b/src/coreclr/.nuget/ILCompiler.Reflection.ReadyToRun.Experimental/ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj @@ -11,7 +11,7 @@ - + \lib\netstandard2.0\ diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 7ed0d509212cc4..0b358c8ca08a4b 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -29,7 +29,7 @@ if(CORECLR_SET_RPATH) set(MACOSX_RPATH ON) endif(CORECLR_SET_RPATH) -if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS) +if(CLR_CMAKE_HOST_TVOS) set(FEATURE_STANDALONE_GC 0) endif() @@ -101,8 +101,10 @@ if(CLR_CMAKE_HOST_UNIX) add_linker_flag(-Wl,-z,notext) endif() - if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) + if(NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(pal) + endif() + if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(hosts) endif() else() @@ -125,7 +127,7 @@ add_subdirectory(pal/prebuilt/inc) set(EP_GENERATED_HEADER_PATH "${GENERATED_INCLUDE_DIR}") include (${CLR_SRC_NATIVE_DIR}/eventpipe/configure.cmake) -if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +if(NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(debug/debug-pal) endif() @@ -242,12 +244,12 @@ if(CLR_CMAKE_HOST_UNIX) add_subdirectory(nativeresources) endif(CLR_CMAKE_HOST_UNIX) -if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +if(NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(utilcode) add_subdirectory(inc) if(CLR_CMAKE_HOST_UNIX) - add_subdirectory(palrt) + add_subdirectory(palrt) endif(CLR_CMAKE_HOST_UNIX) add_subdirectory(ilasm) @@ -260,15 +262,18 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H add_subdirectory(binder) add_subdirectory(classlibnative) add_subdirectory(dlls) - add_subdirectory(tools) add_subdirectory(unwinder) add_subdirectory(interop) +endif() - if(CLR_CMAKE_HOST_WIN32) - add_subdirectory(hosts) - endif(CLR_CMAKE_HOST_WIN32) +if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) + add_subdirectory(tools) endif(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +if(CLR_CMAKE_HOST_WIN32) + add_subdirectory(hosts) +endif(CLR_CMAKE_HOST_WIN32) + #---------------------------------------------------- # Cross target Component install configuration #---------------------------------------------------- diff --git a/src/coreclr/debug/daccess/CMakeLists.txt b/src/coreclr/debug/daccess/CMakeLists.txt index 9ed71521d4283d..fa26f55cc37fa2 100644 --- a/src/coreclr/debug/daccess/CMakeLists.txt +++ b/src/coreclr/debug/daccess/CMakeLists.txt @@ -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) add_definitions(-DUSE_DAC_TABLE_RVA) - set(args $<$>:--dynamic> $ ${GENERATED_INCLUDE_DIR}/dactablerva.h) + set(args $<$>:--dynamic> $ ${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) diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt index f031e3fc4b60f7..13584c5cf5d657 100644 --- a/src/coreclr/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/dlls/mscordac/CMakeLists.txt @@ -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) set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index 7ba58d0297f9a9..3c481c1cc03181 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -221,6 +221,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) +endif() # Enable profile guided optimization add_pgo(coreclr) diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 01eeac600a2240..2988ea0452acfd 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -19,9 +19,15 @@ // 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) +#ifdef __cplusplus #define CORECLR_HOSTING_API(function, ...) \ extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) +#else +#define CORECLR_HOSTING_API(function, ...) \ + int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ + typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) +#endif // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index aeb061ca5ba479..df24acc83afbd0 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -686,9 +686,9 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #if defined(TARGET_OSX) && defined(TARGET_X86) #define DAC_CS_NATIVE_DATA_SIZE 76 -#elif defined(TARGET_OSX) && defined(TARGET_AMD64) +#elif defined(TARGET_APPLE) && defined(TARGET_AMD64) #define DAC_CS_NATIVE_DATA_SIZE 120 -#elif defined(TARGET_OSX) && defined(TARGET_ARM64) +#elif defined(TARGET_APPLE) && defined(TARGET_ARM64) #define DAC_CS_NATIVE_DATA_SIZE 120 #elif defined(TARGET_FREEBSD) && defined(TARGET_X86) #define DAC_CS_NATIVE_DATA_SIZE 12 diff --git a/src/coreclr/inc/executableallocator.h b/src/coreclr/inc/executableallocator.h index 5b9c0d81dc5a2b..11caf3a6857d2d 100644 --- a/src/coreclr/inc/executableallocator.h +++ b/src/coreclr/inc/executableallocator.h @@ -285,7 +285,7 @@ class ExecutableWriterHolder void Unmap() { -#if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE) +#if defined(HOST_APPLE) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE) if (m_addressRX != NULL) { PAL_JitWriteProtect(false); @@ -321,7 +321,7 @@ class ExecutableWriterHolder ExecutableWriterHolder(T* addressRX, size_t size, ExecutableAllocator::CacheableMapping cacheMapping = ExecutableAllocator::AddToCache) { m_addressRX = addressRX; -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) m_addressRW = addressRX; PAL_JitWriteProtect(true); #else diff --git a/src/coreclr/inc/targetosarch.h b/src/coreclr/inc/targetosarch.h index 06f22d8ee487b0..00fe5b70647e7d 100644 --- a/src/coreclr/inc/targetosarch.h +++ b/src/coreclr/inc/targetosarch.h @@ -22,7 +22,7 @@ class TargetOS static bool OSSettingConfigured; static bool IsApplePlatform; #else -#if defined(TARGET_OSX) +#if defined(TARGET_APPLE) static const bool IsApplePlatform = true; #else static const bool IsApplePlatform = false; diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index 766a0a0150e873..067039a1a67abc 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -626,7 +626,7 @@ set(JIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Creates a static library "clrjit_static" to link into the VM. add_subdirectory(static) -if (CLR_CMAKE_TARGET_OSX) +if (CLR_CMAKE_TARGET_APPLE) set(TARGET_OS_NAME unix_osx) elseif (CLR_CMAKE_TARGET_UNIX) set(TARGET_OS_NAME unix) diff --git a/src/coreclr/minipal/Unix/doublemapping.cpp b/src/coreclr/minipal/Unix/doublemapping.cpp index cb65e5e284e2b3..70090d2f5465e6 100644 --- a/src/coreclr/minipal/Unix/doublemapping.cpp +++ b/src/coreclr/minipal/Unix/doublemapping.cpp @@ -21,7 +21,7 @@ #endif // TARGET_LINUX && !MFD_CLOEXEC #include "minipal.h" -#if defined(TARGET_OSX) && defined(TARGET_AMD64) +#if defined(TARGET_APPLE) && defined(TARGET_AMD64) #include #include @@ -35,9 +35,9 @@ bool IsProcessTranslated() } return ret == 1; } -#endif // TARGET_OSX && TARGET_AMD64 +#endif // TARGET_APPLE && TARGET_AMD64 -#ifndef TARGET_OSX +#ifndef TARGET_APPLE #ifdef TARGET_64BIT static const off_t MaxDoubleMappedSize = 2048ULL*1024*1024*1024; @@ -45,11 +45,11 @@ static const off_t MaxDoubleMappedSize = 2048ULL*1024*1024*1024; static const off_t MaxDoubleMappedSize = UINT_MAX; #endif -#endif // TARGET_OSX +#endif // TARGET_APPLE bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecutableCodeSize) { -#ifndef TARGET_OSX +#ifndef TARGET_APPLE #ifdef TARGET_FREEBSD int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU); @@ -76,7 +76,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu *pMaxExecutableCodeSize = MaxDoubleMappedSize; *pHandle = (void*)(size_t)fd; -#else // !TARGET_OSX +#else // !TARGET_APPLE #ifdef TARGET_AMD64 if (IsProcessTranslated()) @@ -88,21 +88,21 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu *pMaxExecutableCodeSize = SIZE_MAX; *pHandle = NULL; -#endif // !TARGET_OSX +#endif // !TARGET_APPLE return true; } void VMToOSInterface::DestroyDoubleMemoryMapper(void *mapperHandle) { -#ifndef TARGET_OSX +#ifndef TARGET_APPLE close((int)(size_t)mapperHandle); #endif } extern "C" void* PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(const void* lpBeginAddress, const void* lpEndAddress, size_t dwSize, int fStoreAllocationInfo); -#ifdef TARGET_OSX +#ifdef TARGET_APPLE bool IsMapJitFlagNeeded() { static volatile int isMapJitFlagNeeded = -1; @@ -133,7 +133,7 @@ bool IsMapJitFlagNeeded() return (bool)isMapJitFlagNeeded; } -#endif // TARGET_OSX +#endif // TARGET_APPLE void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offset, size_t size, const void *rangeStart, const void* rangeEnd) { @@ -147,7 +147,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs } void* result = PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange(rangeStart, rangeEnd, size, 0 /* fStoreAllocationInfo */); -#ifndef TARGET_OSX +#ifndef TARGET_APPLE if (result != NULL) { // Map the shared memory over the range reserved from the executable memory allocator. @@ -158,7 +158,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs result = NULL; } } -#endif // TARGET_OSX +#endif // TARGET_APPLE // For requests with limited range, don't try to fall back to reserving at any address if ((result != NULL) || !isUnlimitedRange) @@ -166,7 +166,7 @@ void* VMToOSInterface::ReserveDoubleMappedMemory(void *mapperHandle, size_t offs return result; } -#ifndef TARGET_OSX +#ifndef TARGET_APPLE result = mmap(NULL, size, PROT_NONE, MAP_SHARED, fd, offset); #else int mmapFlags = MAP_ANON | MAP_PRIVATE; @@ -196,20 +196,20 @@ void *VMToOSInterface::CommitDoubleMappedMemory(void* pStart, size_t size, bool bool VMToOSInterface::ReleaseDoubleMappedMemory(void *mapperHandle, void* pStart, size_t offset, size_t size) { -#ifndef TARGET_OSX +#ifndef TARGET_APPLE int fd = (int)(size_t)mapperHandle; if (mmap(pStart, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset) == MAP_FAILED) { return false; } memset(pStart, 0, size); -#endif // TARGET_OSX +#endif // TARGET_APPLE return munmap(pStart, size) != -1; } void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t offset, size_t size) { -#ifndef TARGET_OSX +#ifndef TARGET_APPLE int fd = (int)(size_t)mapperHandle; void* result = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); if (result == MAP_FAILED) @@ -217,7 +217,7 @@ void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t off result = NULL; } return result; -#else // TARGET_OSX +#else // TARGET_APPLE #ifdef TARGET_AMD64 vm_address_t startRW; vm_prot_t curProtection, maxProtection; @@ -242,7 +242,7 @@ void* VMToOSInterface::GetRWMapping(void *mapperHandle, void* pStart, size_t off assert(false); return NULL; #endif // TARGET_AMD64 -#endif // TARGET_OSX +#endif // TARGET_APPLE } bool VMToOSInterface::ReleaseRWMapping(void* pStart, size_t size) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index c64cf8ee020adc..d271f7dc9e604e 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -2921,14 +2921,14 @@ VirtualFree( IN DWORD dwFreeType); -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) PALIMPORT VOID PALAPI PAL_JitWriteProtect(bool writeEnable); -#endif // defined(HOST_OSX) && defined(HOST_ARM64) +#endif // defined(HOST_APPLE) && defined(HOST_ARM64) PALIMPORT diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 2398334e899897..6631719af961d0 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -1,8 +1,8 @@ -if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU) +if(CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU) # On OSX and *BSD, we use the libunwind that's part of the OS # On Haiku, we used a special port of libunwind set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1) -endif(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU) +endif(CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_HAIKU) if(NOT DEFINED ENV{ROOTFS_DIR}) include_directories(SYSTEM /usr/local/include) @@ -17,7 +17,7 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) include_directories(${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind/include/tdep) add_subdirectory(${CLR_SRC_NATIVE_DIR}/external/libunwind_extras ${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind) -elseif(NOT CLR_CMAKE_TARGET_OSX) +elseif(NOT CLR_CMAKE_TARGET_APPLE) find_unwind_libs(UNWIND_LIBS) else() add_subdirectory(${CLR_SRC_NATIVE_DIR}/external/libunwind_extras ${CLR_ARTIFACTS_OBJ_DIR}/external/libunwind) @@ -70,13 +70,18 @@ if(CLR_CMAKE_TARGET_OSX) if(CLR_CMAKE_TARGET_ARCH_AMD64) add_definitions(-DXSTATE_SUPPORTED) endif() +endif() + +if(CLR_CMAKE_TARGET_APPLE) + add_definitions(-DTARGET_APPLE) + add_definitions(-D_XOPEN_SOURCE) set(PLATFORM_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/context.S arch/${PAL_ARCH_SOURCES_DIR}/dispatchexceptionwrapper.S exception/machexception.cpp exception/machmessage.cpp ) -endif(CLR_CMAKE_TARGET_OSX) +endif(CLR_CMAKE_TARGET_APPLE) if (FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION) add_definitions(-DFEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION) @@ -111,12 +116,12 @@ set(ARCH_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/exceptionhelper.S ) -if(NOT CLR_CMAKE_TARGET_OSX) +if(NOT CLR_CMAKE_TARGET_APPLE) list(APPEND PLATFORM_SOURCES arch/${PAL_ARCH_SOURCES_DIR}/callsignalhandlerwrapper.S arch/${PAL_ARCH_SOURCES_DIR}/signalhandlerhelper.cpp ) -endif(NOT CLR_CMAKE_TARGET_OSX) +endif(NOT CLR_CMAKE_TARGET_APPLE) if(CLR_CMAKE_HOST_ARCH_ARM) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -213,7 +218,7 @@ add_library(coreclrpal ) # Build separate pal library for DAC (addition to regular pal library) -if(CLR_CMAKE_TARGET_OSX) +if(CLR_CMAKE_TARGET_APPLE) set(LIBUNWIND_DAC_OBJECTS $) add_library(coreclrpal_dac STATIC @@ -235,7 +240,7 @@ else() exception/remote-unwind.cpp ) endif(NOT FEATURE_CROSSBITNESS) -endif(CLR_CMAKE_TARGET_OSX) +endif(CLR_CMAKE_TARGET_APPLE) # There is only one function exported in 'tracepointprovider.cpp' namely 'PAL_InitializeTracing', # which is guarded with '#if defined(__linux__)'. On macOS, Xcode issues the following warning: diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index ed730378074c3c..624ed59d8e765e 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_APPLE) 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") @@ -1002,7 +1002,7 @@ 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_APPLE) 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))") @@ -1066,7 +1066,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_APPLE) check_struct_has_member( "struct statfs" diff --git a/src/coreclr/pal/src/debug/debug.cpp b/src/coreclr/pal/src/debug/debug.cpp index b38810864a587f..6d022237f8821c 100644 --- a/src/coreclr/pal/src/debug/debug.cpp +++ b/src/coreclr/pal/src/debug/debug.cpp @@ -46,7 +46,9 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do #elif defined(HAVE_TTRACE) // HAVE_PROCFS_CTL #include #else // defined(HAVE_TTRACE) +#if !defined(TARGET_APPLE) || defined(TARGET_OSX) #include +#endif #endif // HAVE_PROCFS_CTL #if HAVE_VM_READ #include @@ -61,7 +63,9 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do #ifdef __APPLE__ #include +#if defined(TARGET_OSX) #include +#endif #endif // __APPLE__ #if HAVE_MACH_EXCEPTIONS diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index 5b12af8aa027bc..f5e56409b1462b 100644 --- a/src/coreclr/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/pal/src/exception/seh-unwind.cpp @@ -54,7 +54,7 @@ Module Name: #endif // HOST_UNIX -#if defined(TARGET_OSX) && defined(HOST_ARM64) && !defined(HAVE_UNW_AARCH64_X19) +#if defined(TARGET_APPLE) && defined(HOST_ARM64) && !defined(HAVE_UNW_AARCH64_X19) // MacOS uses ARM64 instead of AARCH64 to describe these registers // Create aliases to reuse more code enum @@ -270,7 +270,7 @@ static void WinContextToUnwindContext(CONTEXT *winContext, unw_context_t *unwCon { unwContext->fpregs[i] = winContext->D[i]; } -#elif defined(HOST_ARM64) && !defined(TARGET_OSX) +#elif defined(HOST_ARM64) && !defined(TARGET_APPLE) unwContext->uc_mcontext.pc = winContext->Pc; unwContext->uc_mcontext.sp = winContext->Sp; unwContext->uc_mcontext.regs[29] = winContext->Fp; @@ -312,7 +312,7 @@ static void WinContextToUnwindCursor(CONTEXT *winContext, unw_cursor_t *cursor) unw_set_reg(cursor, UNW_X86_EBX, winContext->Ebx); unw_set_reg(cursor, UNW_X86_ESI, winContext->Esi); unw_set_reg(cursor, UNW_X86_EDI, winContext->Edi); -#elif defined(HOST_ARM64) && defined(TARGET_OSX) +#elif defined(HOST_ARM64) && defined(TARGET_APPLE) // unw_cursor_t is an opaque data structure on macOS // As noted in WinContextToUnwindContext this didn't work for Linux // TBD whether this will work for macOS. @@ -436,12 +436,12 @@ void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext) unw_get_fpreg(cursor, UNW_AARCH64_V30, (unw_fpreg_t*)&winContext->V[30].Low); unw_get_fpreg(cursor, UNW_AARCH64_V31, (unw_fpreg_t*)&winContext->V[31].Low); -#if defined(TARGET_OSX) && defined(TARGET_ARM64) +#if defined(TARGET_APPLE) && defined(TARGET_ARM64) // Strip pointer authentication bits which seem to be leaking out of libunwind // Seems like ptrauth_strip() / __builtin_ptrauth_strip() should work, but currently // errors with "this target does not support pointer authentication" winContext->Pc = winContext->Pc & 0x7fffffffffffull; -#endif // defined(TARGET_OSX) && defined(TARGET_ARM64) +#endif // defined(TARGET_APPLE) && defined(TARGET_ARM64) #elif (defined(HOST_UNIX) && defined(HOST_S390X)) unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->R15); unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->PSWAddr); diff --git a/src/coreclr/pal/src/include/pal/context.h b/src/coreclr/pal/src/include/pal/context.h index 6eeeaa6fed7453..e802a61a4158d4 100644 --- a/src/coreclr/pal/src/include/pal/context.h +++ b/src/coreclr/pal/src/include/pal/context.h @@ -624,7 +624,7 @@ const struct fpregs* GetConstNativeSigSimdContext(const native_context_t *mc) return GetNativeSigSimdContext(const_cast(mc)); } -#elif !defined(TARGET_OSX) // TARGET_FREEBSD +#elif !defined(TARGET_APPLE) // TARGET_FREEBSD #define MCREG_X0(mc) ((mc).regs[0]) #define MCREG_X1(mc) ((mc).regs[1]) @@ -699,7 +699,7 @@ const fpsimd_context* GetConstNativeSigSimdContext(const native_context_t *mc) return GetNativeSigSimdContext(const_cast(mc)); } -#else // TARGET_OSX +#else // TARGET_APPLE #define MCREG_X0(mc) ((mc)->__ss.__x[0]) #define MCREG_X1(mc) ((mc)->__ss.__x[1]) @@ -749,7 +749,7 @@ const _STRUCT_ARM_NEON_STATE64* GetConstNativeSigSimdContext(const native_contex return GetNativeSigSimdContext(const_cast(mc)); } -#endif // TARGET_OSX +#endif // TARGET_APPLE #elif defined(HOST_LOONGARCH64) @@ -789,7 +789,7 @@ const _STRUCT_ARM_NEON_STATE64* GetConstNativeSigSimdContext(const native_contex #else // HOST_ARM64 -#ifdef TARGET_OSX +#ifdef TARGET_APPLE #define MCREG_Rbp(mc) ((mc)->__ss.__rbp) #define MCREG_Rip(mc) ((mc)->__ss.__rip) @@ -874,7 +874,7 @@ inline void *FPREG_Xstate_Hi16Zmm(const ucontext_t *uc, uint32_t *featureSize) *featureSize = sizeof(_STRUCT_ZMM_REG) * 16; return reinterpret_cast(&((_STRUCT_X86_AVX512_STATE64&)FPSTATE(uc)).__fpu_zmm16); } -#else //TARGET_OSX +#else //TARGET_APPLE // For FreeBSD, as found in x86/ucontext.h #define MCREG_Rbp(mc) ((mc).mc_rbp) @@ -911,7 +911,7 @@ inline void *FPREG_Xstate_Hi16Zmm(const ucontext_t *uc, uint32_t *featureSize) #define FPREG_Xmm(uc, index) *(M128A*) &(FPSTATE(uc)->sv_xmm[index]) #define FPREG_St(uc, index) *(M128A*) &(FPSTATE(uc)->sv_fp[index].fp_acc) -#endif // TARGET_OSX +#endif // TARGET_APPLE #endif // HOST_ARM64 #else // HOST_64BIT diff --git a/src/coreclr/pal/src/include/pal/dbgmsg.h b/src/coreclr/pal/src/include/pal/dbgmsg.h index ca8d1454de9143..0d0c5e4aed4cee 100644 --- a/src/coreclr/pal/src/include/pal/dbgmsg.h +++ b/src/coreclr/pal/src/include/pal/dbgmsg.h @@ -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 /*++ Function : PAL_DisplayDialog @@ -514,10 +514,10 @@ Function : --*/ void PAL_DisplayDialogFormatted(const char *szTitle, const char *szTextFormat, ...); -#else // __APPLE__ +#else // TARGET_OSX #define PAL_DisplayDialog(_szTitle, _szText) #define PAL_DisplayDialogFormatted(_szTitle, _szTextFormat, args...) -#endif // __APPLE__ +#endif // TARGET_OSX #ifdef __cplusplus } diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index 3145faac5f5056..6947266f55dfcf 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -40,12 +40,17 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d #include #include #include +#include #if HAVE_VM_ALLOCATE #include #include #endif // HAVE_VM_ALLOCATE +#if defined(TARGET_APPLE) && !defined(TARGET_OSX) +#include +#endif + using namespace CorUnix; CRITICAL_SECTION virtual_critsec; @@ -1231,7 +1236,30 @@ VirtualProtect( return bRetVal; } -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) + +#if defined(TARGET_APPLE) && !defined(TARGET_OSX) + +void +(*jit_write_protect_np)(int enabled); + +static struct jit_write_protect_helper +{ + jit_write_protect_helper() + { + jit_write_protect_np = (void (*)(int))dlsym(RTLD_DEFAULT, "pthread_jit_write_protect_np"); + if (jit_write_protect_np == NULL) + { + ERROR( "pthread_jit_write_protect_np not available.\n" ); + exit(1); + } + } +} jit_write_protect_helper; + +#define pthread_jit_write_protect_np jit_write_protect_np + +#endif + PALAPI VOID PAL_JitWriteProtect(bool writeEnable) { thread_local int enabledCount = 0; diff --git a/src/coreclr/pal/src/misc/dbgmsg.cpp b/src/coreclr/pal/src/misc/dbgmsg.cpp index 38f101d147f67d..d49671dd571b00 100644 --- a/src/coreclr/pal/src/misc/dbgmsg.cpp +++ b/src/coreclr/pal/src/misc/dbgmsg.cpp @@ -734,7 +734,7 @@ bool DBG_ShouldCheckStackAlignment() } #endif // _DEBUG && __APPLE__ -#ifdef __APPLE__ +#if defined(TARGET_OSX) #include "CoreFoundation/CFUserNotification.h" #include "CoreFoundation/CFString.h" #include "Security/AuthSession.h" @@ -854,4 +854,4 @@ void PAL_DisplayDialogFormatted(const char *szTitle, const char *szTextFormat, . va_end(args); } -#endif // __APPLE__ +#endif // TARGET_OSX diff --git a/src/coreclr/pal/src/misc/sysinfo.cpp b/src/coreclr/pal/src/misc/sysinfo.cpp index d20fa7b2aabec1..450eed08ada19f 100644 --- a/src/coreclr/pal/src/misc/sysinfo.cpp +++ b/src/coreclr/pal/src/misc/sysinfo.cpp @@ -58,13 +58,14 @@ Revision History: #include #endif // HAVE_MACHINE_VMPARAM_H -#if defined(TARGET_OSX) +#if defined(TARGET_APPLE) #include #include #include #include -#endif // defined(TARGET_OSX) +#endif // defined(TARGET_APPLE) +#if !defined(TARGET_IOS) && !defined(TARGET_TVOS) // On some platforms sys/user.h ends up defining _DEBUG; if so // remove the definition before including the header and put // back our definition afterwards @@ -78,6 +79,7 @@ Revision History: #define _DEBUG OLD_DEBUG #undef OLD_DEBUG #endif +#endif // !TARGET_IOS && !TARGET_TVOS #include "pal/dbgmsg.h" #include "pal/process.h" @@ -211,6 +213,8 @@ GetSystemInfo( lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47); #elif defined(__sun) lpSystemInfo->lpMaximumApplicationAddress = (PVOID) 0xfffffd7fffe00000ul; +#elif defined(VM_MAX_PAGE_ADDRESS) + lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAX_PAGE_ADDRESS; #elif defined(USERLIMIT) lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT; #elif defined(HOST_64BIT) diff --git a/src/coreclr/pal/src/thread/context.cpp b/src/coreclr/pal/src/thread/context.cpp index 04fabab0e7253e..108b90a9a2bcf3 100644 --- a/src/coreclr/pal/src/thread/context.cpp +++ b/src/coreclr/pal/src/thread/context.cpp @@ -29,6 +29,9 @@ SET_DEFAULT_DEBUG_CHANNEL(THREAD); // some headers have code with asserts, so do #endif #include #include +#if defined(HOST_APPLE) && !defined(HOST_OSX) +#include +#endif extern PGET_GCMARKER_EXCEPTION_CODE g_getGcMarkerExceptionCode; @@ -688,7 +691,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) FPREG_Xmm(native, i) = lpContext->FltSave.XmmRegisters[i]; } #elif defined(HOST_ARM64) -#ifdef TARGET_OSX +#ifdef TARGET_APPLE _STRUCT_ARM_NEON_STATE64* fp = GetNativeSigSimdContext(native); fp->__fpsr = lpContext->Fpsr; fp->__fpcr = lpContext->Fpcr; @@ -707,7 +710,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) *(NEON128*) &fp->fp_q[i] = lpContext->V[i]; } } -#else // TARGET_OSX +#else // TARGET_APPLE fpsimd_context* fp = GetNativeSigSimdContext(native); if (fp) { @@ -718,7 +721,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) *(NEON128*) &fp->vregs[i] = lpContext->V[i]; } } -#endif // TARGET_OSX +#endif // TARGET_APPLE #elif defined(HOST_ARM) VfpSigFrame* fp = GetNativeSigSimdContext(native); if (fp) @@ -897,7 +900,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex lpContext->FltSave.XmmRegisters[i] = FPREG_Xmm(native, i); } #elif defined(HOST_ARM64) -#ifdef TARGET_OSX +#ifdef TARGET_APPLE const _STRUCT_ARM_NEON_STATE64* fp = GetConstNativeSigSimdContext(native); lpContext->Fpsr = fp->__fpsr; lpContext->Fpcr = fp->__fpcr; @@ -916,7 +919,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex lpContext->V[i] = *(NEON128*) &fp->fp_q[i]; } } -#else // TARGET_OSX +#else // TARGET_APPLE const fpsimd_context* fp = GetConstNativeSigSimdContext(native); if (fp) { @@ -927,7 +930,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex lpContext->V[i] = *(NEON128*) &fp->vregs[i]; } } -#endif // TARGET_OSX +#endif // TARGET_APPLE #elif defined(HOST_ARM) const VfpSigFrame* fp = GetConstNativeSigSimdContext(native); if (fp) @@ -1912,6 +1915,8 @@ DBG_FlushInstructionCache( #endif syscall(__NR_riscv_flush_icache, (char *)lpBaseAddress, (char *)((INT_PTR)lpBaseAddress + dwSize), 0 /* all harts */); +#elif defined(HOST_APPLE) && !defined(HOST_OSX) + sys_icache_invalidate((void *)lpBaseAddress, dwSize); #else __builtin___clear_cache((char *)lpBaseAddress, (char *)((INT_PTR)lpBaseAddress + dwSize)); #endif diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 033996645cb5ec..c61dce490f2121 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -84,10 +84,8 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d #endif #ifdef __APPLE__ -#include #include #include -#include #include #include extern "C" @@ -229,7 +227,7 @@ PathCharString* gSharedFilesPath = nullptr; #if defined(__NetBSD__) #define CLR_SEM_MAX_NAMELEN 15 #elif defined(__APPLE__) -#define CLR_SEM_MAX_NAMELEN PSEMNAMLEN +#define CLR_SEM_MAX_NAMELEN 31 #elif defined(NAME_MAX) #define CLR_SEM_MAX_NAMELEN (NAME_MAX - 4) #else @@ -2197,6 +2195,9 @@ PROCCreateCrashDump( INT cbErrorMessageBuffer, bool serialize) { +#if defined(TARGET_IOS) + return FALSE; +#else _ASSERTE(argv.size() > 0); _ASSERTE(errorMessageBuffer == nullptr || cbErrorMessageBuffer > 0); @@ -2321,6 +2322,7 @@ PROCCreateCrashDump( } } return true; +#endif // !TARGET_IOS } /*++ diff --git a/src/coreclr/pal/src/thread/thread.cpp b/src/coreclr/pal/src/thread/thread.cpp index 07be09edaf252c..8c66057a3b5d40 100644 --- a/src/coreclr/pal/src/thread/thread.cpp +++ b/src/coreclr/pal/src/thread/thread.cpp @@ -2584,7 +2584,7 @@ void * CPalThread::GetStackBase() { void* stackBase; -#ifdef TARGET_OSX +#ifdef TARGET_APPLE // This is a Mac specific method stackBase = pthread_get_stackaddr_np(pthread_self()); #else @@ -2624,7 +2624,7 @@ void * CPalThread::GetStackLimit() { void* stackLimit; -#ifdef TARGET_OSX +#ifdef TARGET_APPLE // This is a Mac specific method stackLimit = ((BYTE *)pthread_get_stackaddr_np(pthread_self()) - pthread_get_stacksize_np(pthread_self())); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs index 59a0567d790f20..ef76a9abcce5bb 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs @@ -112,6 +112,11 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t return MachineOSOverride.Linux; case TargetOS.OSX: + case TargetOS.MacCatalyst: + case TargetOS.iOS: + case TargetOS.iOSSimulator: + case TargetOS.tvOS: + case TargetOS.tvOSSimulator: return MachineOSOverride.Apple; case TargetOS.FreeBSD: diff --git a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs index 5159f474f01010..4a6b6a2714c659 100644 --- a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs +++ b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs @@ -295,7 +295,7 @@ public static IEnumerable> GetExtendedHelp(HelpContext _ Console.WriteLine(); string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64"}; - string[] ValidOS = new string[] {"windows", "linux", "osx"}; + string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "tvos", "tvossimulator", "maccatalyst"}; Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant())); Console.WriteLine(); diff --git a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt index 6a612e14869852..7dc878f56c8515 100644 --- a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt +++ b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt @@ -5,10 +5,14 @@ set(NATIVE_SOURCES jitinterface.cpp jitwrapper.cpp corinfoexception.cpp - - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c ) +if(NOT CLR_CROSS_COMPONENTS_BUILD) + list(APPEND NATIVE_SOURCES + ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c + ) +endif() + if(CLR_CMAKE_TARGET_WIN32) set(JITINTERFACE_RESOURCES Native.rc) else() diff --git a/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp b/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp index 8fd38d192f84e9..48cf7ece4a12b9 100644 --- a/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp +++ b/src/coreclr/tools/aot/jitinterface/jitwrapper.cpp @@ -55,5 +55,9 @@ DLL_EXPORT void JitProcessShutdownWork(ICorJitCompiler * pJit) DLL_EXPORT int JitGetProcessorFeatures() { +#ifndef CROSS_COMPILE return minipal_getcpufeatures(); +#else + return 0; +#endif } diff --git a/src/coreclr/utilcode/executableallocator.cpp b/src/coreclr/utilcode/executableallocator.cpp index 09a4801d2d5dbc..561579ddcae543 100644 --- a/src/coreclr/utilcode/executableallocator.cpp +++ b/src/coreclr/utilcode/executableallocator.cpp @@ -124,7 +124,7 @@ bool ExecutableAllocator::IsDoubleMappingEnabled() { LIMITED_METHOD_CONTRACT; -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) return false; #else return g_isWXorXEnabled; @@ -135,7 +135,7 @@ bool ExecutableAllocator::IsWXORXEnabled() { LIMITED_METHOD_CONTRACT; -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_APPLE) && defined(HOST_ARM64) return true; #else return g_isWXorXEnabled; diff --git a/src/coreclr/vm/amd64/asmhelpers.S b/src/coreclr/vm/amd64/asmhelpers.S index 8d83938246a2c9..a02959566b8816 100644 --- a/src/coreclr/vm/amd64/asmhelpers.S +++ b/src/coreclr/vm/amd64/asmhelpers.S @@ -271,7 +271,7 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT, NoHandler ret NESTED_END ProfileTailcallNaked, _TEXT -#ifdef TARGET_OSX +#ifdef TARGET_APPLE # EXTERN_C void* GetThreadVarsAddress() # # Helper to calculate the address of relevant __thread_vars section that holds the address of symbol tlv_get_address for thread @@ -283,9 +283,9 @@ LEAF_ENTRY GetThreadVarsAddress, _TEXT ret LEAF_END GetThreadVarsAddress, _TEXT // ------------------------------------------------------------------ -#endif // TARGET_OSX +#endif // TARGET_APPLE -#ifndef TARGET_OSX +#ifndef TARGET_APPLE # EXTERN_C void* GetTlsIndexObjectDescOffset(); # diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 0edbb3fdf92fc7..c2c12c7a99e305 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -777,7 +777,7 @@ LEAF_ENTRY JIT_DispatchIndirectCall, _TEXT br x9 LEAF_END JIT_DispatchIndirectCall, _TEXT -#ifdef TARGET_OSX +#ifdef TARGET_APPLE // ------------------------------------------------------------------ // void* GetThreadVarsAddress() @@ -791,9 +791,9 @@ LEAF_ENTRY GetThreadVarsAddress, _TEXT ret LEAF_END GetThreadVarsAddress, _TEXT // ------------------------------------------------------------------ -#endif // TARGET_OSX +#endif // TARGET_APPLE -#ifndef TARGET_OSX +#ifndef TARGET_APPLE // ------------------------------------------------------------------ // size_t GetThreadStaticsVariableOffset() @@ -811,4 +811,4 @@ LEAF_ENTRY GetThreadStaticsVariableOffset, _TEXT EPILOG_RETURN LEAF_END GetThreadStaticsVariableOffset, _TEXT // ------------------------------------------------------------------ -#endif // !TARGET_OSX +#endif // !TARGET_APPLE diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 442bdd01627ad2..ce954a9e8f9ee1 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1338,7 +1338,7 @@ static uint32_t ThreadLocalOffset(void* p) uint8_t* pOurTls = pTls[_tls_index]; return (uint32_t)((uint8_t*)p - pOurTls); } -#elif defined(TARGET_OSX) +#elif defined(TARGET_APPLE) extern "C" void* GetThreadVarsAddress(); static void* GetThreadVarsSectionAddressFromDesc(uint8_t* p) @@ -1432,7 +1432,7 @@ void CEEInfo::getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo->offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer); threadStaticBaseOffset = ThreadLocalOffset(&t_ThreadStatics); -#elif defined(TARGET_OSX) +#elif defined(TARGET_APPLE) pInfo->threadVarsSection = GetThreadVarsSectionAddress(); @@ -1583,7 +1583,7 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken, // Optimization is disabled for FreeBSD/arm64 #else bool optimizeThreadStaticAccess = true; -#if !defined(TARGET_OSX) && defined(TARGET_UNIX) && defined(TARGET_AMD64) +#if !defined(TARGET_APPLE) && defined(TARGET_UNIX) && defined(TARGET_AMD64) // For linux/x64, check if compiled coreclr as .so file and not single file. // For single file, the `tls_index` might not be accurate. // Do not perform this optimization in such case. @@ -10095,7 +10095,7 @@ void InlinedCallFrame::GetEEInfo(CORINFO_EE_INFO::InlinedCallFrameInfo *pInfo) CORINFO_OS getClrVmOs() { -#ifdef TARGET_OSX +#ifdef TARGET_APPLE return CORINFO_APPLE; #elif defined(TARGET_UNIX) return CORINFO_UNIX; diff --git a/src/coreclr/vm/threads.h b/src/coreclr/vm/threads.h index c84fd8a4dec3be..b1f230a978276e 100644 --- a/src/coreclr/vm/threads.h +++ b/src/coreclr/vm/threads.h @@ -5707,7 +5707,7 @@ inline BOOL IsWriteBarrierCopyEnabled() #ifdef DACCESS_COMPILE return FALSE; #else // DACCESS_COMPILE -#ifdef HOST_OSX +#ifdef HOST_APPLE return TRUE; #else return ExecutableAllocator::IsWXORXEnabled(); diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 0de334e7ff2113..b89ad091fb1ff8 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -104,6 +104,7 @@ + diff --git a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets index 3d982701bf8b66..bf0b75fc060b08 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.InTree.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.InTree.targets @@ -12,6 +12,15 @@ + + + + + + + diff --git a/src/mono/msbuild/apple/build/AppleBuild.props b/src/mono/msbuild/apple/build/AppleBuild.props index 22984e921c9681..6625f122c63efb 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.props +++ b/src/mono/msbuild/apple/build/AppleBuild.props @@ -1,7 +1,7 @@ - true + true @@ -12,7 +12,7 @@ true $(TargetOS)-$(TargetArchitecture.ToLowerInvariant()) - true + true true false @@ -24,7 +24,7 @@ <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' == 'true'">_AppleNativeAotCompile <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_AppleAotCompile ComputeIlcCompileInputs;SetupOSSpecificProps;PrepareForILLink - <_ReadRuntimeComponentsManifestTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_MonoReadAvailableComponentsManifest + <_ReadRuntimeComponentsManifestTargetName Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' != 'false'">_MonoReadAvailableComponentsManifest Publish @@ -44,6 +44,6 @@ <_CommonTargetsDir Condition="'$(_CommonTargetsDir)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', '..', 'common')) - - + + \ No newline at end of file diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 35d0f16c35b4b8..fda81eefb40658 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -53,12 +53,12 @@ $([MSBuild]::NormalizeDirectory('$(OutDir)', 'Bundle')) $(AppleBundleDir) - <_MonoHeaderPath Condition="'$(UseNativeAOTRuntime)' != 'true'">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include', 'mono-2.0')) + <_MonoHeaderPath Condition="'$(UseMonoRuntime)' != 'false' and '$(UseNativeAOTRuntime)' != 'true'">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include', 'mono-2.0')) <_AotModuleTablePath>$(AppleBundleDir)\modules.m $(AssemblyName) - + @@ -292,8 +292,15 @@ + + + NativeAOT + CoreCLR + MonoVM + + UseConsoleUITemplate="$(UseConsoleUITemplate)"> diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 7a14c7c92ed668..161e14baa75edf 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -144,9 +144,7 @@ else() System.Globalization.Native-Static System.IO.Compression.Native-Static - System.Net.Security.Native-Static System.Native-Static - System.Security.Cryptography.Native.OpenSsl-Static palrt coreclrpal_dac @@ -156,6 +154,14 @@ else() nativeresourcestring ) + if(NOT CLR_CMAKE_TARGET_TVOS) + LIST(APPEND NATIVE_LIBS System.Net.Security.Native-Static) + endif() + + if(NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_HOST_ANDROID) + LIST(APPEND NATIVE_LIBS System.Security.Cryptography.Native.OpenSsl-Static) + endif() + # additional requirements for System.IO.Compression.Native include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) append_extra_compression_libs(NATIVE_LIBS) @@ -177,7 +183,6 @@ else() endif() set(RUNTIMEINFO_LIB runtimeinfo) - endif() if(CLR_CMAKE_TARGET_APPLE) @@ -195,13 +200,13 @@ endif() # if(CLR_CMAKE_TARGET_APPLE) find_library(COREFOUNDATION CoreFoundation) - find_library(CORESERVICES CoreServices) find_library(SECURITY Security) find_library(SYSTEM System) - LIST(APPEND NATIVE_LIBS + target_link_libraries( + singlefilehost + PUBLIC ${COREFOUNDATION} - ${CORESERVICES} ${SECURITY} ${SYSTEM} ) diff --git a/src/native/corehost/hostmisc/pal.h b/src/native/corehost/hostmisc/pal.h index f482b6df63456b..b0d6eed145044c 100644 --- a/src/native/corehost/hostmisc/pal.h +++ b/src/native/corehost/hostmisc/pal.h @@ -69,7 +69,7 @@ #if defined(TARGET_WINDOWS) #define LIB_PREFIX "" #define LIB_FILE_EXT ".dll" -#elif defined(TARGET_OSX) +#elif defined(TARGET_APPLE) #define LIB_PREFIX "lib" #define LIB_FILE_EXT ".dylib" #else diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 1a1f63dae073c4..0001d2fd63ed79 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -60,20 +60,24 @@ namespace // This function is only called with the library name specified for a p/invoke, not any variations. // It must handle exact matches to the names specified. See Interop.Libraries.cs for each platform. #if !defined(_WIN32) +#if !defined(TARGET_TVOS) if (strcmp(library_name, LIB_NAME("System.Net.Security.Native")) == 0) { return SecurityResolveDllImport(entry_point_name); } +#endif if (strcmp(library_name, LIB_NAME("System.Native")) == 0) { return SystemResolveDllImport(entry_point_name); } +#if !defined(TARGET_APPLE) || defined(TARGET_OSX) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.OpenSsl")) == 0) { return CryptoResolveDllImport(entry_point_name); } +#endif #endif if (strcmp(library_name, LIB_NAME("System.IO.Compression.Native")) == 0) @@ -95,7 +99,7 @@ namespace } } -#if defined(TARGET_OSX) +#if defined(TARGET_APPLE) if (strcmp(library_name, LIB_NAME("System.Security.Cryptography.Native.Apple")) == 0) { return CryptoAppleResolveDllImport(entry_point_name); diff --git a/src/native/external/libunwind.cmake b/src/native/external/libunwind.cmake index 5dcca157e23ae6..6d4a03fdff4daf 100644 --- a/src/native/external/libunwind.cmake +++ b/src/native/external/libunwind.cmake @@ -447,7 +447,7 @@ if(CLR_CMAKE_HOST_UNIX) list(APPEND libunwind_setjmp_la_SOURCES riscv/siglongjmp.S) endif() - if(CLR_CMAKE_HOST_OSX) + if(CLR_CMAKE_HOST_APPLE) set(LIBUNWIND_SOURCES_BASE remote/mac/missing-functions.c ${libunwind_remote_la_SOURCES} @@ -463,7 +463,7 @@ if(CLR_CMAKE_HOST_UNIX) ${libunwind_dwarf_generic_la_SOURCES} ${libunwind_elf_la_SOURCES} ) - endif(CLR_CMAKE_HOST_OSX) + endif(CLR_CMAKE_HOST_APPLE) else(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_TARGET_ARCH_ARM64) diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 2bfd2194c969e2..b08325f09e3bf8 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -78,7 +78,7 @@ if(CLR_CMAKE_HOST_UNIX) ###TODO: maybe add options for RISCV64 endif() - if (CLR_CMAKE_HOST_OSX) + if (CLR_CMAKE_HOST_APPLE) add_definitions(-DUNW_REMOTE_ONLY) add_compile_options(-Wno-sometimes-uninitialized) add_compile_options(-Wno-implicit-function-declaration) @@ -86,7 +86,7 @@ if(CLR_CMAKE_HOST_UNIX) # Our posix abstraction layer will provide these headers set(HAVE_ELF_H 1) set(HAVE_ENDIAN_H 1) - endif(CLR_CMAKE_HOST_OSX) + endif(CLR_CMAKE_HOST_APPLE) endif(CLR_CMAKE_HOST_UNIX) @@ -146,7 +146,7 @@ if(CLR_CMAKE_HOST_WIN32) add_compile_options(-wd4311) # pointer truncation from 'unw_word_t *' to 'long' add_compile_options(-wd4475) # 'fprintf' : length modifier 'L' cannot be used add_compile_options(-wd4477) # fprintf argument type -elseif(CLR_CMAKE_HOST_OSX) +elseif(CLR_CMAKE_HOST_APPLE) include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote) include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/mac) endif (CLR_CMAKE_HOST_WIN32) @@ -166,11 +166,11 @@ if(CLR_CMAKE_HOST_WIN32) endif(CLR_CMAKE_HOST_WIN32) if(CLR_CMAKE_HOST_UNIX) - if(CLR_CMAKE_HOST_OSX) + if(CLR_CMAKE_HOST_APPLE) add_library(libunwind_dac OBJECT ${LIBUNWIND_SOURCES}) else() add_library(libunwind OBJECT ${LIBUNWIND_SOURCES}) - endif(CLR_CMAKE_HOST_OSX) + endif(CLR_CMAKE_HOST_APPLE) else(CLR_CMAKE_HOST_UNIX) set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc) diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 07080ea9056bb5..1cdc1cb9231784 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -188,6 +188,12 @@ add_library(System.Globalization.Native-Static entrypoints.c ) +if (DEFINED CMAKE_ICU_DIR) + include_directories(${CMAKE_ICU_DIR}/include) + target_link_libraries(System.Globalization.Native-Static ${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) + target_link_libraries(System.Globalization.Native-Static stdc++) +endif() + if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) set_target_properties(System.Globalization.Native-Static PROPERTIES OUTPUT_NAME System.Globalization.Native CLEAN_DIRECT_OUTPUT 1) endif() diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 4cac1051f6739b..ac757b4fef7a61 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -144,7 +144,7 @@ if (GEN_SHARED_LIB) install_with_stripped_symbols (System.Native PROGRAMS .) 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 AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVE_SOURCES ${NATIVE_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Native/entrypoints.c b/src/native/libs/System.Native/entrypoints.c index 30cc86f2aff976..4280d5aa6a9eec 100644 --- a/src/native/libs/System.Native/entrypoints.c +++ b/src/native/libs/System.Native/entrypoints.c @@ -34,6 +34,7 @@ static const Entry s_sysNative[] = { DllImportEntry(SystemNative_FStat) +#if !defined(TARGET_APPLE) || defined(TARGET_OSX) DllImportEntry(SystemNative_GetWindowSize) DllImportEntry(SystemNative_SetWindowSize) DllImportEntry(SystemNative_IsATty) @@ -47,6 +48,7 @@ static const Entry s_sysNative[] = DllImportEntry(SystemNative_ReadStdin) DllImportEntry(SystemNative_GetSignalForBreak) DllImportEntry(SystemNative_SetSignalForBreak) +#endif DllImportEntry(SystemNative_GetSystemTimeAsTicks) DllImportEntry(SystemNative_GetDefaultTimeZone) DllImportEntry(SystemNative_GetTimeZoneData) diff --git a/src/native/libs/System.Net.Security.Native/CMakeLists.txt b/src/native/libs/System.Net.Security.Native/CMakeLists.txt index b0e02f41509b58..e8efae3d33a795 100644 --- a/src/native/libs/System.Net.Security.Native/CMakeLists.txt +++ b/src/native/libs/System.Net.Security.Native/CMakeLists.txt @@ -19,7 +19,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 AND NOT CLR_CMAKE_TARGET_WASI) +if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVEGSS_SOURCES ${NATIVEGSS_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index b847f5c3cd68b9..e621e3c3091210 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -77,7 +77,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) +if (NOT GEN_SHARED_LIB) set(NATIVECRYPTO_SOURCES ${NATIVECRYPTO_SOURCES} entrypoints.c) endif() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c index 099fb343947110..d98498586e3fff 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c @@ -8,7 +8,6 @@ #include "pal_ecc.h" #include "pal_hmac.h" #include "pal_keyagree.h" -#include "pal_keychain_macos.h" #include "pal_keyderivation.h" #include "pal_random.h" #include "pal_rsa.h" @@ -19,17 +18,19 @@ #include "pal_ssl.h" #include "pal_swiftbindings.h" #include "pal_symmetric.h" -#include "pal_trust_macos.h" #include "pal_x509.h" -#include "pal_x509_macos.h" #include "pal_x509chain.h" +#if defined(TARGET_OSX) +#include "pal_trust_macos.h" +#include "pal_keychain_macos.h" +#include "pal_x509_macos.h" +#else +#include "pal_keychain_ios.h" +#include "pal_x509_ios.h" +#endif static const Entry s_cryptoAppleNative[] = { - DllImportEntry(AppleCryptoNative_AesGcmEncrypt) - DllImportEntry(AppleCryptoNative_AesGcmDecrypt) - DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Encrypt) - DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Decrypt) DllImportEntry(AppleCryptoNative_DigestFree) DllImportEntry(AppleCryptoNative_DigestCreate) DllImportEntry(AppleCryptoNative_DigestUpdate) @@ -48,15 +49,8 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_HmacFinal) DllImportEntry(AppleCryptoNative_HmacCurrent) DllImportEntry(AppleCryptoNative_HmacOneShot) - DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) - DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) - DllImportEntry(AppleCryptoNative_SecKeychainCreate) - DllImportEntry(AppleCryptoNative_SecKeychainDelete) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateCerts) - DllImportEntry(AppleCryptoNative_SecKeychainOpen) - DllImportEntry(AppleCryptoNative_SecKeychainUnlock) DllImportEntry(AppleCryptoNative_SecKeychainEnumerateIdentities) - DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) DllImportEntry(AppleCryptoNative_SslCopyCADistinguishedNames) DllImportEntry(AppleCryptoNative_SslCopyCertChain) DllImportEntry(AppleCryptoNative_SslIsHostnameMatch) @@ -77,8 +71,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_RsaEncryptionPrimitive) DllImportEntry(AppleCryptoNative_RsaVerificationPrimitive) DllImportEntry(AppleCryptoNative_SecCopyErrorMessageString) - DllImportEntry(AppleCryptoNative_SecKeyExport) - DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) DllImportEntry(AppleCryptoNative_SecKeyGetSimpleKeySizeInBytes) DllImportEntry(AppleCryptoNative_SecKeyCreateSignature) DllImportEntry(AppleCryptoNative_SecKeyVerifySignature) @@ -105,10 +97,6 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_CryptorCreate) DllImportEntry(AppleCryptoNative_CryptorUpdate) DllImportEntry(AppleCryptoNative_CryptorReset) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) - DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) - DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) DllImportEntry(AppleCryptoNative_X509ChainCreate) DllImportEntry(AppleCryptoNative_X509DemuxAndRetainHandle) DllImportEntry(AppleCryptoNative_X509GetContentType) @@ -117,10 +105,7 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509CopyPrivateKeyFromIdentity) DllImportEntry(AppleCryptoNative_X509ImportCollection) DllImportEntry(AppleCryptoNative_X509ImportCertificate) - DllImportEntry(AppleCryptoNative_X509ExportData) DllImportEntry(AppleCryptoNative_X509GetRawData) - DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) - DllImportEntry(AppleCryptoNative_X509MoveToKeychain) DllImportEntry(AppleCryptoNative_X509ChainCreateDefaultPolicy) DllImportEntry(AppleCryptoNative_X509ChainCreateRevocationPolicy) DllImportEntry(AppleCryptoNative_X509ChainEvaluate) @@ -134,6 +119,28 @@ static const Entry s_cryptoAppleNative[] = DllImportEntry(AppleCryptoNative_X509StoreRemoveCertificate) DllImportEntry(AppleCryptoNative_Pbkdf2) DllImportEntry(AppleCryptoNative_X509GetSubjectSummary) +#ifdef TARGET_OSX + DllImportEntry(AppleCryptoNative_AesGcmEncrypt) + DllImportEntry(AppleCryptoNative_AesGcmDecrypt) + DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Encrypt) + DllImportEntry(AppleCryptoNative_ChaCha20Poly1305Decrypt) + DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) + DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) + DllImportEntry(AppleCryptoNative_SecKeychainCreate) + DllImportEntry(AppleCryptoNative_SecKeychainDelete) + DllImportEntry(AppleCryptoNative_SecKeychainOpen) + DllImportEntry(AppleCryptoNative_SecKeychainUnlock) + DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) + DllImportEntry(AppleCryptoNative_SecKeyExport) + DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) + DllImportEntry(AppleCryptoNative_X509ExportData) + DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) + DllImportEntry(AppleCryptoNative_X509MoveToKeychain) +#endif }; EXTERN_C const void* CryptoAppleResolveDllImport(const char* name); diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index bba930e0c0072f..2044acab84875c 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -9,7 +9,7 @@ include(CheckTypeSize) include(CheckLibraryExists) include(CheckFunctionExists) -if (CLR_CMAKE_TARGET_OSX) +if (CLR_CMAKE_TARGET_APPLE) # Xcode's clang does not include /usr/local/include by default, but brew's does. # This ensures an even playing field. include_directories(SYSTEM /usr/local/include) diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index 0e16db616d62e8..9635fe02dc22d9 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -13,6 +13,7 @@ public class AppleAppBuilderTask : Task { private string targetOS = TargetNames.iOS; + private TargetRuntime targetRuntime; /// /// The Apple OS we are targeting (ios, tvos, iossimulator, tvossimulator) @@ -177,9 +178,9 @@ public string TargetOS public bool StripSymbolTable { get; set; } /// - /// Bundles the application for NativeAOT runtime. Default runtime is Mono. + /// Bundles the application for specific runtime. Valid values: MonoVM, NativeAOT, CoreCLR. /// - public bool UseNativeAOTRuntime { get; set; } + public string Runtime { get; set; } = "MonoVM"; /// /// Extra native dependencies to link into the app @@ -193,28 +194,33 @@ public string TargetOS public void ValidateRuntimeSelection() { - if (UseNativeAOTRuntime) + if (!Enum.TryParse(Runtime, out targetRuntime)) + { + throw new ArgumentException($"The \"{nameof(AppleAppBuilderTask)}\" task was not given an invalid value for parameter \"{nameof(Runtime)}\"."); + } + + if (targetRuntime == TargetRuntime.NativeAOT || targetRuntime == TargetRuntime.CoreCLR) { if (!string.IsNullOrEmpty(MonoRuntimeHeaders)) - throw new ArgumentException($"Property \"{nameof(MonoRuntimeHeaders)}\" is not supported with NativeAOT runtime and will be ignored."); + throw new ArgumentException($"Property \"{nameof(MonoRuntimeHeaders)}\" is not supported with {Runtime} runtime and will be ignored."); - if (!string.IsNullOrEmpty(MainLibraryFileName)) - throw new ArgumentException($"Property \"{nameof(MainLibraryFileName)}\" is not supported with NativeAOT runtime and will be ignored."); + if (!string.IsNullOrEmpty(MainLibraryFileName) && targetRuntime == TargetRuntime.NativeAOT) + throw new ArgumentException($"Property \"{nameof(MainLibraryFileName)}\" is not supported with {Runtime} runtime and will be ignored."); if (ForceInterpreter) - throw new ArgumentException($"Property \"{nameof(ForceInterpreter)}\" is not supported with NativeAOT runtime and will be ignored."); + throw new ArgumentException($"Property \"{nameof(ForceInterpreter)}\" is not supported with {Runtime} runtime and will be ignored."); if (ForceAOT) - throw new ArgumentException($"Property \"{nameof(ForceAOT)}\" is not supported with NativeAOT runtime and will be ignored."); + throw new ArgumentException($"Property \"{nameof(ForceAOT)}\" is not supported with {Runtime} runtime and will be ignored."); - if (RuntimeComponents.Length > 0) + if (RuntimeComponents.Length > 0 && targetRuntime == TargetRuntime.NativeAOT) throw new ArgumentException($"Item \"{nameof(RuntimeComponents)}\" is not supported with NativeAOT runtime and will be ignored."); if (!string.IsNullOrEmpty(DiagnosticPorts)) - throw new ArgumentException($"Property \"{nameof(DiagnosticPorts)}\" is not supported with NativeAOT runtime and will be ignored."); + throw new ArgumentException($"Property \"{nameof(DiagnosticPorts)}\" is not supported with {Runtime} runtime and will be ignored."); if (EnableRuntimeLogging) - throw new ArgumentException($"Property \"{nameof(EnableRuntimeLogging)}\" is not supported with NativeAOT runtime and will be ignored."); + throw new ArgumentException($"Property \"{nameof(EnableRuntimeLogging)}\" is not supported with {Runtime} runtime and will be ignored."); } else { @@ -288,7 +294,7 @@ public override bool Execute() } } - if (!ForceInterpreter && (shouldStaticLink || ForceAOT) && (assemblerFiles.Count == 0 && !UseNativeAOTRuntime)) + if (!ForceInterpreter && (shouldStaticLink || ForceAOT) && (assemblerFiles.Count == 0 && targetRuntime == TargetRuntime.MonoVM)) { throw new InvalidOperationException("Need list of AOT files for static linked builds."); } @@ -315,12 +321,18 @@ public override bool Execute() extraLinkerArgs.Add(item.ItemSpec); } + if (targetRuntime == TargetRuntime.CoreCLR) + { + extraLinkerArgs.Add("-rpath @executable_path"); + shouldStaticLink = false; + } + var generator = new Xcode(Log, TargetOS, Arch); if (GenerateXcodeProject) { XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes, - AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime, IsLibraryMode); + AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, targetRuntime, IsLibraryMode); if (BuildAppBundle) { @@ -346,7 +358,7 @@ public override bool Execute() else if (GenerateCMakeProject) { generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink, extraLinkerArgs, excludes, - AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime, IsLibraryMode); + AppDir, binDir, MonoRuntimeHeaders, !shouldStaticLink, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, HybridGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, targetRuntime, IsLibraryMode); } return true; diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj index fe87320a2da81f..721e2c67738236 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj @@ -9,6 +9,7 @@ + @@ -17,6 +18,7 @@ + diff --git a/src/tasks/AppleAppBuilder/TargetRuntime.cs b/src/tasks/AppleAppBuilder/TargetRuntime.cs new file mode 100644 index 00000000000000..81fb9b1c956d18 --- /dev/null +++ b/src/tasks/AppleAppBuilder/TargetRuntime.cs @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +internal enum TargetRuntime +{ + MonoVM, + CoreCLR, + NativeAOT, +} diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index 614d9a7cf64fbe..20633351254174 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -28,7 +28,7 @@ endif() %Defines% -if(NOT %UseNativeAOTRuntime%) +if(NOT "%MonoInclude%" STREQUAL "") include_directories("%MonoInclude%") endif() diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m new file mode 100644 index 00000000000000..582f041a44d3ee --- /dev/null +++ b/src/tasks/AppleAppBuilder/Templates/runtime-coreclr.m @@ -0,0 +1,161 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#import +#include "coreclrhost.h" +#include +#import +#include +#include +#include +#include +#include + +#import "util.h" + +#define APPLE_RUNTIME_IDENTIFIER "iossimulator-arm64" + +const char * +get_bundle_path (void) +{ + static char *bundle_path = NULL; + 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; +} + +char * +compute_trusted_platform_assemblies () +{ + const char *bundle_path = get_bundle_path (); + + NSMutableArray *files = [NSMutableArray array]; + NSMutableArray *exes = [NSMutableArray array]; + + NSFileManager *manager = [NSFileManager defaultManager]; + NSString *dir = [NSString stringWithUTF8String: bundle_path]; + NSDirectoryEnumerator *enumerator = [manager enumeratorAtURL:[NSURL fileURLWithPath: dir] + includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey] + options:NSDirectoryEnumerationSkipsSubdirectoryDescendants + errorHandler:nil]; + for (NSURL *file in enumerator) { + // skip subdirectories + NSNumber *isDirectory = nil; + if (![file getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] || [isDirectory boolValue]) + continue; + + NSString *name = nil; + if (![file getResourceValue:&name forKey:NSURLNameKey error:nil]) + continue; + if ([name length] < 4) + continue; + if ([name compare: @".dll" options: NSCaseInsensitiveSearch range: NSMakeRange ([name length] - 4, 4)] == NSOrderedSame) { + [files addObject: [dir stringByAppendingPathComponent: name]]; + } + } + + // Join them all together with a colon separating them + NSString *joined = [files componentsJoinedByString: @":"]; + return strdup([joined UTF8String]); +} + +void* +pinvoke_override (const char *libraryName, const char *entrypointName) +{ + if (!strcmp (libraryName, "__Internal")) + { + return dlsym (RTLD_DEFAULT, entrypointName); + } + return NULL; +} + +void +mono_ios_runtime_init (void) +{ +#if INVARIANT_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); +#endif + +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif + + // build using DiagnosticPorts property in AppleAppBuilder + // or set DOTNET_DiagnosticPorts env via mlaunch, xharness when undefined. + // NOTE, using DOTNET_DiagnosticPorts requires app build using AppleAppBuilder and RuntimeComponents=diagnostics_tracing +#ifdef DIAGNOSTIC_PORTS + setenv ("DOTNET_DiagnosticPorts", DIAGNOSTIC_PORTS, true); +#endif + + char **managed_argv; + int argi = get_managed_args (&managed_argv); + + bool wait_for_debugger = FALSE; + + const char* bundle = get_bundle_path (); + chdir (bundle); + + char icu_dat_path [1024]; + int res; +#if defined(HYBRID_GLOBALIZATION) + res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt_hybrid.dat"); +#else + res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt.dat"); +#endif + assert (res > 0); + + char pinvoke_override_addr [16]; + sprintf (pinvoke_override_addr, "%p", &pinvoke_override); + + // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES + const char *appctx_keys [] = { + "RUNTIME_IDENTIFIER", + "APP_CONTEXT_BASE_DIRECTORY", + "TRUSTED_PLATFORM_ASSEMBLIES", + "PINVOKE_OVERRIDE", +#if !defined(INVARIANT_GLOBALIZATION) + "ICU_DAT_FILE_PATH" +#endif + }; + const char *appctx_values [] = { + APPLE_RUNTIME_IDENTIFIER, + bundle, + compute_trusted_platform_assemblies(), + pinvoke_override_addr, +#if !defined(INVARIANT_GLOBALIZATION) + icu_dat_path +#endif + }; + + const char* executable = "Program.dll"; + const char *executablePath = [[[[NSBundle mainBundle] executableURL] path] UTF8String]; + unsigned int coreclr_domainId = 0; + void *coreclr_handle = NULL; + + char path [1024]; + res = snprintf (path, sizeof (path) - 1, "%s/%s", bundle, executable); + assert (res > 0); + + res = coreclr_initialize ( + executablePath, executable, + sizeof (appctx_keys) / sizeof (appctx_keys [0]), appctx_keys, appctx_values, + &coreclr_handle, &coreclr_domainId); + assert (res == 0); + + coreclr_execute_assembly (coreclr_handle, coreclr_domainId, argi, managed_argv, path, &res); + // Print this so apps parsing logs can detect when we exited + os_log_info (OS_LOG_DEFAULT, EXIT_CODE_TAG ": %d", res); + + free_managed_args (&managed_argv, argi); + + exit (res); +} diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index aed4bf7dfaeba3..733e766d18b355 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -190,10 +190,10 @@ public string GenerateXCode( string? diagnosticPorts, IEnumerable runtimeComponents, string? nativeMainSource = null, - bool useNativeAOTRuntime = false, + TargetRuntime targetRuntime = TargetRuntime.MonoVM, bool isLibraryMode = false) { - var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, excludes, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, useNativeAOTRuntime, isLibraryMode); + var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, extraLinkerArgs, excludes, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, hybridGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, targetRuntime, isLibraryMode); CreateXcodeProject(projectName, cmakeDirectoryPath); return Path.Combine(binDir, projectName, projectName + ".xcodeproj"); } @@ -263,14 +263,14 @@ public string GenerateCMake( string? diagnosticPorts, IEnumerable runtimeComponents, string? nativeMainSource = null, - bool useNativeAOTRuntime = false, + TargetRuntime targetRuntime = TargetRuntime.MonoVM, bool isLibraryMode = false) { // bundle everything as resources excluding native files - var predefinedExcludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib", "icudt*" }; + var predefinedExcludes = new List { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "icudt*" }; // TODO: All of these exclusions shouldn't be needed once we carefully construct the publish folder on Helix - if (useNativeAOTRuntime) + if (targetRuntime == TargetRuntime.NativeAOT) { predefinedExcludes.Add(".dll"); predefinedExcludes.Add(".pdb"); @@ -289,6 +289,10 @@ public string GenerateCMake( { predefinedExcludes.Add(".pdb"); } + if (targetRuntime != TargetRuntime.CoreCLR) + { + predefinedExcludes.Add("libcoreclr.dylib"); + } string[] resources = Directory.GetFileSystemEntries(workspace, "", SearchOption.TopDirectoryOnly) .Where(f => !predefinedExcludes.Any(e => (!e.EndsWith('*') && f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)) || (e.EndsWith('*') && Path.GetFileName(f).StartsWith(e.TrimEnd('*'), StringComparison.InvariantCultureIgnoreCase) && @@ -338,7 +342,8 @@ public string GenerateCMake( string cmakeTemplateName = (isLibraryMode) ? "CMakeLists-librarymode.txt.template" : "CMakeLists.txt.template"; string cmakeLists = Utils.GetEmbeddedResource(cmakeTemplateName) - .Replace("%UseNativeAOTRuntime%", useNativeAOTRuntime ? "TRUE" : "FALSE") + .Replace("%UseMonoRuntime%", targetRuntime == TargetRuntime.MonoVM ? "TRUE" : "FALSE") + .Replace("%UseNativeAOTRuntime%", targetRuntime == TargetRuntime.NativeAOT ? "TRUE" : "FALSE") .Replace("%ProjectName%", projectName) .Replace("%AppResources%", appResources) .Replace("%MainSource%", nativeMainSource) @@ -356,7 +361,7 @@ public string GenerateCMake( // Current differences: // - NativeAOT produces {ProjectName}.dylib, while MonoAOT produces lib{ProjectName}.dylib // - NativeAOT places the library in the 'workspace' location ie 'publish' folder, while MonoAOT places it in 'binDir' ie 'AppBundle' - if (useNativeAOTRuntime) + if (targetRuntime == TargetRuntime.NativeAOT) { libraryPath = Path.Combine(workspace, $"{projectName}.dylib"); } @@ -373,7 +378,7 @@ public string GenerateCMake( cmakeLists = cmakeLists.Replace("%DYLIB_PATH%", libraryPath); // pass the shared library to the linker for dynamic linking - if (useNativeAOTRuntime) + if (targetRuntime == TargetRuntime.NativeAOT) toLink += $" {libraryPath}{Environment.NewLine}"; } else @@ -407,26 +412,36 @@ public string GenerateCMake( } string[] dylibs = Directory.GetFiles(workspace, "*.dylib"); - foreach (string lib in Directory.GetFiles(workspace, "*.a")) + if (targetRuntime == TargetRuntime.CoreCLR) { - // all component libs already added to linker. - if (allComponentLibs.Any(lib.Contains)) - continue; - - string libName = Path.GetFileNameWithoutExtension(lib); - // libmono must always be statically linked, for other librarires we can use dylibs - bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib"); - - if (useNativeAOTRuntime) + foreach (string lib in dylibs) { - // link NativeAOT framework libs without '-force_load' - toLink += $" {lib}{Environment.NewLine}"; + toLink += $" \"-force_load {lib}\"{Environment.NewLine}"; } - else if (forceAOT || !(preferDylibs && dylibExists)) + } + else + { + foreach (string lib in Directory.GetFiles(workspace, "*.a")) { - // these libraries are pinvoked - // -force_load will be removed once we enable direct-pinvokes for AOT - toLink += $" \"-force_load {lib}\"{Environment.NewLine}"; + // all component libs already added to linker. + if (allComponentLibs.Any(lib.Contains)) + continue; + + string libName = Path.GetFileNameWithoutExtension(lib); + // libmono must always be statically linked, for other librarires we can use dylibs + bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib"); + + if (targetRuntime == TargetRuntime.NativeAOT) + { + // link NativeAOT framework libs without '-force_load' + toLink += $" {lib}{Environment.NewLine}"; + } + else if (forceAOT || !(preferDylibs && dylibExists)) + { + // these libraries are pinvoked + // -force_load will be removed once we enable direct-pinvokes for AOT + toLink += $" \"-force_load {lib}\"{Environment.NewLine}"; + } } } @@ -460,7 +475,14 @@ public string GenerateCMake( cmakeLists = cmakeLists.Replace("%EXTRA_LINKER_ARGS%", extraLinkerArgsConcat); cmakeLists = cmakeLists.Replace("%AotSources%", aotSources); cmakeLists = cmakeLists.Replace("%AotTargetsList%", aotList); - cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); + if (targetRuntime == TargetRuntime.CoreCLR) + { + cmakeLists = cmakeLists.Replace("%AotModulesSource%", "coreclrhost.h"); + } + else + { + cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); + } var defines = new StringBuilder(); if (forceInterpreter) @@ -493,10 +515,14 @@ public string GenerateCMake( defines.AppendLine($"\nadd_definitions(-DDIAGNOSTIC_PORTS=\"{diagnosticPorts}\")"); } - if (useNativeAOTRuntime) + if (targetRuntime == TargetRuntime.NativeAOT) { defines.AppendLine("add_definitions(-DUSE_NATIVE_AOT=1)"); } + else if (targetRuntime == TargetRuntime.CoreCLR) + { + defines.AppendLine("add_definitions(-DCORECLR=1)"); + } if (isLibraryMode) { @@ -531,30 +557,45 @@ public string GenerateCMake( File.WriteAllText(Path.Combine(binDir, "runtime-librarymode.h"), Utils.GetEmbeddedResource("runtime-librarymode.h")); File.WriteAllText(Path.Combine(binDir, "runtime-librarymode.m"), Utils.GetEmbeddedResource("runtime-librarymode.m")); } - else if (!useNativeAOTRuntime) + else if (targetRuntime != TargetRuntime.NativeAOT) { File.WriteAllText(Path.Combine(binDir, "runtime.h"), Utils.GetEmbeddedResource("runtime.h")); - // lookup statically linked libraries via dlsym(), see handle_pinvoke_override() in runtime.m - var pinvokeOverrides = new StringBuilder(); - foreach (string aFile in Directory.GetFiles(workspace, "*.a")) + if (targetRuntime == TargetRuntime.MonoVM) { - string aFileName = Path.GetFileNameWithoutExtension(aFile); - pinvokeOverrides.AppendLine($" \"{aFileName}\","); + // lookup statically linked libraries via dlsym(), see handle_pinvoke_override() in runtime.m + var pinvokeOverrides = new StringBuilder(); + foreach (string aFile in Directory.GetFiles(workspace, "*.a")) + { + string aFileName = Path.GetFileNameWithoutExtension(aFile); + pinvokeOverrides.AppendLine($" \"{aFileName}\","); - // also register with or without "lib" prefix - aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName; - pinvokeOverrides.AppendLine($" \"{aFileName}\","); - } + // also register with or without "lib" prefix + aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName; + pinvokeOverrides.AppendLine($" \"{aFileName}\","); + } - pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); + pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); - File.WriteAllText(Path.Combine(binDir, "runtime.m"), - Utils.GetEmbeddedResource("runtime.m") - .Replace("//%PInvokeOverrideLibraries%", pinvokeOverrides.ToString()) - .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier) - .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib))); + string runtimeTemplateName = (isLibraryMode) ? "runtime-librarymode.m" : "runtime.m"; + File.WriteAllText(Path.Combine(binDir, "runtime.m"), + Utils.GetEmbeddedResource(runtimeTemplateName) + .Replace("//%PInvokeOverrideLibraries%", pinvokeOverrides.ToString()) + .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier) + .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib))); + } + else + { + File.WriteAllText(Path.Combine(binDir, "coreclrhost.h"), + Utils.GetEmbeddedResource("coreclrhost.h")); + + // NOTE: Library mode is not supported yet + File.WriteAllText(Path.Combine(binDir, "runtime.m"), + Utils.GetEmbeddedResource("runtime-coreclr.m") + .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier) + .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib))); + } } File.WriteAllText(Path.Combine(binDir, "util.h"), Utils.GetEmbeddedResource("util.h")); diff --git a/src/tasks/LibraryBuilder/LibraryBuilder.csproj b/src/tasks/LibraryBuilder/LibraryBuilder.csproj index 50cd1c06867ef8..618895fc4c7b3a 100644 --- a/src/tasks/LibraryBuilder/LibraryBuilder.csproj +++ b/src/tasks/LibraryBuilder/LibraryBuilder.csproj @@ -23,6 +23,7 @@ + diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props index 8f85e3a0c293f2..c81996dd716ebe 100644 --- a/src/tests/Directory.Build.props +++ b/src/tests/Directory.Build.props @@ -214,7 +214,8 @@ <_targetOS>$(TargetOS) <_targetArchitecture>$(TargetArchitecture) - true + NativeAOT + CoreCLR static true <_IsApplePlatform Condition="'$(TargetsAppleMobile)' == 'true'">true diff --git a/src/tests/build.proj b/src/tests/build.proj index 0222d6b95a6bc0..b8d8b0b61fb1fd 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -418,8 +418,7 @@ - - + $([System.IO.Path]::GetDirectoryName($([System.IO.Path]::GetDirectoryName($(_CMDDIR))))) $([System.IO.Path]::GetFileName($(CategoryPath))) @@ -438,7 +437,10 @@ false false + + + @@ -449,6 +451,10 @@ + + $(IntermediateOutputPath)\..\$(TestRelativePath)\$(TestName)\native\$(TestName).o + + @@ -482,14 +488,21 @@ Projects="@(RunProj)" Targets="BuildMonoiOSApp" BuildInParallel="true" - Condition="'@(TestDirectories)' != '' and '$(TestBuildMode)' != 'nativeaot'" + Condition="'@(TestDirectories)' != '' and '$(RuntimeFlavor)' != 'coreclr'" + /> + +