Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Improving HelloiOS sample for NativeAOT to be testable with runtime packs #86652

Merged
merged 21 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
478e01f
HelloiOS sample improvements and sync with main branch
ivanpovazan May 23, 2023
9ca9c3f
Fix the way we are passing extra linker arguments from AppleAppBuilder
ivanpovazan May 23, 2023
daa1c0c
Use ILC collected linker arguments for bundling the application
ivanpovazan May 23, 2023
37b1550
Use better naming in the Makefile
ivanpovazan May 23, 2023
c94e9f0
Prepare grounds for PublishAotUsingRuntimePack = true
ivanpovazan May 23, 2023
9afd5fb
Update ILCompiler paths to handle PublishAotUsingRuntimePack=true
filipnavara May 9, 2023
5f2fe86
Enable using runtime pack from NuGet
ivanpovazan May 23, 2023
08126df
Use publish instead
ivanpovazan May 25, 2023
a8665ce
FIXME: revert once testing is finished
ivanpovazan May 23, 2023
c2eeead
Cleaning up the code
ivanpovazan May 25, 2023
2e6c29c
Fix for using publish targets
ivanpovazan May 29, 2023
65de62f
Prevent building invalid Microsoft.DotNet.ILCompiler package
ivanpovazan May 31, 2023
ae968cf
Updating README.md to reflect the changes
ivanpovazan Jun 1, 2023
ce1c9c4
PR feedback
ivanpovazan Jun 1, 2023
d4da903
Merge remote-tracking branch 'upstream/main' into hellios-packs
ivanpovazan Jun 1, 2023
808b121
Fix markdownlint errors
ivanpovazan Jun 1, 2023
5693fd3
Escape NativeAOT bundling targets
ivanpovazan Jun 2, 2023
a221b5a
Use local folder for restore packages
ivanpovazan Jun 2, 2023
6514512
PR feedback on documentation
ivanpovazan Jun 2, 2023
7c0fd97
Use IlcSdkPath instead of IlcPrivateSdkPath
filipnavara Jun 3, 2023
c9d5543
Revert "FIXME: revert once testing is finished"
ivanpovazan Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"sdk": {
"version": "8.0.100-preview.4.23260.5",
"version": "8.0.100-preview.5.23267.7",
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
"allowPrerelease": true,
"rollForward": "major"
},
"tools": {
"dotnet": "8.0.100-preview.4.23260.5"
"dotnet": "8.0.100-preview.5.23267.7"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23280.3",
Expand All @@ -15,4 +15,4 @@
"Microsoft.Build.Traversal": "3.4.0",
"Microsoft.NET.Sdk.IL": "8.0.0-preview.5.23279.2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
Text="Add a PackageReference for '$(_hostPackageName)' to allow cross-compilation for $(_targetArchitecture)" />

<!-- NativeAOT runtime pack assemblies need to be defined to avoid the default CoreCLR implementations being set as compiler inputs -->
<Error Condition="'@(PrivateSdkAssemblies)' == ''" Text="The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />
<Error Condition="'@(FrameworkAssemblies)' == ''" Text="The FrameworkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />
<Error Condition="'@(PrivateSdkAssemblies)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'" Text="The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />
<Error Condition="'@(FrameworkAssemblies)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'" Text="The FrameworkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />

<ComputeManagedAssembliesToCompileToNative
Assemblies="@(_ResolvedCopyLocalPublishAssets)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeLibrary Condition="'$(IlcMultiModule)' == 'true'" Include="$(SharedLibrary)" />
<NativeLibrary Condition="'$(NativeLib)' == '' and '$(CustomNativeMain)' != 'true'" Include="$(IlcSdkPath)libbootstrapper.a" />
<NativeLibrary Condition="'$(NativeLib)' != '' or '$(CustomNativeMain)' == 'true'" Include="$(IlcSdkPath)libbootstrapperdll.a" />
<NativeLibrary Include="$(IlcSdkPath)$(FullRuntimeName).a" />
<NativeLibrary Include="$(IlcSdkPath)$(EventPipeName)$(LibFileExt)" />
<NativeLibrary Condition="'$(LinkStandardCPlusPlusLibrary)' != 'true' and '$(StaticICULinking)' != 'true'" Include="$(IlcSdkPath)libstdc++compat.a" />
<NativeLibrary Condition="'$(NativeLib)' == '' and '$(CustomNativeMain)' != 'true'" Include="$(IlcPrivateSdkPath)libbootstrapper.a" />
<NativeLibrary Condition="'$(NativeLib)' != '' or '$(CustomNativeMain)' == 'true'" Include="$(IlcPrivateSdkPath)libbootstrapperdll.a" />
<NativeLibrary Include="$(IlcPrivateSdkPath)$(FullRuntimeName).a" />
<NativeLibrary Include="$(IlcPrivateSdkPath)$(EventPipeName)$(LibFileExt)" />
<NativeLibrary Condition="'$(LinkStandardCPlusPlusLibrary)' != 'true' and '$(StaticICULinking)' != 'true'" Include="$(IlcPrivateSdkPath)libstdc++compat.a" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,41 @@ The .NET Foundation licenses this file to you under the MIT license.

<!-- The properties below need to be defined only after we've found the correct runtime package reference -->
<Target Name="SetupProperties" DependsOnTargets="$(IlcSetupPropertiesDependsOn)" BeforeTargets="Publish">
<ItemGroup>
<_NETCoreAppFrameworkReference Include="@(ResolvedFrameworkReference)" Condition="'%(ResolvedFrameworkReference.RuntimePackName)' == 'Microsoft.NETCore.App.Runtime.NativeAOT.$(RuntimeIdentifier)'" />
</ItemGroup>

<PropertyGroup>
<!-- Define paths used in build targets to point to the runtime-specific ILCompiler implementation -->
<IlcToolsPath Condition="'$(IlcToolsPath)' == ''">$(IlcHostPackagePath)\tools\</IlcToolsPath>
<IlcSdkPath Condition="'$(IlcSdkPath)' == ''">$(RuntimePackagePath)\sdk\</IlcSdkPath>
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
<IlcFrameworkPath Condition="'$(IlcFrameworkPath)' == ''">$(RuntimePackagePath)\framework\</IlcFrameworkPath>
<IlcFrameworkNativePath Condition="'$(IlcFrameworkNativePath)' == ''">$(RuntimePackagePath)\framework\</IlcFrameworkNativePath>
<IlcFrameworkPath Condition="'$(IlcFrameworkPath)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'">$(RuntimePackagePath)\framework\</IlcFrameworkPath>
<_NETCoreAppRuntimePackPath>%(_NETCoreAppFrameworkReference.RuntimePackPath)/runtimes/$(RuntimeIdentifier)/</_NETCoreAppRuntimePackPath>
<IlcFrameworkNativePath Condition="'$(IlcFrameworkNativePath)' == '' and '$(PublishAotUsingRuntimePack)' == 'true'">$(_NETCoreAppRuntimePackPath)\native\</IlcFrameworkNativePath>
<IlcFrameworkNativePath Condition="'$(IlcFrameworkNativePath)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'">$(RuntimePackagePath)\framework\</IlcFrameworkNativePath>
<IlcPrivateSdkPath Condition="'$(IlcPrivateSdkPath)' == '' and '$(PublishAotUsingRuntimePack)' == 'true'">$(IlcFrameworkNativePath)</IlcPrivateSdkPath>
<IlcPrivateSdkPath Condition="'$(IlcPrivateSdkPath)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'">$(IlcSdkPath)</IlcPrivateSdkPath>
<IlcMibcPath Condition="'$(IlcMibcPath)' == ''">$(RuntimePackagePath)\mibc\</IlcMibcPath>
</PropertyGroup>

<ItemGroup>
<PrivateSdkAssemblies Include="$(IlcSdkPath)*.dll" />
<ItemGroup Condition="'$(PublishAotUsingRuntimePack)' == 'true'">
<PrivateSdkAssemblies Include="$(IlcPrivateSdkPath)*.dll"/>
<FrameworkAssemblies Include="@(RuntimePackAsset)" Condition="'%(Extension)' == '.dll'" />
<DefaultFrameworkAssemblies Include="@(FrameworkAssemblies)" />
</ItemGroup>

<ItemGroup Condition="'$(PublishAotUsingRuntimePack)' != 'true'">
<PrivateSdkAssemblies Include="$(IlcPrivateSdkPath)*.dll"/>
<!-- Exclude unmanaged dlls -->
<FrameworkAssemblies Include="$(IlcFrameworkPath)*.dll" Exclude="$(IlcFrameworkPath)*.Native.dll;$(IlcFrameworkPath)msquic.dll" />

<MibcFile Include="$(IlcMibcPath)*.mibc" Condition="'$(IlcPgoOptimize)' == 'true'" />

<DefaultFrameworkAssemblies Include="@(FrameworkAssemblies)" />
<DefaultFrameworkAssemblies Include="@(PrivateSdkAssemblies)" />
</ItemGroup>

<ItemGroup>
<MibcFile Include="$(IlcMibcPath)*.mibc" Condition="'$(IlcPgoOptimize)' == 'true'" />
</ItemGroup>
</Target>

<Target Name="ComputeIlcCompileInputs" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)" BeforeTargets="Publish">
Expand Down
2 changes: 1 addition & 1 deletion src/installer/pkg/projects/nativeaot-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<ItemGroup>
<Project Include="Microsoft.DotNet.ILCompiler\Microsoft.DotNet.ILCompiler.pkgproj" />
<ProjectReference Include="@(Project)" />
<ProjectReference Condition="'$(BuildNativeAOTRuntimePack)' != 'true'" Include="@(Project)" />
<ProjectReference Include="@(Project)" AdditionalProperties="PackageTargetRuntime=$(OutputRID)" />
</ItemGroup>

Expand Down
26 changes: 22 additions & 4 deletions src/mono/sample/iOS-NativeAOT/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,41 @@ TARGET_ARCH?=$(shell . $(TOP)eng/native/init-os-and-arch.sh && echo $${arch})
TARGET_OS?=iossimulator
DEPLOY_AND_RUN?=false
STRIP_DEBUG_SYMBOLS?=false
USE_RUNTIME_PACKS?=false

REPO_DIR=$(realpath $(TOP))
TASKS_DIR=$(REPO_DIR)/src/tasks
DOTNET=$(REPO_DIR)/dotnet.sh
BUILD_SCRIPT=$(REPO_DIR)/build.sh
ifeq ($(USE_RUNTIME_PACKS),false)
LOCAL_NUGET_RESTORE_DIR=
else
LOCAL_NUGET_RESTORE_DIR=$(realpath .)/packages
endif

world: build-deps all

# build all dependencies: runtime, nativeAot and all the libs
ifeq ($(USE_RUNTIME_PACKS),false)
build-deps: build-runtime-ilc build-libs-all
else
build-deps: build-runtime-ilc-packs build-libs-all-packs
endif

# building for host
build-runtime-ilc:
$(BUILD_SCRIPT) clr+clr.aot -c $(BUILD_CONFIG)

