Skip to content

Commit 1de5501

Browse files
authored
[CI] Add an "macOS .NET Core" build (#655)
Add a `Mac - .NET Core` build to Azure Pipelines, which *mostly* uses .NET Core to build the Java.Interop repo on macOS, with *few* Mono dependencies. Some notable changes: * Adds the `Prepare` target on Mac (.NET Core only) to move closer to what Windows uses, with the eventual goal of all systems being identical. * Adds the [`Microsoft.NETFramework.ReferenceAssemblies`][0] NuGet package to all assemblies that target `net472`. This allows them to be built on .NET Core, which does not have `net472` reference assemblies. * [Use `/`, not `\`, in `<Exec/>` tasks][1]. Mono will fix these for us, while `dotnet build` will not. * Expanded `jnienv-gen` logic to handle running `jnienv-gen.dll` on `dotnet` in `src\java-interop` as well as `src\Java.Interop`. Note that Mono is still used in the following cases: 1. `make prepare-core` uses Mono/MSBuild to build `BootstrapTasks.dll` to, which creates `JdkInfo.props`. 2. `mono jnienv-gen.exe` is used when it is run from a project build targeting `net472`. 3. Mono headers are needed to build `libjava-interop.dylib`. [0]: https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies/ [1]: dotnet/msbuild#1024 (comment)
1 parent 9a56465 commit 1de5501

File tree

32 files changed

+195
-101
lines changed

32 files changed

+195
-101
lines changed

Before.Java.Interop.sln.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\PrepareWindows.targets" Condition=" '$(OS)' == 'Windows_NT' " />
3+
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\Prepare.targets" />
44
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\RunNUnitTests.targets" />
55
</Project>

Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@
5252
<_XamarinAndroidCecilPath Condition=" '$(CecilSourceDirectory)' != '' And Exists('$(UtilityOutputFullPath)Xamarin.Android.Cecil.dll') ">$(UtilityOutputFullPath)Xamarin.Android.Cecil.dll</_XamarinAndroidCecilPath>
5353
<XamarinAndroidToolsFullPath>$([System.IO.Path]::GetFullPath ('$(XamarinAndroidToolsDirectory)'))</XamarinAndroidToolsFullPath>
5454
</PropertyGroup>
55+
<PropertyGroup>
56+
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
57+
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(BuildToolOutputFullPath)jnienv-gen.dll</_JNIEnvGenPath>
58+
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(BuildToolOutputFullPath)jnienv-gen.exe</_JNIEnvGenPath>
59+
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">dotnet "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
60+
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
61+
</PropertyGroup>
5562
</Project>

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ prepare-external $(PREPARE_EXTERNAL_FILES):
6767
(cd external/xamarin-android-tools && $(MAKE) prepare)
6868
nuget restore
6969

70+
prepare-core: bin/Build$(CONFIGURATION)/MonoInfo.props src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
71+
7072
clean:
7173
-$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean
7274
-rm -Rf bin/$(CONFIGURATION) bin/Build$(CONFIGURATION) bin/Test$(CONFIGURATION)

build-tools/automation/azure-pipelines.yaml

Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pr:
1010

1111
# Global variables
1212
variables:
13-
DotNetCoreVersion: 3.1.201
13+
DotNetCoreVersion: 3.1.300
1414
HostedMac: Hosted Mac Internal
1515
HostedWinVS2019: Hosted Windows 2019 with VS2019
1616

@@ -25,10 +25,7 @@ jobs:
2525
- checkout: self
2626
submodules: recursive
2727

28-
- task: UseDotNet@2
29-
displayName: Use .NET Core $(DotNetCoreVersion)
30-
inputs:
31-
version: $(DotNetCoreVersion)
28+
- template: templates\install-dependencies.yaml
3229

3330
- task: NuGetToolInstaller@0
3431
inputs:
@@ -78,71 +75,13 @@ jobs:
7875
- checkout: self
7976
submodules: recursive
8077

81-
- task: UseDotNet@2
82-
displayName: Use .NET Core $(DotNetCoreVersion)
83-
inputs:
84-
version: $(DotNetCoreVersion)
85-
86-
- task: DotNetCoreCLI@2
87-
displayName: Prepare Solution
88-
inputs:
89-
projects: Java.Interop.sln
90-
arguments: '-c $(Build.Configuration) -target:Prepare'
91-
92-
- task: DotNetCoreCLI@2
93-
displayName: Build Solution
94-
inputs:
95-
projects: Java.Interop.sln
96-
arguments: '-c $(Build.Configuration)'
97-
98-
- task: DotNetCoreCLI@2
99-
displayName: 'Tests: Java.Interop.Tools.Generator'
100-
inputs:
101-
command: test
102-
arguments: bin\Test$(Build.Configuration)\Java.Interop.Tools.Generator-Tests.dll
103-
continueOnError: true
104-
105-
- task: DotNetCoreCLI@2
106-
displayName: 'Tests: generator'
107-
inputs:
108-
command: test
109-
arguments: bin\Test$(Build.Configuration)\generator-Tests.dll
110-
continueOnError: true
111-
112-
- task: DotNetCoreCLI@2
113-
displayName: 'Tests: JavaCallableWrappers'
114-
inputs:
115-
command: test
116-
arguments: bin\Test$(Build.Configuration)\Java.Interop.Tools.JavaCallableWrappers-Tests.dll
117-
continueOnError: true
78+
- template: templates\install-dependencies.yaml
11879

119-
- task: DotNetCoreCLI@2
120-
displayName: 'Tests: logcat-parse'
121-
inputs:
122-
command: test
123-
arguments: bin\Test$(Build.Configuration)\logcat-parse-Tests.dll
124-
continueOnError: true
80+
- template: templates\core-build.yaml
12581

126-
- task: DotNetCoreCLI@2
127-
displayName: 'Tests: ApiXmlAdjuster'
128-
inputs:
129-
command: test
130-
arguments: bin\Test$(Build.Configuration)\Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
131-
continueOnError: true
82+
- template: templates\core-tests.yaml
13283

133-
- task: DotNetCoreCLI@2
134-
displayName: 'Tests: Bytecode'
135-
inputs:
136-
command: test
137-
arguments: bin\Test$(Build.Configuration)\Xamarin.Android.Tools.Bytecode-Tests.dll
138-
continueOnError: true
139-
140-
- powershell: |
141-
Write-Host "Current job status is: $env:AGENT_JOBSTATUS"
142-
if ($env:AGENT_JOBSTATUS -eq "SucceededWithIssues") {
143-
Write-Host "##vso[task.complete result=Failed;]DONE"
144-
}
145-
displayName: Fail job if tests failed
84+
- template: templates\fail-on-issue.yaml
14685

14786
- job: mac_build
14887
displayName: Mac - Mono
@@ -154,15 +93,7 @@ jobs:
15493
- checkout: self
15594
submodules: recursive
15695

157-
- task: UseDotNet@2
158-
displayName: Use .NET Core $(DotNetCoreVersion)
159-
inputs:
160-
version: $(DotNetCoreVersion)
161-
162-
- script: |
163-
dotnet tool install --global boots
164-
boots --stable Mono
165-
displayName: Install Mono-Stable
96+
- template: templates\install-dependencies.yaml
16697

16798
- script: make prepare CONFIGURATION=$(Build.Configuration)
16899
displayName: make prepare
@@ -200,3 +131,24 @@ jobs:
200131
inputs:
201132
ArtifactName: debug
202133
condition: succeededOrFailed()
134+
135+
- job: mac_dotnet_build
136+
displayName: Mac - .NET Core
137+
pool: $(HostedMac)
138+
timeoutInMinutes: 20
139+
workspace:
140+
clean: all
141+
steps:
142+
- checkout: self
143+
submodules: recursive
144+
145+
- template: templates\install-dependencies.yaml
146+
147+
- script: make prepare-core CONFIGURATION=$(Build.Configuration)
148+
displayName: make prepare-core
149+
150+
- template: templates\core-build.yaml
151+
152+
- template: templates\core-tests.yaml
153+
154+
- template: templates\fail-on-issue.yaml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
condition: succeeded()
3+
4+
steps:
5+
- task: DotNetCoreCLI@2
6+
displayName: Prepare Solution
7+
inputs:
8+
projects: Java.Interop.sln
9+
arguments: '-c $(Build.Configuration) -target:Prepare'
10+
11+
- task: DotNetCoreCLI@2
12+
displayName: Build Solution
13+
inputs:
14+
projects: Java.Interop.sln
15+
arguments: '-c $(Build.Configuration) -m:1'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
parameters:
2+
condition: succeeded()
3+
4+
steps:
5+
- task: DotNetCoreCLI@2
6+
displayName: 'Tests: generator'
7+
inputs:
8+
command: test
9+
arguments: bin/Test$(Build.Configuration)/generator-Tests.dll
10+
continueOnError: true
11+
12+
- task: DotNetCoreCLI@2
13+
displayName: 'Tests: JavaCallableWrappers'
14+
inputs:
15+
command: test
16+
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaCallableWrappers-Tests.dll
17+
continueOnError: true
18+
19+
- task: DotNetCoreCLI@2
20+
displayName: 'Tests: logcat-parse'
21+
inputs:
22+
command: test
23+
arguments: bin/Test$(Build.Configuration)/logcat-parse-Tests.dll
24+
continueOnError: true
25+
26+
- task: DotNetCoreCLI@2
27+
displayName: 'Tests: ApiXmlAdjuster'
28+
inputs:
29+
command: test
30+
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
31+
continueOnError: true
32+
33+
- task: DotNetCoreCLI@2
34+
displayName: 'Tests: Bytecode'
35+
inputs:
36+
command: test
37+
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.Bytecode-Tests.dll
38+
continueOnError: true
39+
40+
- task: DotNetCoreCLI@2
41+
displayName: 'Tests: Java.Interop.Tools.Generator'
42+
inputs:
43+
command: test
44+
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.Generator-Tests.dll
45+
continueOnError: true
46+
47+
- task: DotNetCoreCLI@2
48+
displayName: 'Tests: Java.Interop.Tools.JavaSource'
49+
inputs:
50+
command: test
51+
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaSource-Tests.dll
52+
continueOnError: true
53+
54+
# Running native Java.Interop tests are not yet supported on .NET Core
55+
#- task: DotNetCoreCLI@2
56+
# displayName: 'Tests: Java.Interop'
57+
# inputs:
58+
# command: test
59+
# arguments: bin/Test$(Build.Configuration)/Java.Interop-Tests.dll
60+
# continueOnError: true
61+
62+
#- task: DotNetCoreCLI@2
63+
# displayName: 'Tests: Java.Interop.Dynamic'
64+
# inputs:
65+
# command: test
66+
# arguments: bin/Test$(Build.Configuration)/Java.Interop.Dynamic-Tests.dll
67+
# continueOnError: true
68+
69+
#- task: DotNetCoreCLI@2
70+
# displayName: 'Tests: Java.Interop.Export'
71+
# inputs:
72+
# command: test
73+
# arguments: bin/Test$(Build.Configuration)/Java.Interop.Export-Tests.dll
74+
# continueOnError: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
condition: succeeded()
3+
4+
steps:
5+
- powershell: |
6+
Write-Host "Current job status is: $env:AGENT_JOBSTATUS"
7+
if ($env:AGENT_JOBSTATUS -eq "SucceededWithIssues") {
8+
Write-Host "##vso[task.complete result=Failed;]DONE"
9+
}
10+
displayName: fail if any issues occurred
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
condition: succeeded()
3+
4+
steps:
5+
- task: UseDotNet@2
6+
displayName: Use .NET Core $(DotNetCoreVersion)
7+
inputs:
8+
version: $(DotNetCoreVersion)
9+
10+
- script: |
11+
dotnet tool install --global boots
12+
boots --stable Mono
13+
displayName: Install Mono-Stable
14+
condition: and(succeeded(), eq(variables['agent.os'], 'Darwin'))

build-tools/jnienv-gen/jnienv-gen.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
<OutputPath>$(BuildToolOutputFullPath)</OutputPath>
1212
</PropertyGroup>
1313

14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
16+
</ItemGroup>
1417
</Project>

samples/Hello/Hello.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<OutputPath>$(TestOutputFullPath)</OutputPath>
1212
</PropertyGroup>
1313

14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
16+
</ItemGroup>
17+
1418
<ItemGroup>
1519
<ProjectReference Include="..\..\src\Java.Interop\Java.Interop.csproj" />
1620
<ProjectReference Include="..\..\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj" />

src/Java.Interop/Directory.Build.targets

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<PropertyGroup>
4-
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
5-
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(BuildToolOutputFullPath)jnienv-gen.dll</_JNIEnvGenPath>
6-
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(BuildToolOutputFullPath)jnienv-gen.exe</_JNIEnvGenPath>
7-
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">dotnet "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
8-
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
9-
</PropertyGroup>
103
<ItemGroup>
114
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\internal\JavaProxyObject.java" />
125
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\internal\JavaProxyThrowable.java" />
@@ -21,16 +14,16 @@
2114
<Target Name="BuildJniEnvironment_g_cs"
2215
BeforeTargets="BeforeCompile"
2316
Inputs="$(_JNIEnvGenPath)"
24-
Outputs="Java.Interop\JniEnvironment.g.cs;$(IntermediateOutputPath)\jni.c">
17+
Outputs="Java.Interop/JniEnvironment.g.cs;$(IntermediateOutputPath)jni.c">
2518
<MakeDir Directories="$(IntermediateOutputPath)" />
2619
<PropertyGroup>
27-
<_AddCompile Condition=" !Exists('Java.Interop\JniEnvironment.g.cs') ">True</_AddCompile>
20+
<_AddCompile Condition=" !Exists('Java.Interop/JniEnvironment.g.cs') ">True</_AddCompile>
2821
</PropertyGroup>
2922
<Exec
30-
Command="$(_RunJNIEnvGen) Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
23+
Command="$(_RunJNIEnvGen) Java.Interop/JniEnvironment.g.cs $(IntermediateOutputPath)jni.c"
3124
/>
3225
<ItemGroup>
33-
<Compile Include="Java.Interop\JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
26+
<Compile Include="Java.Interop/JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
3427
</ItemGroup>
3528
</Target>
3629
<Target Name="BuildInteropJar"

src/java-interop/java-interop.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
</ItemGroup>
4545

4646
<Import Project="java-interop.targets" />
47-
47+
48+
<ItemGroup>
49+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
50+
</ItemGroup>
51+
4852
<ItemGroup>
4953
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" />
5054
</ItemGroup>

src/java-interop/java-interop.targets

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
3-
<PropertyGroup>
4-
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
5-
</PropertyGroup>
63
<Target Name="BuildJni_c"
7-
Inputs="$(JNIEnvGenPath)\jnienv-gen.exe"
4+
Inputs="$(_JNIEnvGenPath)"
85
Outputs="jni.c">
96
<MakeDir Directories="$(OutputPath)" />
10-
<Exec Command="$(Runtime) &quot;$(JNIEnvGenPath)\jnienv-gen.exe&quot; jni.g.cs jni.c" />
7+
<Exec Command="$(_RunJNIEnvGen) jni.g.cs jni.c" />
118
</Target>
129

1310
<PropertyGroup>
14-
<_MacLib>$(OutputPath)\lib$(OutputName).dylib</_MacLib>
11+
<_MacLib>$(OutputPath)/lib$(OutputName).dylib</_MacLib>
1512
</PropertyGroup>
1613

1714
<Target Name="_CompileObjectFiles"
@@ -32,7 +29,7 @@
3229
<_Inc>@(_Includes->'-I "%(Identity)"', ' ')</_Inc>
3330
</PropertyGroup>
3431
<Exec
35-
Command="$(_Cc) -c -g $(_Arch) -o &quot;obj\$(Configuration)\%(ClCompile.Filename).o&quot; $(_Def) $(_Inc) &quot;%(Identity)&quot;"
32+
Command="$(_Cc) -c -g $(_Arch) -o &quot;obj/$(Configuration)/%(ClCompile.Filename).o&quot; $(_Def) $(_Inc) &quot;%(Identity)&quot;"
3633
/>
3734
</Target>
3835

@@ -47,7 +44,8 @@
4744
<_Libs>$(MonoLibs)</_Libs>
4845
<_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ')</_Files>
4946
</PropertyGroup>
50-
<Exec Command="gcc -g -shared -m64 -std=c99 -fPIC -o &quot;$(_MacLib)&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
47+
<!-- Use 'IgnoreStandardErrorWarningFormat' to ignore 'ld: warning: text-based stub file X and and library file Y are out of sync' warnings. -->
48+
<Exec Command="gcc -g -shared -m64 -std=c99 -fPIC -o &quot;$(_MacLib)&quot; $(_LinkFlags) $(_Libs) $(_Files)" IgnoreStandardErrorWarningFormat="true" />
5149
<!-- Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) has an incorrect shared library name. Fix it -->
5250
<Exec Command="install_name_tool -change /private/tmp/source-mono-4.4.0/bockbuild-mono-4.4.0-branch/profiles/mono-mac-xamarin/package-root/lib/libmonosgen-2.0.1.dylib /Library/Frameworks/Mono.framework/Libraries/libmonosgen-2.0.1.dylib &quot;$(_MacLib)&quot;" />
5351
</Target>
@@ -69,7 +67,7 @@
6967
<_Libs>$(MonoLibs)</_Libs>
7068
<_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ')</_Files>
7169
</PropertyGroup>
72-
<Exec Command="g++ -g -shared -o &quot;$(OutputPath)\lib$(OutputName).so&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
70+
<Exec Command="g++ -g -shared -o &quot;$(OutputPath)/lib$(OutputName).so&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
7371
</Target>
7472

7573
<Target Name="Clean">

0 commit comments

Comments
 (0)