From: Jan Dupej <109523496+jandupej@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:48:12 +0000 (+0200) Subject: [mono][ios] Drop marshal-ilgen from iOS builds if it is not needed (#88903) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~820 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8ad0257e5a3abef57c10cfe23463c7b9f75f84c;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [mono][ios] Drop marshal-ilgen from iOS builds if it is not needed (#88903) * MarshallingPInvokeScanner is applied to Apple toolchains. * HelloiOS example uses simpler string marshaling. * Removing marshal-ilgen from HelloWorld. * Runtime components and runtime library paths are now decided in the correct order relative to building the native runtime. * RuntimeComponents is manipulated through an ItemGroup. * Cleaned up commented old code. * Reordered runtime components section. * Addressed more feedback. --- diff --git a/src/mono/msbuild/apple/build/AppleBuild.props b/src/mono/msbuild/apple/build/AppleBuild.props index 75426eb..9ce0696 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.props +++ b/src/mono/msbuild/apple/build/AppleBuild.props @@ -26,6 +26,8 @@ _InitializeCommonProperties; _BeforeAppleBuild; _AppleResolveReferences; + _ScanAssembliesDecideLightweightMarshaler; + $(_ProcessRuntimeComponentsForLibraryMode); _AppleAotCompile; _BuildNativeLibrary; _AppleGenerateAppBundle; diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index d2e8520..a816d96 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 false @@ -14,6 +14,8 @@ + @@ -55,30 +57,6 @@ <_CommonLinkerArgs Condition="'$(_IsLibraryMode)' == 'true' and '$(TargetOS)' != 'tvos' and '$(TargetOS)' != 'tvossimulator'" Include="-framework GSS" /> - - - marshal-ilgen - - - - - - - - - <_UsedComponents - Condition="'$(RuntimeComponents)' != '' and '$(RuntimeComponents)' != '*'" - Include="$(RuntimeComponents)" /> - - <_RuntimeLibraries - Include="$(AppleBuildDir)\*-stub-static.a" /> - <_RuntimeLibraries - Include="$(AppleBuildDir)\*.a" - Exclude="$(AppleBuildDir)\*-static.a" /> - - <_RuntimeLibraries Remove="$(AppleBuildDir)\libmono-component-%(_UsedComponents.Identity)-stub-static.a" /> - <_RuntimeLibraries Include="$(AppleBuildDir)\libmono-component-%(_UsedComponents.Identity)-static.a" /> - @@ -110,6 +88,50 @@ + + + true + + + + + + + + + + + + + + + + + + + + @(RuntimeComponentList) + + + + + + + + + + + <_UsedComponents + Condition="'$(RuntimeComponents)' != '' and '$(RuntimeComponents)' != '*'" + Include="$(RuntimeComponents)" /> + + <_RuntimeLibraries Include="$(AppleBuildDir)\*.a" Exclude="$(AppleBuildDir)\libmono-component-*.a" /> + <_RuntimeLibraries Include="$(AppleBuildDir)\libmono-component-*-stub-static.a" /> + <_RuntimeLibraries Remove="$(AppleBuildDir)\libmono-component-%(_UsedComponents.Identity)-stub-static.a" /> + <_RuntimeLibraries Include="$(AppleBuildDir)\libmono-component-%(_UsedComponents.Identity)-static.a" /> + + + diff --git a/src/mono/sample/iOS/Program.cs b/src/mono/sample/iOS/Program.cs index 1c9839a..54cddc3 100644 --- a/src/mono/sample/iOS/Program.cs +++ b/src/mono/sample/iOS/Program.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Text; using System.Threading; using System.Threading.Tasks; using System.Runtime.InteropServices; @@ -10,18 +11,31 @@ public static class Program { // Defined in main.m [DllImport("__Internal")] - private static extern void ios_set_text(string value); + unsafe private static extern void ios_set_text(byte* value); [DllImport("__Internal")] unsafe private static extern void ios_register_button_click(delegate* unmanaged callback); private static int counter = 0; + private static void SetText(string txt) + { + byte[] ascii = ASCIIEncoding.ASCII.GetBytes(txt); + + unsafe + { + fixed (byte* asciiPtr = ascii) + { + ios_set_text(asciiPtr); + } + } + } + // Called by native code, see main.m [UnmanagedCallersOnly] private static void OnButtonClick() { - ios_set_text("OnButtonClick! #" + counter++); + SetText("OnButtonClick! #" + counter++); } #if CI_TEST @@ -39,7 +53,7 @@ public static class Program for (int i = 0; i < msg.Length; i++) { // a kind of an animation - ios_set_text(msg.Substring(0, i + 1)); + SetText(msg.Substring(0, i + 1)); await Task.Delay(100); } diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 9a77237..f7b0306 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -31,9 +31,9 @@ - - diagnostics_tracing;marshal-ilgen - + + +