build-ilc:
$(BUILD_SCRIPT) clr.aot -c $(BUILD_CONFIG)
build-runtime-ilc-packs:
$(BUILD_SCRIPT) clr+clr.aot+libs+packs -c $(BUILD_CONFIG)

# building for target platform
build-libs-all:
$(BUILD_SCRIPT) clr.nativeaotruntime+clr.nativeaotlibs+libs -c $(BUILD_CONFIG) -os $(TARGET_OS) -arch $(TARGET_ARCH)

build-libs-all-packs:
$(BUILD_SCRIPT) clr.nativeaotruntime+clr.nativeaotlibs+libs+packs -c $(BUILD_CONFIG) -os $(TARGET_OS) -arch $(TARGET_ARCH) /p:BuildNativeAOTRuntimePack=true

build-libs-nativeaot:
$(BUILD_SCRIPT) clr.nativeaotruntime+clr.nativeaotlibs -c $(BUILD_CONFIG) -os $(TARGET_OS) -arch $(TARGET_ARCH)

Expand All @@ -37,14 +50,19 @@ all: appbuilder hello-app
appbuilder:
$(DOTNET) build -c $(BUILD_CONFIG) $(TASKS_DIR)/AppleAppBuilder/AppleAppBuilder.csproj

ifeq ($(USE_RUNTIME_PACKS),true)
hello-app: export NUGET_PACKAGES = $(LOCAL_NUGET_RESTORE_DIR)
endif

