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

[mono] Add iOS app builder project #34563

Merged
merged 25 commits into from
Apr 14, 2020
Merged

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Apr 5, 2020

This PR adds a project with a single msbuild task. This task creates an *.app bundle for iOS (device or simulator) from a list of *.dll files with some simple UI (can be configured).

Usage:

  <UsingTask TaskName="AppleAppBuilderTask" 
             AssemblyFile="$(ArtifactsObjDir)mono\AppleAppBuilder\$(TargetArchitecture)\$(Configuration)\AppleAppBuilder.dll" />

  <Target Name="BuildAppleApp">
    <AppleAppBuilderTask 
        Arch="$(TargetArchitecture)"
        ProjectName="$(ProjectName)"
        Optimized="$(Optimized)"
        MonoInclude="$(BinDir)include\mono-2.0"
        CrossCompiler="$(BinDir)cross\mono-aot-cross"
        MainLibraryFileName="$(MainLibraryFileName)"
        NativeMainSource="$(NativeMainSource)"
        GenerateXcodeProject="$(GenerateXcodeProject)"
        BuildAppBundle="$(BuildAppBundle)"
        DevTeamProvisioning="$(DevTeamProvisioning)"
        AppDir="$(AppDir)">
        <Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
        <Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
    </AppleAppBuilderTask>
    <Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/>
    <Message Importance="High" Text="App: $(AppBundlePath)"/>
  </Target>

For x64 (Simulator) DevTeamProvisioning and CrossCompiler are not required.

How it works

First of all it needs a AppDir directory (e.g. dotnet publish result) with:

  • Entry point library (e.g. Program.dll) it can be a hand-made xunit runner or a HelloWorld app
  • All managed dependencies including BCL libraries and System.Private.CoreLib.dll (mono's one)
  • All static files: libmono.a, libSystem.Native.a, etc.
  • Other files are bundled as resources (e.g. pdb, configs, etc)

AotCompiler runs FullAOT compilation and produces *.dll.o files with help of clang (it does it in parallel).
Also, it creates modules.m file where it lists all the linking symbols from all *.dll.o.
Then it creates a CMakeLists.txt in order to create an xcode project via cmake.
That xcode project produces app bundles via xcodebuild command.

These app bundles are ready-to-use e.g. to be deployed to simulators via xcrun simctl install/launch or to real devices via mlaunch or ios-deploy tools.

Screen Shot 2020-04-05 at 16 10 39

Notes:
FullAOT compilation is used only for arm64 builds
Some tests crash (e.g. all with remote executor)

I'll add a hand-made xunit runner app in a separate PR.

How to run the sample:

git clone git@github.com:dotnet/runtime.git
cd runtime/src/mono/netcore/iOS
make MONO_ARCH=arm64

/cc @steveisok @marek-safar @akoeplinger

@EgorBo EgorBo requested a review from vargaz as a code owner April 5, 2020 19:11
Copy link
Contributor

@marek-safar marek-safar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/mono/IosAppBuilderTasks/AotCompiler.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTasks.csproj Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
src/mono/IosAppBuilderTasks/IosAppBuilderTask.cs Outdated Show resolved Hide resolved
@rolfbjarne
Copy link
Member

Is this a task that you're going to ship? Or is it for internal consumption? What we need is a task that only does the AOT compilation (takes the managed assemblies as input, and produces .o/.m files as output).

@EgorBo
Copy link
Member Author

EgorBo commented Apr 6, 2020

What we need is a task that only does the AOT compilation

It'd make sense to sync with @akoeplinger as he has been working on same thing

@marek-safar @rolfbjarne It looks like there is a miscommunication, I was asked to make a task from my makefile scripts to produce app bundles from libraries (tests)

src/mono/mono.proj Outdated Show resolved Hide resolved
.Select(i => i.ItemSpec)
.ToArray();
}
string[] libsToAot = Directory.GetFiles(AppDir, "*.dll")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should come as input to the task (e.g. from publish)

Copy link
Member Author

@EgorBo EgorBo Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the AppDir is basically the dotnet publish location - we need everything in the directory anyway.
Collection of files as an input makes it harder to use via command line 🙁

Arch="$(TargetArchitecture)"
ProjectName="$(ProjectName)"
Optimized="$(Optimized)"
MonoInclude="$(BinDir)include\mono-2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should better come from runtime pack

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @steveisok @akoeplinger
how do I build the "runtime pack", I've just built my repo with build.sh -c Release -os iOS -arch arm64 -subset Mono+Libs+Libs.Tests and don't see any runtime packs. The only location where I can find mono-2.0 headers and mono-aot-cross is this $(BinDir)

Copy link
Member

@steveisok steveisok Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in a PR. You'll have to update src/mono/netcore/sample/iOS/Program.csproj when it's ready.

ProjectName="$(ProjectName)"
Optimized="$(Optimized)"
MonoInclude="$(BinDir)include\mono-2.0"
CrossCompiler="$(BinDir)cross\mono-aot-cross"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also come from the runtime pack.

Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once you address the comments

}

Process process = Process.Start(processStartInfo)!;
process.ErrorDataReceived += (sender, e) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should attach ErrorDataReceived and OutputDataReceived before we start the process or we could miss some output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe also follow the recommendations from #18789 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should attach ErrorDataReceived and OutputDataReceived before we start the process or we could miss some output.

Looks like it won't miss anything, furthermore you can't start listening for outputs before you start the actual process - it throws StandardOut has not been redirected or the process hasn't started yet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18789 (comment) doesn't apply here since I actually use the parameterless overload

@steveisok
Copy link
Member

@marek-safar I think this is good to go. We'll likely need a follow up PR once the in-tree runtime pack functionality is there. Since we want to make available some kind of test runner, I think this PR shouldn't wait.

Copy link
Contributor

@marek-safar marek-safar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveisok please extract the remaining work items into tracking issue

@marek-safar marek-safar merged commit dda0a57 into dotnet:master Apr 14, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants