Skip to content

Commit 6f7a89f

Browse files
authored
[mono] Fix iOS sample (#35241)
1 parent 6bb37e1 commit 6f7a89f

File tree

2 files changed

+72
-51
lines changed

2 files changed

+72
-51
lines changed
Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,23 @@
11
MONO_CONFIG=Debug
22
MONO_ARCH=arm64
3+
DOTNET := ../../../../.././dotnet.sh
34

4-
ARTIFACTS_BIN=../../../../../artifacts/bin/
5-
ARTIFACTS_BCL=$(ARTIFACTS_BIN)runtime/netcoreapp5.0-iOS-$(MONO_CONFIG)-$(MONO_ARCH)
6-
ARTIFACTS_MONO=$(ARTIFACTS_BIN)/mono/iOS.$(MONO_ARCH).$(MONO_CONFIG)
7-
8-
DOTNET := $(shell cd ../../ && bash init-tools.sh | tail -1)
9-
10-
BCL_LIBS = \
11-
System.Runtime.dll \
12-
System.Runtime.Extensions.dll \
13-
System.Collections.dll \
14-
System.Core.dll \
15-
System.Threading.dll \
16-
System.Threading.Tasks.dll \
17-
System.Linq.dll \
18-
System.Memory.dll \
19-
System.Runtime.InteropServices.dll \
20-
System.Text.Encoding.Extensions.dll \
21-
Microsoft.Win32.Primitives.dll \
22-
System.Console.dll
23-
24-
all: mono build
5+
# usage example:
6+
# 'make all MONO_ARCH=x64 MONO_CONFIG=Release' to build the app for simulator
7+
all: runtimepack bundle
258

269
program:
27-
$(DOTNET) build -c Debug Program.csproj
10+
$(DOTNET) build -c $(MONO_CONFIG) Program.csproj
2811

29-
# copy everything to bin/ and run BuildIosApp task
30-
build: clean program
31-
cp $(ARTIFACTS_MONO)/System.Private.CoreLib.{dll,pdb} bin
32-
cp $(ARTIFACTS_MONO)/libmono.a bin
33-
for lib in $(BCL_LIBS); do cp $(ARTIFACTS_BCL)/$$lib bin; done
34-
cp $(ARTIFACTS_BCL)/*.a bin
35-
$(DOTNET) msbuild /t:BuildAppleApp /p:Configuration=$(MONO_CONFIG) \
36-
/p:TargetArchitecture=$(MONO_ARCH) \
37-
/p:TargetOS=iOS \
38-
/p:OutputDirectory=bin \
39-
/p:ProjectName=HelloiOS \
40-
/p:Optimized=false \
41-
/p:AppDir=$(CURDIR)/bin \
42-
/p:NativeMainSource=$(CURDIR)/main.m \
43-
/p:BuildAppBundle=true \
44-
/p:GenerateXcodeProject=true \
45-
/p:DevTeamProvisioning= \
46-
/p:MainLibraryFileName=Program.dll \
47-
../../../mono.proj
12+
bundle: clean program
13+
$(DOTNET) msbuild /t:BuildAppBundle /p:Configuration=$(MONO_CONFIG) /p:TargetArchitecture=$(MONO_ARCH) \
14+
/p:UseLlvm=$(UseLlvm) /p:LlvmPath=$(LlvmPath)
4815

4916
deploy-sim:
50-
make build MONO_ARCH=x64
51-
xcrun simctl shutdown "iPhone 11" || true
52-
xcrun simctl boot "iPhone 11"
53-
open -a Simulator
54-
xcrun simctl install "iPhone 11" $(realpath ../../../../../artifacts/bin/mono/iOS.x64.$(MONO_CONFIG)/HelloiOS/HelloiOS/Debug-iphonesimulator/HelloiOS.app)
55-
xcrun simctl launch booted net.dot.HelloiOS
17+
$(DOTNET) msbuild /t:IosDeployToSimulator /p:Configuration=$(MONO_CONFIG) /p:TargetArchitecture=$(MONO_ARCH)
5618

57-
# rebuild mono for iOS-arm64 or x64
58-
mono:
59-
../../../../.././build.sh -c $(MONO_CONFIG) -os iOS -arch $(MONO_ARCH) -subset Mono
19+
runtimepack:
20+
../../../../.././build.sh -c $(MONO_CONFIG) -os iOS -arch $(MONO_ARCH) -subset Mono+Libs /p:DisableCrossgen=true
6021

6122
clean:
6223
rm -rf bin
Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,69 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
54
<OutputPath>bin</OutputPath>
65
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
6+
<TargetArchitecture Condition="'$(TargetArchitecture)'==''">x64</TargetArchitecture>
7+
<RuntimePackDir>$(ArtifactsDir)bin\lib-runtime-packs\runtimes\ios-$(TargetArchitecture)</RuntimePackDir>
8+
<MonoRuntimeDir>$(ArtifactsDir)bin\mono\iOS.$(TargetArchitecture).$(Configuration)</MonoRuntimeDir>
9+
<BundleDir>$(MSBuildThisFileDirectory)\bin\bundle</BundleDir>
710
</PropertyGroup>
811

12+
<Target Name="RebuildAppleAppBuilder">
13+
<MSBuild Projects="$(RepoRoot)src\mono\msbuild\AppleAppBuilder\AppleAppBuilder.csproj"
14+
Properties="Configuration=$(Configuration)" Targets="Restore;Build" />
15+
</Target>
16+
17+
<UsingTask TaskName="AppleAppBuilderTask"
18+
AssemblyFile="$(ArtifactsObjDir)mono\AppleAppBuilder\$(TargetArchitecture)\$(Configuration)\AppleAppBuilder.dll" />
19+
20+
<Target Name="BuildAppBundle" DependsOnTargets="RebuildAppleAppBuilder">
21+
<PropertyGroup>
22+
<TargetArch Condition="$(RuntimeIdentifier.EndsWith('arm64'))">arm64</TargetArch>
23+
<TargetArch Condition="'$(TargetArch)' == ''">x64</TargetArch>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<AppBinaries Include="bin\*.*"/>
27+
<BclBinaries Include="$(RuntimePackDir)\lib\$(NetCoreAppCurrent)\*.*" Exclude="$(RuntimePackDir)\lib\$(NetCoreAppCurrent)\System.Runtime.WindowsRuntime.dll" />
28+
<BclBinaries Include="$(RuntimePackDir)\native\*.*" />
29+
<MonoRuntimeBinaries Include="$(MonoRuntimeDir)\*.*" />
30+
</ItemGroup>
31+
<Error Condition="!Exists('$(RuntimePackDir)')" Text="RuntimePackDir=$(RuntimePackDir) doesn't exist" />
32+
<RemoveDir Directories="$(BundleDir)" />
33+
<Copy SourceFiles="@(AppBinaries)" DestinationFolder="$(BundleDir)" SkipUnchangedFiles="true"/>
34+
<Copy SourceFiles="@(BclBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
35+
<!-- runtime pack contains all needed binaries but lets overwrite them from artifacts/bin/mono to sync runtime changes -->
36+
<Copy SourceFiles="@(MonoRuntimeBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
37+
<AppleAppBuilderTask
38+
Arch="$(TargetArchitecture)"
39+
ProjectName="HelloiOS"
40+
MonoRuntimeHeaders="$(RuntimePackDir)\native\include\mono-2.0"
41+
CrossCompiler="$(RuntimePackDir)\native\cross\mono-aot-cross"
42+
MainLibraryFileName="Program.dll"
43+
GenerateXcodeProject="True"
44+
BuildAppBundle="True"
45+
DevTeamProvisioning="$(DevTeamProvisioning)"
46+
OutputDirectory="$(BundleDir)"
47+
UseLlvm="$(UseLlvm)"
48+
LlvmPath="$(LlvmPath)"
49+
Optimized="False"
50+
AppDir="$(BundleDir)">
51+
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
52+
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
53+
</AppleAppBuilderTask>
54+
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/>
55+
<Message Importance="High" Text="App: $(AppBundlePath)"/>
56+
</Target>
57+
58+
<Target Name="IosDeployToSimulator">
59+
<PropertyGroup>
60+
<IosSimulator Condition="'$(IosSimulator)' == ''">iPhone 11</IosSimulator>
61+
</PropertyGroup>
62+
<Message Importance="High" Text="\nDeploying to '$(IosSimulator)' simulator..." />
63+
<Exec Command="xcrun simctl shutdown &quot;$(IosSimulator)&quot;" ContinueOnError="WarnAndContinue" />
64+
<Exec Command="xcrun simctl boot &quot;$(IosSimulator)&quot;" />
65+
<Exec Command="open -a Simulator" />
66+
<Exec Command="xcrun simctl install &quot;$(IosSimulator)&quot; $(BundleDir)/HelloiOS/Debug-iphonesimulator/HelloiOS.app" />
67+
<Exec Command="xcrun simctl launch --console booted net.dot.HelloiOS" />
68+
</Target>
969
</Project>

0 commit comments

Comments
 (0)