hello-app: clean
$(DOTNET) \
build -c $(BUILD_CONFIG) \
publish -c $(BUILD_CONFIG) \
-p:TargetOS=$(TARGET_OS) \
-p:TargetArchitecture=$(TARGET_ARCH) \
-p:DeployAndRun=$(DEPLOY_AND_RUN) \
-p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \
-p:PublishAotUsingRuntimePack=$(USE_RUNTIME_PACKS) \
-bl

clean:
rm -rf obj bin
rm -rf obj bin *.binlog $(LOCAL_NUGET_RESTORE_DIR)
62 changes: 40 additions & 22 deletions src/mono/sample/iOS-NativeAOT/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,48 @@
<OutputPath>bin</OutputPath>
<IntermediateOutputPath>$(MSBuildThisFileDirectory)/obj/</IntermediateOutputPath>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TargetOS Condition="'$(TargetOS)' == ''">ios</TargetOS>
<TargetOS Condition="'$(TargetsiOSSimulator)' == 'true'">iossimulator</TargetOS>
<TargetOS Condition="'$(TargetOS)' == ''">iossimulator</TargetOS>
<DeployAndRun Condition="'$(DeployAndRun)' == ''">true</DeployAndRun>
<RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</RuntimeIdentifier>
<AppName>HelloiOS</AppName>
<StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''">false</StripDebugSymbols>
<!-- NativeAOT-specific props -->
<NativeLib>static</NativeLib>
<CustomNativeMain>true</CustomNativeMain>
<UseNativeAOTRuntime Condition="'$(UseNativeAOTRuntime)' == ''">true</UseNativeAOTRuntime>
<!-- FIXME: Once we support building System.Globalization.Native and icu, should be removed -->
<InvariantGlobalization>true</InvariantGlobalization>
<!-- FIXME: We do not use publish targets yet, but we need to create a publish directory -->
<PublishDir Condition="'$(PublishDir)' == ''">$(OutputPath)/publish</PublishDir>
<NativeLib>static</NativeLib>
<CustomNativeMain>true</CustomNativeMain>
<!-- Escape NativeAOT bundling targets -->
<NativeCompilationDuringPublish>false</NativeCompilationDuringPublish>
<IlcCompileDependsOn>Compile;ComputeIlcCompileInputs;SetupOSSpecificProps;PrepareForILLink</IlcCompileDependsOn>
</PropertyGroup>

<PropertyGroup Condition="'$(PublishAotUsingRuntimePack)' == 'true'">
<PublishAot>true</PublishAot>
<MSBuildWarningsAsErrors>$(MSBuildWarningsAsErrors);NU1603</MSBuildWarningsAsErrors>
<UseLocalTargetingRuntimePack>false</UseLocalTargetingRuntimePack>
<RestoreAdditionalProjectSources>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'packages', '$(CoreCLRConfiguration)', 'Shipping'))</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\iOS\Program.cs" Link="Program.cs" />
<DirectPInvoke Include="__Internal" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetOS)' == 'maccatalyst'">
<DevTeamProvisioning Condition="'$(DevTeamProvisioning)' == ''">adhoc</DevTeamProvisioning>
<EnableAppSandbox Condition="'$(EnableAppSandbox)' == ''">false</EnableAppSandbox>
</PropertyGroup>
<!-- Fix temporary regression, will be fixed on the main in a separate PR: https://github.com/dotnet/runtime/issues/80911 -->
<Import Project="$(CoreClrProjectRoot)nativeaot\BuildIntegration\Microsoft.DotNet.ILCompiler.SingleEntry.targets" />
<Import Condition="'$(PublishAotUsingRuntimePack)' != 'true'" Project="$(CoreClrProjectRoot)nativeaot\BuildIntegration\Microsoft.DotNet.ILCompiler.SingleEntry.targets" />
<UsingTask TaskName="AppleAppBuilderTask"
AssemblyFile="$(AppleAppBuilderTasksAssemblyPath)" />

