-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Adding HelloiOS sample for NativeAOT #82249
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
Changes from all commits
e0b8ca3
53baa49
433f8df
ba174d2
65b08e3
c09b462
b369a36
b621221
d42f3e3
d69ba2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.DEFAULT_GOAL := all | ||
|
||
TOP=../../../../ | ||
|
||
BUILD_CONFIG?=Debug | ||
TARGET_ARCH?=$(shell . $(TOP)eng/native/init-os-and-arch.sh && echo $${arch}) | ||
TARGET_OS?=iossimulator | ||
DEPLOY_AND_RUN?=false | ||
STRIP_DEBUG_SYMBOLS?=false | ||
|
||
REPO_DIR=$(realpath $(TOP)) | ||
TASKS_DIR=$(REPO_DIR)/src/tasks | ||
DOTNET=$(REPO_DIR)/dotnet.sh | ||
BUILD_SCRIPT=$(REPO_DIR)/build.sh | ||
|
||
world: build-deps all | ||
|
||
# build all dependencies: runtime, nativeAot and all the libs | ||
build-deps: build-runtime-ilc build-libs-all | ||
|
||
# building for host | ||
build-runtime-ilc: | ||
$(BUILD_SCRIPT) clr+clr.aot -c $(BUILD_CONFIG) | ||
|
||
build-ilc: | ||
$(BUILD_SCRIPT) clr.aot -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-nativeaot: | ||
$(BUILD_SCRIPT) clr.nativeaotruntime+clr.nativeaotlibs -c $(BUILD_CONFIG) -os $(TARGET_OS) -arch $(TARGET_ARCH) | ||
|
||
all: appbuilder hello-app | ||
|
||
appbuilder: | ||
$(DOTNET) build -c $(BUILD_CONFIG) $(TASKS_DIR)/AppleAppBuilder/AppleAppBuilder.csproj | ||
|
||
hello-app: clean | ||
$(DOTNET) \ | ||
build -c $(BUILD_CONFIG) \ | ||
-p:TargetOS=$(TARGET_OS) \ | ||
-p:TargetArchitecture=$(TARGET_ARCH) \ | ||
-p:DeployAndRun=$(DEPLOY_AND_RUN) \ | ||
-p:StripDebugSymbols=$(STRIP_DEBUG_SYMBOLS) \ | ||
-bl | ||
kotlarmilos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
clean: | ||
rm -rf obj bin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<OutputPath>bin</OutputPath> | ||
<IntermediateOutputPath>$(MSBuildThisFileDirectory)/obj/</IntermediateOutputPath> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<TargetOS Condition="'$(TargetOS)' == ''">ios</TargetOS> | ||
<TargetOS Condition="'$(TargetsiOSSimulator)' == 'true'">iossimulator</TargetOS> | ||
<DeployAndRun Condition="'$(DeployAndRun)' == ''">true</DeployAndRun> | ||
<RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</RuntimeIdentifier> | ||
<AppName>HelloiOS</AppName> | ||
kotlarmilos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<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> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\iOS\Program.cs" Link="Program.cs" /> | ||
<DirectPInvoke Include="__Internal" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(TargetOS)' == 'maccatalyst'"> | ||
ivanpovazan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<DevTeamProvisioning Condition="'$(DevTeamProvisioning)' == ''">adhoc</DevTeamProvisioning> | ||
<EnableAppSandbox Condition="'$(EnableAppSandbox)' == ''">false</EnableAppSandbox> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(CoreClrProjectRoot)nativeaot\BuildIntegration\Microsoft.NETCore.Native.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"> | ||
<PropertyGroup> | ||
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(HostOS).$(BuildArchitecture).$(CoreCLRConfiguration)', 'ilc'))</IlcPath> | ||
<IlcToolsPath>$(IlcPath)</IlcToolsPath> | ||
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath> | ||
<IlcFrameworkPath>$(LibrariesAllBinArtifactsPath)</IlcFrameworkPath> | ||
<IlcFrameworkNativePath>$(LibrariesAllBinArtifactsPath)</IlcFrameworkNativePath> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Target Name="BuildAppBundle" | ||
AfterTargets="Build" | ||
DependsOnTargets="ConfigureIlcPathsForiOSCrossCompilation;SetupProperties;ComputeIlcCompileInputs;IlcCompile"> | ||
|
||
<PropertyGroup> | ||
<AppDir>$(MSBuildThisFileDirectory)$(PublishDir)\app</AppDir> | ||
<IosSimulator Condition="'$(TargetsiOSSimulator)' == 'true'">iPhone 11</IosSimulator> | ||
<Optimized Condition="'$(Configuration)' == 'Release'">True</Optimized> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<NativeLibrary Include="%(ManagedBinary.IlcOutputFile)" /> | ||
</ItemGroup> | ||
|
||
<RemoveDir Directories="$(AppDir)" /> | ||
|
||
<AppleAppBuilderTask | ||
UseNativeAOTRuntime="$(UseNativeAOTRuntime)" | ||
NativeDependencies="@(NativeLibrary)" | ||
TargetOS="$(TargetOS)" | ||
Arch="$(TargetArchitecture)" | ||
ProjectName="$(AppName)" | ||
Assemblies="@(BundleAssemblies)" | ||
GenerateXcodeProject="True" | ||
BuildAppBundle="True" | ||
DevTeamProvisioning="$(DevTeamProvisioning)" | ||
OutputDirectory="$(AppDir)" | ||
Optimized="$(Optimized)" | ||
InvariantGlobalization="$(InvariantGlobalization)" | ||
StripSymbolTable="$(StripDebugSymbols)" | ||
AppDir="$(MSBuildThisFileDirectory)$(PublishDir)" > | ||
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" /> | ||
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" /> | ||
</AppleAppBuilderTask> | ||
|
||
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/> | ||
<Message Importance="High" Text="App: $(AppBundlePath)"/> | ||
|
||
</Target> | ||
|
||
<Target Name="RunAppBundle" | ||
AfterTargets="BuildAppBundle" | ||
Condition="'$(DeployAndRun)' == 'true'"> | ||
<Exec Condition="'$(TargetOS)' == 'iossimulator'" Command="dotnet xharness apple run --app=$(AppBundlePath) --targets=ios-simulator-64 --output-directory=/tmp/out" /> | ||
<Exec Condition="'$(TargetOS)' == 'ios'" Command="dotnet xharness apple run --app=$(AppBundlePath) --targets=ios-device --output-directory=/tmp/out" /> | ||
</Target> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# NativeAOT iOS sample app | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it under mono folder? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree the location is not ideal as I wrote in the description, I wanted to avoid interrupting the repo tree and think that until we have more complete support with NativeAOT it might stay like this, as these samples are generally used as PoC. Later, once we have more complete NativeAOT on iOS support, we should move the sample into a tests directory where it should become a functional test. Nevertheless, I am open for suggestions where to place the application. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW NativeAOT keeps samples here: https://github.com/dotnet/samples/tree/main/core/nativeaot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also https://github.com/dotnet/runtime/tree/main/src/samples which may be better than the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MichalStrehovsky what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong opinion. If the sample is not building/testing, it will go stale and stop working quickly. This sample is digging into too many unstable internals to be placed in the dotnet/samples repo. I don't know about the src/samples directory. It looks like it's something we imported from runtimelab. It's unclear if intentionally; can't find any docs for what it is. If I try to It's not clear to me who the target audience for the sample is. I don't have an opinion on where it should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The target audience, for now, are developers contributing to NativeAOT on iOS work and the sample serves as a verification method to locally test a change (or series of changes). On the other hand, the sample is also a "proof" that with the current state of dotnet/runtime main, one can build an iOS-like application targeting different platforms with NativeAOT. Once we have runtime packages ready, they will be referenced instead of referencing internals explicitly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I was trying to say is that if this is not building/running, it will go stale and might as well live in a personal repo of one of the devs. It will likely get regularly broken now or in the future. If it's building and running, it would qualify as a test and would go to src/tests. I'm not firm on any of this but I was asked for an opinion :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, and I am grateful for your input! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had very similar discussion when src/mono/sample was added initially. The problem is that we have overloaded meaning of samples.
|
||
|
||
## Description | ||
|
||
This sample application is intended to be used by developers who work on enabling NativeAOT on iOS-like platforms and can serve as PoC for verifying support for the following systems: | ||
- ios | ||
- iossimulator | ||
- tvos | ||
- tvossimulator | ||
- maccatalyst | ||
|
||
The sample shares the source code with the Mono sample specified at: `../iOS/Program.cs` and in general should have the same behavior as MonoAOT. | ||
|
||
## Limitations | ||
|
||
The application is **_currently_** relying on the following: | ||
1. Internal dependencies - locally building the internals is required as runtime and tools nuget packages are still not being produced | ||
2. Invariant globalization - `System.Globalization.Native` is currently not being built as part of NativeAOT framework for iOS-like platforms | ||
3. No publish targets - the SDK and MSBuild integration is still not complete | ||
|
||
## How to build and test | ||
|
||
### Building for the first time | ||
|
||
When building for the first time (on a clean checkout) run from this directory the following `make` command: | ||
``` bash | ||
make world | ||
``` | ||
This will first build all required runtime components and dependencies, after which it will build the sample app and bundle it into an application bundle. | ||
By default the build will use `Debug` build configuration and target `iossimulator`. | ||
To change this behavior, specify the desired setting in the following way: | ||
``` bash | ||
make world BUILD_CONFIG=Release TARGET_OS=ios | ||
``` | ||
|
||
### To avoid building all the dependencies | ||
|
||
For future builds, you can run just: | ||
``` bash | ||
make | ||
``` | ||
which will skip building all the runtime dependencies, assuming those have been already properly built, and build the MSBuild task used for bundling the application and the application it self. | ||
|
||
For convenience, it is also possible to rebuild only the application it self with: | ||
``` bash | ||
make hello-app | ||
``` | ||
|
||
### Deploy and run | ||
|
||
#### Simulator | ||
|
||
To test the application on a simulator include the following in your make command `DEPLOY_AND_RUN=true` e.g.,: | ||
``` bash | ||
make hello-app DEPLOY_AND_RUN=true | ||
``` | ||
|
||
#### Device | ||
|
||
To test the application on a device, a provisioning profile needs to be specified. | ||
This can be achieved by defining `DevTeamProvisioning` environment variable with a valid team ID (see [developer.apple.com/account/#/membership](https://developer.apple.com/account/#/membership), scroll down to `Team ID`) for example: | ||
``` bash | ||
export DevTeamProvisioning=A1B2C3D4E5; make hello-app TARGET_OS=ios DEPLOY_AND_RUN=true | ||
``` | ||
Assuming `A1B2C3D4E5` is a valid team ID. | ||
|
||
#### One-liner | ||
|
||
On a clean dotnet/runtime checkout, from this directory, run: | ||
|
||
``` bash | ||
export DevTeamProvisioning=A1B2C3D4E5; make world BUILD_CONFIG=Release TARGET_OS=ios DEPLOY_AND_RUN=true | ||
``` | ||
|
||
This command will build everything necessary to run and deploy the application on an iOS device. | ||
|
||
### Custom builds | ||
|
||
Check the `Makefile` for individual list of targets and variables to customize the build. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#ifndef util_h | ||
#define util_h | ||
|
||
// XHarness is looking for this tag in app's output to determine the exit code | ||
#define EXIT_CODE_TAG "DOTNET.APP_EXIT_CODE" | ||
|
||
size_t get_managed_args (char*** managed_args_array); | ||
void free_managed_args (char*** managed_args_array, size_t array_size); | ||
|
||
#endif /* util_h */ |
Uh oh!
There was an error while loading. Please reload this page.