From e4cd60a2c80b1ba8f6bea79d2cadc305257be2a2 Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Thu, 12 Oct 2023 19:21:33 +0200 Subject: [PATCH 1/6] Support library mode with NativeAOT on iOS-like platforms --- eng/testing/tests.ioslike.targets | 3 +- .../Microsoft.NETCore.Native.Publish.targets | 4 +- .../Microsoft.NETCore.Native.Unix.targets | 51 ++++++++++++++++- .../Microsoft.NETCore.Native.targets | 3 +- src/libraries/sendtohelix-mobile.targets | 3 +- src/mono/msbuild/apple/build/AppleBuild.props | 5 +- .../msbuild/apple/build/AppleBuild.targets | 13 +++-- .../apple/data/ProxyProjectForAOTOnHelix.proj | 33 +++++++++-- .../CMakeLists-librarymode.txt.template | 13 ++--- .../AppleAppBuilder/Templates/main-console.m | 15 ++++- .../Templates/runtime-librarymode.h | 9 +++ .../Templates/runtime-librarymode.m | 8 ++- src/tasks/AppleAppBuilder/Xcode.cs | 55 +++++++++++++++++-- .../LibraryMode/ClassLibrary.cs} | 14 +---- .../Device/LibraryMode/ILLink.Descriptors.xml | 7 +++ .../iOS.Device.LibraryMode.Test.csproj | 55 +++++++++++++++++++ .../iOS/Simulator/LibraryMode/ClassLibrary.cs | 17 ++++++ .../LibraryMode/ILLink.Descriptors.xml | 2 +- .../iOS.Simulator.LibraryMode.Test.csproj | 42 +++++++++++--- 19 files changed, 291 insertions(+), 61 deletions(-) create mode 100644 src/tasks/AppleAppBuilder/Templates/runtime-librarymode.h rename src/tests/FunctionalTests/iOS/{Simulator/LibraryMode/Program.cs => Device/LibraryMode/ClassLibrary.cs} (55%) create mode 100644 src/tests/FunctionalTests/iOS/Device/LibraryMode/ILLink.Descriptors.xml create mode 100644 src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj create mode 100644 src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ClassLibrary.cs diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index df77a1481fcc7..d4dfbe3ebe1e4 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -10,13 +10,14 @@ - <_AOTBuildCommand>export PATH=$HELIX_CORRELATION_PAYLOAD/build/cmake/cmake-3.16.4-Darwin-x86_64/CMake.app/Contents/bin:$PATH && + <_AOTBuildCommand>export PATH=$HELIX_CORRELATION_PAYLOAD/build/cmake/cmake-3.28.0-macos-universal/CMake.app/Contents/bin:$PATH && <_AOTBuildCommand>$(_AOTBuildCommand) dotnet msbuild publish/ProxyProjectForAOTOnHelix.proj /bl:$XHARNESS_OUT/AOTBuild.binlog <_AOTBuildCommand Condition="'$(ContinuousIntegrationBuild)' != 'true'">$(_AOTBuildCommand) /p:RuntimeSrcDir=$(RepoRoot) /p:RuntimeConfig=$(Configuration) <_AOTBuildCommand>$(_AOTBuildCommand) /p:XHARNESS_EXECUTION_DIR="$XHARNESS_EXECUTION_DIR" /p:RunAOTCompilation=$(RunAOTCompilation) /p:UseNativeAOTRuntime=$(UseNativeAOTRuntime) /p:TargetOS=$(TargetOS) /p:TargetArchitecture=$(TargetArchitecture) /p:MonoForceInterpreter=$(MonoForceInterpreter) /p:MonoEnableLLVM=true /p:DevTeamProvisioning=$(DevTeamProvisioning) /p:UsePortableRuntimePack=true /p:Configuration=$(Configuration) + <_AOTBuildCommand Condition="'$(NativeLib)' != ''">$(_AOTBuildCommand) /p:NativeLib=$(NativeLib) /p:BundlesResources=$(BundlesResources) /p:ForceLibraryModeGenerateAppBundle=$(ForceLibraryModeGenerateAppBundle) <_AOTBuildCommand>$(_AOTBuildCommand) <_ResetSimulatorSwitch Condition="('$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvossimulator') and '$(IncludesTestRunner)' == 'true'">--reset-simulator diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index 256b344888cc0..3202fcf43a776 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -105,8 +105,8 @@ <_symbolExt Condition="'$(OS)' != 'Windows_NT'">$(NativeBinaryExt)$(NativeSymbolExt) <_symbolSourcePath>$(NativeOutputPath)$(TargetName)$(_symbolExt) <_symbolTargetPath>$(PublishDir)\$(TargetName)$(_symbolExt) - - <_symbolIsFile Condition="'$(NativeSymbolExt)' == '.dsym'">false + + <_symbolIsFile Condition="'$(NativeSymbolExt)' == '.dSYM'">false <_symbolIsFile Condition="'$(_symbolIsFile)' == ''">true diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 107f750af7290..c517b15fb0dc0 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -57,6 +57,51 @@ The .NET Foundation licenses this file to you under the MIT license. libstandalonegc-enabled + + xcrun + <_WhereXcrun>0 + + + + + + + + + 13.5 + 14.2 + 11.0 + + <_AppleSdkName Condition="'$(_targetOS)' == 'ios'">iphoneos + <_AppleSdkName Condition="'$(_targetOS)' == 'iossimulator'">iphonesimulator + <_AppleSdkName Condition="'$(_targetOS)' == 'tvos'">appletvos + <_AppleSdkName Condition="'$(_targetOS)' == 'tvossimulator'">appletvsimulator + <_AppleSdkName Condition="'$(_targetOS)' == 'maccatalyst'">macosx + + <_AppleTripleArch Condition="'$(TargetArchitecture)' == 'x64'">x86_64 + <_AppleTripleArch Condition="'$(TargetArchitecture)' == 'arm64'">arm64 + + <_AppleTripleOS Condition="'$(_targetOS)' == 'maccatalyst' or $(_targetOS.StartsWith('ios'))">ios + <_AppleTripleOS Condition="$(_targetOS.StartsWith('tvos'))">tvos + + <_AppleTripleAbi Condition="'$(_targetOS)' == 'ios' or '$(_targetOS)' == 'tvos'">macho + <_AppleTripleAbi Condition="'$(_targetOS)' == 'maccatalyst'">macabi + <_AppleTripleAbi Condition="$(_targetOS.EndsWith('simulator'))">simulator + + $(_AppleTripleArch)-apple-$(_AppleTripleOS)$(AppleMinOSVersion)-$(_AppleTripleAbi) + @rpath/$(TargetName)$(NativeBinaryExt) + + + + + + + + + @@ -130,13 +175,15 @@ The .NET Foundation licenses this file to you under the MIT license. - - + + + + diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index e54323ccb4040..a5da4e93b0d3e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -30,6 +30,7 @@ The .NET Foundation licenses this file to you under the MIT license. false <_IsiOSLikePlatform Condition="'$(_targetOS)' == 'maccatalyst' or $(_targetOS.StartsWith('ios')) or $(_targetOS.StartsWith('tvos'))">true <_IsApplePlatform Condition="'$(_targetOS)' == 'osx' or '$(_IsiOSLikePlatform)' == 'true'">true + <_iOSLibraryMode Condition="'$(_IsiOSLikePlatform)' == 'true' and !$(TargetFramework.Contains('$(_targetOS)')) and '$(NativeLib)' != '' and '$(CustomNativeMain)' != 'true'">true @@ -71,7 +72,7 @@ The .NET Foundation licenses this file to you under the MIT license. .lib .a - .dsym + .dSYM .pdb .dbg diff --git a/src/libraries/sendtohelix-mobile.targets b/src/libraries/sendtohelix-mobile.targets index 1d207919aa51f..b003014bdcd26 100644 --- a/src/libraries/sendtohelix-mobile.targets +++ b/src/libraries/sendtohelix-mobile.targets @@ -53,7 +53,7 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'msbuild', 'common')) $(TargetOS)- - https://netcorenativeassets.blob.core.windows.net/resource-packages/external/macos/cmake/cmake-3.16.4-Darwin-x86_64.tar.gz + https://netcorenativeassets.blob.core.windows.net/resource-packages/external/macos/cmake/cmake-3.28.0-macos-universal.tar.gz <_XHarnessAppleCustomCommand Condition="'$(NeedsiOSSDK)' == 'true'"> source build-apple-app.sh @@ -64,6 +64,7 @@ + diff --git a/src/mono/msbuild/apple/build/AppleBuild.props b/src/mono/msbuild/apple/build/AppleBuild.props index 211b35e7004e1..b910c6c395728 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.props +++ b/src/mono/msbuild/apple/build/AppleBuild.props @@ -5,7 +5,7 @@ - + true @@ -19,7 +19,8 @@ - <_IsLibraryMode Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != ''">true + + <_IsLibraryMode Condition="('$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != '') or ('$(UseNativeAOTRuntime)' == 'true' and '$(NativeLib)' == 'Shared')">true <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' == 'true'">_AppleNativeAotCompile <_AotCompileTargetName Condition="'$(UseNativeAOTRuntime)' != 'true'">_AppleAotCompile diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index df0bf82e95bd5..914351a5cee4d 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -4,7 +4,7 @@ true false - <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true'">_ProcessRuntimeComponentsForLibraryMode + <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_ProcessRuntimeComponentsForLibraryMode false @@ -267,7 +267,7 @@ + DependsOnTargets="SetupProperties;ComputeIlcCompileInputs;IlcCompile;$(_IlcLibraryBuildDependsOn)" /> + + - + - - - + + <_LinkerFlagsToDrop Include="@(NativeFramework->'-framework %(Identity)')" /> diff --git a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj index fe64069b485fb..725308aa8c5cb 100644 --- a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj @@ -11,20 +11,36 @@ - $(OriginalPublishDir) false true - static - true - false + <_UseLibraryModeBundling Condition="'$(NativeLib)' != ''">true + <_IsApplePlatform>true true <_targetOS>$(TargetOS) - + true + + + $(OriginalPublishDir) + static + true + false + + + + false + $(BaseIntermediateOutputPath) + $([MSBuild]::NormalizeDirectory($(TestRootDir), '..', 'bin')) + $(OriginalPublishDir) + <_IlcLibraryBuildDependsOn>LinkNative;CopyNativeBinary + + false + + @@ -57,6 +73,13 @@ + + + + 127.0.0.1:9000,nosuspend,listen diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template index edb0989f2bdf7..2b40c6dd1b4ef 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template @@ -5,22 +5,18 @@ enable_language(OBJC ASM) set(APP_RESOURCES %AppResources% -lib%ProjectName%.dylib ) add_executable( %ProjectName% %MainSource% ${APP_RESOURCES} + util.h + util.m + runtime-librarymode.h + runtime-librarymode.m ) -if(NOT %UseNativeAOTRuntime%) - target_sources( - %ProjectName% - PRIVATE - runtime.m) -endif() - %Defines% if(NOT %UseNativeAOTRuntime%) @@ -36,6 +32,7 @@ set_target_properties(%ProjectName% PROPERTIES XCODE_EMBED_FRAMEWORKS "%DYLIB_PATH%" XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks" XCODE_ATTRIBUTE_SUPPORTS_MACCATALYST "YES" + XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY "YES" RESOURCE "${APP_RESOURCES}" ) diff --git a/src/tasks/AppleAppBuilder/Templates/main-console.m b/src/tasks/AppleAppBuilder/Templates/main-console.m index 5bad15ff67de1..bd3a9e78ca0e1 100644 --- a/src/tasks/AppleAppBuilder/Templates/main-console.m +++ b/src/tasks/AppleAppBuilder/Templates/main-console.m @@ -2,13 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. #import + +#if !USE_LIBRARY_MODE #if !USE_NATIVE_AOT #import "runtime.h" #else #import #import "util.h" extern int __managed__Main(int argc, char* argv[]); -#endif +#endif // !USE_NATIVE_AOT +#else +#import "runtime-librarymode.h" +#endif // !USE_LIBRARY_MODE @interface ViewController : UIViewController @end @@ -69,19 +74,23 @@ - (void)viewDidLoad { [self.view addSubview:summaryLabel]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ +#if !USE_LIBRARY_MODE #if !USE_NATIVE_AOT mono_ios_runtime_init (); #else #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); -#endif +#endif // INVARIANT_GLOBALIZATION char **managed_argv; int managed_argc = get_managed_args (&managed_argv); int ret_val = __managed__Main (managed_argc, managed_argv); free_managed_args (&managed_argv, managed_argc); os_log_info (OS_LOG_DEFAULT, EXIT_CODE_TAG ": %d", ret_val); exit (ret_val); -#endif +#endif // !USE_NATIVE_AOT +#else + library_mode_init(); +#endif //!USE_LIBRARY_MODE }); } diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.h b/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.h new file mode 100644 index 0000000000000..16b57d15f4897 --- /dev/null +++ b/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.h @@ -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. + +#ifndef runtime_librarymode_h +#define runtime_librarymode_h + +void library_mode_init (void); + +#endif /* runtime_librarymode_h */ diff --git a/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.m b/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.m index 274d9a5414c16..a4cef0ad029c2 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime-librarymode.m @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. #import +#if !USE_NATIVE_AOT #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#endif #include #import #include @@ -49,7 +51,7 @@ int invoke_netlibrary_entrypoints (void) } void -mono_ios_runtime_init (void) +library_mode_init (void) { #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); @@ -59,17 +61,19 @@ int invoke_netlibrary_entrypoints (void) setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); #endif -#if ENABLE_RUNTIME_LOGGING +#if ENABLE_RUNTIME_LOGGING && !USE_NATIVE_AOT setenv ("MONO_LOG_LEVEL", "debug", TRUE); setenv ("MONO_LOG_MASK", "all", TRUE); #endif +#if !USE_NATIVE_AOT // 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 to include 'diagnostics_tracing' component #ifdef DIAGNOSTIC_PORTS setenv ("DOTNET_DiagnosticPorts", DIAGNOSTIC_PORTS, true); #endif +#endif // !USE_NATIVE_AOT // When not bundling, this will make sure the runtime can access all the assemblies const char* bundle = get_bundle_path (); diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index e3c4d8149249c..c8b41d31789ed 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -259,6 +259,18 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) { // 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*" }; + + // TODO: All of these exclusions shouldn't be needed once we carefully construct the publish folder on Helix + if (useNativeAOTRuntime) + { + predefinedExcludes.Add(".dll"); + predefinedExcludes.Add(".pdb"); + predefinedExcludes.Add(".json"); + predefinedExcludes.Add(".txt"); + predefinedExcludes.Add(".bin"); + predefinedExcludes.Add(".dSYM"); + } + predefinedExcludes = predefinedExcludes.Concat(excludes).ToList(); if (!preferDylibs) { @@ -278,7 +290,7 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) { // use built-in main.m (with default UI) if it's not set nativeMainSource = Path.Combine(binDir, "main.m"); - File.WriteAllText(nativeMainSource, Utils.GetEmbeddedResource(useConsoleUiTemplate ? "main-console.m" : "main-simple.m")); + File.WriteAllText(nativeMainSource, Utils.GetEmbeddedResource((useConsoleUiTemplate || isLibraryMode) ? "main-console.m" : "main-simple.m")); } else { @@ -330,8 +342,30 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) if (isLibraryMode) { - string dylibName = $"lib{projectName}.dylib"; - cmakeLists = cmakeLists.Replace("%DYLIB_PATH%", $"{Path.Combine(binDir, dylibName)}"); + string libraryPath; + // TODO: unify MonoAOT and NativeAOT library paths + // 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) + { + libraryPath = Path.Combine(workspace, $"{projectName}.dylib"); + } + else + { + libraryPath = Path.Combine(binDir, $"lib{projectName}.dylib"); + } + + if (!File.Exists(libraryPath)) + { + throw new Exception($"Library not found at: {libraryPath} when building in the library mode."); + } + + cmakeLists = cmakeLists.Replace("%DYLIB_PATH%", libraryPath); + + // pass the shared library to the linker for dynamic linking + if (useNativeAOTRuntime) + toLink += $" {libraryPath}{Environment.NewLine}"; } else { @@ -454,6 +488,11 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) defines.AppendLine("add_definitions(-DUSE_NATIVE_AOT=1)"); } + if (isLibraryMode) + { + defines.AppendLine("add_definitions(-DUSE_LIBRARY_MODE=1)"); + } + cmakeLists = cmakeLists.Replace("%Defines%", defines.ToString()); string plist = Utils.GetEmbeddedResource("Info.plist.template") @@ -477,7 +516,12 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) File.WriteAllText(Path.Combine(binDir, "app.entitlements"), entitlementsTemplate.Replace("%Entitlements%", ent.ToString())); } - if (!useNativeAOTRuntime) + if (isLibraryMode) + { + 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) { File.WriteAllText(Path.Combine(binDir, "runtime.h"), Utils.GetEmbeddedResource("runtime.h")); @@ -496,9 +540,8 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); - string runtimeTemplateName = (isLibraryMode) ? "runtime-librarymode.m" : "runtime.m"; File.WriteAllText(Path.Combine(binDir, "runtime.m"), - Utils.GetEmbeddedResource(runtimeTemplateName) + Utils.GetEmbeddedResource("runtime.m") .Replace("//%PInvokeOverrideLibraries%", pinvokeOverrides.ToString()) .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier) .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib))); diff --git a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/Program.cs b/src/tests/FunctionalTests/iOS/Device/LibraryMode/ClassLibrary.cs similarity index 55% rename from src/tests/FunctionalTests/iOS/Simulator/LibraryMode/Program.cs rename to src/tests/FunctionalTests/iOS/Device/LibraryMode/ClassLibrary.cs index 75b4fa4f6d751..078eb84c4d608 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/Program.cs +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/ClassLibrary.cs @@ -6,24 +6,12 @@ using System.Threading.Tasks; using System.Runtime.InteropServices; -public static class Program +public static class ClassLibrary { - [DllImport("__Internal")] - public static extern void mono_ios_set_summary (string value); - [UnmanagedCallersOnly(EntryPoint = nameof(SayHello))] public static int SayHello() { Console.WriteLine("Called from native! Hello!"); return 42; } - - public static async Task Main(string[] args) - { - mono_ios_set_summary($"Starting functional test"); - Console.WriteLine("Done!"); - await Task.Delay(5000); - - return 42; - } } diff --git a/src/tests/FunctionalTests/iOS/Device/LibraryMode/ILLink.Descriptors.xml b/src/tests/FunctionalTests/iOS/Device/LibraryMode/ILLink.Descriptors.xml new file mode 100644 index 0000000000000..599ada98f3ba5 --- /dev/null +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/ILLink.Descriptors.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj new file mode 100644 index 0000000000000..c803f96adf3ab --- /dev/null +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj @@ -0,0 +1,55 @@ + + + + Library + true + $(NetCoreAppCurrent) + $(TargetOS)-$(TargetArchitecture) + ios + false + 42 + true + true + true + shared + false + true + + + + true + true + iOS.Device.LibraryMode.Test.dll + false + + + + + + + + + + + + + $(CoreClrProjectRoot)nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets + $(ToolsProjectRoot)illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)', 'ilc-published', 'netstandard')) + $(IlcBuildTasksDir)ILCompiler.Build.Tasks.dll + + + + + + $(CoreCLRCrossILCompilerDir) + $(CoreCLRAotSdkDir) + $(LibrariesAllBinArtifactsPath) + $(LibrariesAllBinArtifactsPath) + + + + + + + diff --git a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ClassLibrary.cs b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ClassLibrary.cs new file mode 100644 index 0000000000000..078eb84c4d608 --- /dev/null +++ b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ClassLibrary.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Threading; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +public static class ClassLibrary +{ + [UnmanagedCallersOnly(EntryPoint = nameof(SayHello))] + public static int SayHello() + { + Console.WriteLine("Called from native! Hello!"); + return 42; + } +} diff --git a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ILLink.Descriptors.xml b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ILLink.Descriptors.xml index 407eecfd7968c..f6ecff2f1ff37 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ILLink.Descriptors.xml +++ b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/ILLink.Descriptors.xml @@ -1,6 +1,6 @@ - + diff --git a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj index 0454742254a2c..91d2f197a97e9 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj @@ -1,29 +1,55 @@ - Exe - false - true + Library true $(NetCoreAppCurrent) + $(TargetOS)-$(TargetArchitecture) iossimulator - iOS.Simulator.LibraryMode.Test.dll false 42 - true - true true shared false - false + true + + true + true + iOS.Simulator.LibraryMode.Test.dll + false + true + false + - + + + + + $(CoreClrProjectRoot)nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets + $(ToolsProjectRoot)illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)', 'ilc-published', 'netstandard')) + $(IlcBuildTasksDir)ILCompiler.Build.Tasks.dll + + + + + + $(CoreCLRCrossILCompilerDir) + $(CoreCLRAotSdkDir) + $(LibrariesAllBinArtifactsPath) + $(LibrariesAllBinArtifactsPath) + + + + + + From 07250857365731480eeb9df814f68ddb2b0b379d Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Tue, 19 Dec 2023 12:49:27 +0100 Subject: [PATCH 2/6] PR feedback --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index c517b15fb0dc0..603b8f9b9ad5d 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -96,7 +96,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + - - + + From 8262b02d3945ad6a5324be646301ad656d5beec7 Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Thu, 21 Dec 2023 15:59:46 +0100 Subject: [PATCH 3/6] Simplifications according to the feedback --- .../Microsoft.NETCore.Native.Unix.targets | 28 +++++++++---------- .../Microsoft.NETCore.Native.targets | 1 - .../apple/data/ProxyProjectForAOTOnHelix.proj | 10 +++---- src/tasks/AppleAppBuilder/Xcode.cs | 3 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 603b8f9b9ad5d..7e21d3d39275c 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -57,21 +57,21 @@ The .NET Foundation licenses this file to you under the MIT license. libstandalonegc-enabled - + xcrun <_WhereXcrun>0 - + - - - 13.5 + + 13.5 14.2 - 11.0 + 11.0 <_AppleSdkName Condition="'$(_targetOS)' == 'ios'">iphoneos <_AppleSdkName Condition="'$(_targetOS)' == 'iossimulator'">iphonesimulator @@ -79,8 +79,8 @@ The .NET Foundation licenses this file to you under the MIT license. <_AppleSdkName Condition="'$(_targetOS)' == 'tvossimulator'">appletvsimulator <_AppleSdkName Condition="'$(_targetOS)' == 'maccatalyst'">macosx - <_AppleTripleArch Condition="'$(TargetArchitecture)' == 'x64'">x86_64 - <_AppleTripleArch Condition="'$(TargetArchitecture)' == 'arm64'">arm64 + <_AppleTripleArch Condition="'$(_targetArchitecture)' == 'x64'">x86_64 + <_AppleTripleArch Condition="'$(_targetArchitecture)' == 'arm64'">arm64 <_AppleTripleOS Condition="'$(_targetOS)' == 'maccatalyst' or $(_targetOS.StartsWith('ios'))">ios <_AppleTripleOS Condition="$(_targetOS.StartsWith('tvos'))">tvos @@ -90,16 +90,16 @@ The .NET Foundation licenses this file to you under the MIT license. <_AppleTripleAbi Condition="$(_targetOS.EndsWith('simulator'))">simulator $(_AppleTripleArch)-apple-$(_AppleTripleOS)$(AppleMinOSVersion)-$(_AppleTripleAbi) - @rpath/$(TargetName)$(NativeBinaryExt) + @rpath/$(TargetName)$(NativeBinaryExt) - - + - @@ -177,13 +177,13 @@ The .NET Foundation licenses this file to you under the MIT license. - + - + diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index a5da4e93b0d3e..c9ff464334c49 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -30,7 +30,6 @@ The .NET Foundation licenses this file to you under the MIT license. false <_IsiOSLikePlatform Condition="'$(_targetOS)' == 'maccatalyst' or $(_targetOS.StartsWith('ios')) or $(_targetOS.StartsWith('tvos'))">true <_IsApplePlatform Condition="'$(_targetOS)' == 'osx' or '$(_IsiOSLikePlatform)' == 'true'">true - <_iOSLibraryMode Condition="'$(_IsiOSLikePlatform)' == 'true' and !$(TargetFramework.Contains('$(_targetOS)')) and '$(NativeLib)' != '' and '$(CustomNativeMain)' != 'true'">true diff --git a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj index 725308aa8c5cb..e1a82cd4f7c28 100644 --- a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj @@ -13,7 +13,7 @@ false true - <_UseLibraryModeBundling Condition="'$(NativeLib)' != ''">true + <_UseNativeAOTLibraryModeBundling Condition="'$(NativeLib)' == 'Shared'">true <_IsApplePlatform>true true @@ -23,7 +23,7 @@ true - + $(OriginalPublishDir) static @@ -31,7 +31,7 @@ false - + false $(BaseIntermediateOutputPath) $([MSBuild]::NormalizeDirectory($(TestRootDir), '..', 'bin')) @@ -74,9 +74,9 @@ - - diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index c8b41d31789ed..a9bf648f8129a 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -443,7 +443,8 @@ public void CreateXcodeProject(string projectName, string cmakeDirectoryPath) } string appLinkLibraries = $" {frameworks}{Environment.NewLine}"; - string extraLinkerArgsConcat = $"\"{string.Join('\n', extraLinkerArgs)}\""; + string extraLinkerArgsConcatEscapeQuotes = string.Join('\n', extraLinkerArgs).Replace("\"", "\\\""); + string extraLinkerArgsConcat = $"\"{extraLinkerArgsConcatEscapeQuotes}\""; cmakeLists = cmakeLists.Replace("%NativeLibrariesToLink%", toLink); cmakeLists = cmakeLists.Replace("%APP_LINK_LIBRARIES%", appLinkLibraries); From 9d92ebae2324cbd3f6fd9a692f9f276420194a7a Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Fri, 22 Dec 2023 09:57:59 +0100 Subject: [PATCH 4/6] PR feedback --- .../Microsoft.NETCore.Native.Unix.targets | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 7e21d3d39275c..ce8c1e904de51 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -33,7 +33,7 @@ The .NET Foundation licenses this file to you under the MIT license. libRuntime.ServerGC - $(RuntimeIdentifier) + $(RuntimeIdentifier) x86_64 @@ -79,9 +79,6 @@ The .NET Foundation licenses this file to you under the MIT license. <_AppleSdkName Condition="'$(_targetOS)' == 'tvossimulator'">appletvsimulator <_AppleSdkName Condition="'$(_targetOS)' == 'maccatalyst'">macosx - <_AppleTripleArch Condition="'$(_targetArchitecture)' == 'x64'">x86_64 - <_AppleTripleArch Condition="'$(_targetArchitecture)' == 'arm64'">arm64 - <_AppleTripleOS Condition="'$(_targetOS)' == 'maccatalyst' or $(_targetOS.StartsWith('ios'))">ios <_AppleTripleOS Condition="$(_targetOS.StartsWith('tvos'))">tvos @@ -89,12 +86,12 @@ The .NET Foundation licenses this file to you under the MIT license. <_AppleTripleAbi Condition="'$(_targetOS)' == 'maccatalyst'">macabi <_AppleTripleAbi Condition="$(_targetOS.EndsWith('simulator'))">simulator - $(_AppleTripleArch)-apple-$(_AppleTripleOS)$(AppleMinOSVersion)-$(_AppleTripleAbi) + $(CrossCompileArch)-apple-$(_AppleTripleOS)$(AppleMinOSVersion)-$(_AppleTripleAbi) @rpath/$(TargetName)$(NativeBinaryExt) - + From 3a7c402e914801bca70290b73be6f71ddb7ebd6e Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Mon, 8 Jan 2024 11:40:31 +0100 Subject: [PATCH 5/6] PR feedback --- .../Microsoft.NETCore.Native.Unix.targets | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index ce8c1e904de51..ec91635d8fb1d 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -57,17 +57,6 @@ The .NET Foundation licenses this file to you under the MIT license. libstandalonegc-enabled - - xcrun - <_WhereXcrun>0 - - - - - - - 13.5 14.2 @@ -93,6 +82,17 @@ The .NET Foundation licenses this file to you under the MIT license. + + xcrun + <_WhereXcrun>0 + + + + + + + From 22235ddd42b761a0855123bd6816e60399c5b372 Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Mon, 8 Jan 2024 13:12:07 +0100 Subject: [PATCH 6/6] PR feedback --- .../iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj | 3 --- .../LibraryMode/iOS.Simulator.LibraryMode.Test.csproj | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj index c803f96adf3ab..7f33aa52c112d 100644 --- a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj @@ -47,9 +47,6 @@ $(LibrariesAllBinArtifactsPath) $(LibrariesAllBinArtifactsPath) - - - diff --git a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj index 91d2f197a97e9..843f82e1555ab 100644 --- a/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj @@ -47,9 +47,6 @@ $(LibrariesAllBinArtifactsPath) $(LibrariesAllBinArtifactsPath) - - -