<!-- FIXME: Once we set up builing appropriate runtime package for iOS-like platforms the following properties should be removed -->
<Target Name="ConfigureIlcPathsForiOSCrossCompilation">
<!-- Use locally built runtime and ilcompiler packages -->
<Target Name="UpdateRuntimePackVersion" Condition="'$(PublishAotUsingRuntimePack)' == 'true'" BeforeTargets="ProcessFrameworkReferences">
<ItemGroup>
<KnownRuntimePack Condition="%(RuntimePackLabels) == 'NativeAOT'" LatestRuntimeFrameworkVersion="8.0.0-dev" />
<KnownILCompilerPack Update="Microsoft.DotNet.ILCompiler">
<ILCompilerPackVersion>8.0.0-dev</ILCompilerPackVersion>
</KnownILCompilerPack>
</ItemGroup>
</Target>

<!-- Run before ILC setup -->
<Target Name="ConfigureIlcPathsForiOSCrossCompilation" Condition="'$(PublishAotUsingRuntimePack)' != 'true'"
BeforeTargets="SetupProperties">
<PropertyGroup>
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(HostOS).$(BuildArchitecture).$(CoreCLRConfiguration)', 'ilc'))</IlcPath>
<IlcToolsPath>$(IlcPath)</IlcToolsPath>
Expand All @@ -47,23 +57,29 @@

<Target Name="BuildAppBundle"
AfterTargets="Build"
DependsOnTargets="ConfigureIlcPathsForiOSCrossCompilation;SetupProperties;ComputeIlcCompileInputs;IlcCompile">
DependsOnTargets="IlcCompile;CopyFilesToPublishDirectory">

<PropertyGroup>
<AppDir>$(MSBuildThisFileDirectory)$(PublishDir)\app</AppDir>
<IosSimulator Condition="'$(TargetsiOSSimulator)' == 'true'">iPhone 11</IosSimulator>
<Optimized Condition="'$(Configuration)' == 'Release'">True</Optimized>
<StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''">false</StripDebugSymbols>
<DevTeamProvisioning Condition="'$(TargetOS)' == 'maccatalyst' and '$(DevTeamProvisioning)' == ''">adhoc</DevTeamProvisioning>
<EnableAppSandbox Condition="'$(TargetOS)' == 'maccatalyst' and '$(EnableAppSandbox)' == ''">false</EnableAppSandbox>
</PropertyGroup>

<ItemGroup>
<NativeLibrary Include="%(ManagedBinary.IlcOutputFile)" />
<_LinkerFlagsToDrop Include="@(NativeFramework->'-framework %(Identity)')" />
<_LinkerFlagsToDrop Include="@(LinkerArg)" Condition="$([System.String]::new('%(Identity)').Contains('swift'))" />
<LinkerArg Remove="@(_LinkerFlagsToDrop)" />
<ExtraLinkerArguments Include="@(LinkerArg)" />
<_NativeDependencies Include="%(ManagedBinary.IlcOutputFile)" />
</ItemGroup>

<RemoveDir Directories="$(AppDir)" />

<AppleAppBuilderTask
UseNativeAOTRuntime="$(UseNativeAOTRuntime)"
NativeDependencies="@(NativeLibrary)"
NativeDependencies="@(_NativeDependencies)"
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
ProjectName="$(AppName)"
Expand All @@ -74,8 +90,10 @@
OutputDirectory="$(AppDir)"
Optimized="$(Optimized)"
InvariantGlobalization="$(InvariantGlobalization)"
EnableAppSandbox="$(EnableAppSandbox)"
StripSymbolTable="$(StripDebugSymbols)"
AppDir="$(MSBuildThisFileDirectory)$(PublishDir)" >
AppDir="$(MSBuildThisFileDirectory)$(PublishDir)"
ExtraLinkerArguments="@(ExtraLinkerArguments)" >
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
</AppleAppBuilderTask>
Expand Down
Loading