Skip to content

Commit

Permalink
[CI] Add an "macOS .NET Core" build (#655)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jpobst authored Jun 15, 2020
1 parent 9a56465 commit 1de5501
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 101 deletions.
2 changes: 1 addition & 1 deletion Before.Java.Interop.sln.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\PrepareWindows.targets" Condition=" '$(OS)' == 'Windows_NT' " />
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\Prepare.targets" />
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\RunNUnitTests.targets" />
</Project>
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@
<_XamarinAndroidCecilPath Condition=" '$(CecilSourceDirectory)' != '' And Exists('$(UtilityOutputFullPath)Xamarin.Android.Cecil.dll') ">$(UtilityOutputFullPath)Xamarin.Android.Cecil.dll</_XamarinAndroidCecilPath>
<XamarinAndroidToolsFullPath>$([System.IO.Path]::GetFullPath ('$(XamarinAndroidToolsDirectory)'))</XamarinAndroidToolsFullPath>
</PropertyGroup>
<PropertyGroup>
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(BuildToolOutputFullPath)jnienv-gen.dll</_JNIEnvGenPath>
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(BuildToolOutputFullPath)jnienv-gen.exe</_JNIEnvGenPath>
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">dotnet "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ prepare-external $(PREPARE_EXTERNAL_FILES):
(cd external/xamarin-android-tools && $(MAKE) prepare)
nuget restore

prepare-core: bin/Build$(CONFIGURATION)/MonoInfo.props src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config

clean:
-$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean
-rm -Rf bin/$(CONFIGURATION) bin/Build$(CONFIGURATION) bin/Test$(CONFIGURATION)
Expand Down
104 changes: 28 additions & 76 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pr:

# Global variables
variables:
DotNetCoreVersion: 3.1.201
DotNetCoreVersion: 3.1.300
HostedMac: Hosted Mac Internal
HostedWinVS2019: Hosted Windows 2019 with VS2019

Expand All @@ -25,10 +25,7 @@ jobs:
- checkout: self
submodules: recursive

- task: UseDotNet@2
displayName: Use .NET Core $(DotNetCoreVersion)
inputs:
version: $(DotNetCoreVersion)
- template: templates\install-dependencies.yaml

- task: NuGetToolInstaller@0
inputs:
Expand Down Expand Up @@ -78,71 +75,13 @@ jobs:
- checkout: self
submodules: recursive

- task: UseDotNet@2
displayName: Use .NET Core $(DotNetCoreVersion)
inputs:
version: $(DotNetCoreVersion)

- task: DotNetCoreCLI@2
displayName: Prepare Solution
inputs:
projects: Java.Interop.sln
arguments: '-c $(Build.Configuration) -target:Prepare'

- task: DotNetCoreCLI@2
displayName: Build Solution
inputs:
projects: Java.Interop.sln
arguments: '-c $(Build.Configuration)'

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Interop.Tools.Generator'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\Java.Interop.Tools.Generator-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: generator'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\generator-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: JavaCallableWrappers'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\Java.Interop.Tools.JavaCallableWrappers-Tests.dll
continueOnError: true
- template: templates\install-dependencies.yaml

- task: DotNetCoreCLI@2
displayName: 'Tests: logcat-parse'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\logcat-parse-Tests.dll
continueOnError: true
- template: templates\core-build.yaml

- task: DotNetCoreCLI@2
displayName: 'Tests: ApiXmlAdjuster'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
continueOnError: true
- template: templates\core-tests.yaml

- task: DotNetCoreCLI@2
displayName: 'Tests: Bytecode'
inputs:
command: test
arguments: bin\Test$(Build.Configuration)\Xamarin.Android.Tools.Bytecode-Tests.dll
continueOnError: true

- powershell: |
Write-Host "Current job status is: $env:AGENT_JOBSTATUS"
if ($env:AGENT_JOBSTATUS -eq "SucceededWithIssues") {
Write-Host "##vso[task.complete result=Failed;]DONE"
}
displayName: Fail job if tests failed
- template: templates\fail-on-issue.yaml

- job: mac_build
displayName: Mac - Mono
Expand All @@ -154,15 +93,7 @@ jobs:
- checkout: self
submodules: recursive

- task: UseDotNet@2
displayName: Use .NET Core $(DotNetCoreVersion)
inputs:
version: $(DotNetCoreVersion)

- script: |
dotnet tool install --global boots
boots --stable Mono
displayName: Install Mono-Stable
- template: templates\install-dependencies.yaml

- script: make prepare CONFIGURATION=$(Build.Configuration)
displayName: make prepare
Expand Down Expand Up @@ -200,3 +131,24 @@ jobs:
inputs:
ArtifactName: debug
condition: succeededOrFailed()

- job: mac_dotnet_build
displayName: Mac - .NET Core
pool: $(HostedMac)
timeoutInMinutes: 20
workspace:
clean: all
steps:
- checkout: self
submodules: recursive

- template: templates\install-dependencies.yaml

- script: make prepare-core CONFIGURATION=$(Build.Configuration)
displayName: make prepare-core

- template: templates\core-build.yaml

- template: templates\core-tests.yaml

- template: templates\fail-on-issue.yaml
15 changes: 15 additions & 0 deletions build-tools/automation/templates/core-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
condition: succeeded()

steps:
- task: DotNetCoreCLI@2
displayName: Prepare Solution
inputs:
projects: Java.Interop.sln
arguments: '-c $(Build.Configuration) -target:Prepare'

- task: DotNetCoreCLI@2
displayName: Build Solution
inputs:
projects: Java.Interop.sln
arguments: '-c $(Build.Configuration) -m:1'
74 changes: 74 additions & 0 deletions build-tools/automation/templates/core-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
parameters:
condition: succeeded()

steps:
- task: DotNetCoreCLI@2
displayName: 'Tests: generator'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/generator-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: JavaCallableWrappers'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaCallableWrappers-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: logcat-parse'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/logcat-parse-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: ApiXmlAdjuster'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: Bytecode'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.Bytecode-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Interop.Tools.Generator'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.Generator-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Interop.Tools.JavaSource'
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaSource-Tests.dll
continueOnError: true

# Running native Java.Interop tests are not yet supported on .NET Core
#- task: DotNetCoreCLI@2
# displayName: 'Tests: Java.Interop'
# inputs:
# command: test
# arguments: bin/Test$(Build.Configuration)/Java.Interop-Tests.dll
# continueOnError: true

#- task: DotNetCoreCLI@2
# displayName: 'Tests: Java.Interop.Dynamic'
# inputs:
# command: test
# arguments: bin/Test$(Build.Configuration)/Java.Interop.Dynamic-Tests.dll
# continueOnError: true

#- task: DotNetCoreCLI@2
# displayName: 'Tests: Java.Interop.Export'
# inputs:
# command: test
# arguments: bin/Test$(Build.Configuration)/Java.Interop.Export-Tests.dll
# continueOnError: true
10 changes: 10 additions & 0 deletions build-tools/automation/templates/fail-on-issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
condition: succeeded()

steps:
- powershell: |
Write-Host "Current job status is: $env:AGENT_JOBSTATUS"
if ($env:AGENT_JOBSTATUS -eq "SucceededWithIssues") {
Write-Host "##vso[task.complete result=Failed;]DONE"
}
displayName: fail if any issues occurred
14 changes: 14 additions & 0 deletions build-tools/automation/templates/install-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
condition: succeeded()

steps:
- task: UseDotNet@2
displayName: Use .NET Core $(DotNetCoreVersion)
inputs:
version: $(DotNetCoreVersion)

- script: |
dotnet tool install --global boots
boots --stable Mono
displayName: Install Mono-Stable
condition: and(succeeded(), eq(variables['agent.os'], 'Darwin'))
3 changes: 3 additions & 0 deletions build-tools/jnienv-gen/jnienv-gen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<OutputPath>$(BuildToolOutputFullPath)</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>
</Project>
File renamed without changes.
4 changes: 4 additions & 0 deletions samples/Hello/Hello.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<OutputPath>$(TestOutputFullPath)</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Java.Interop\Java.Interop.csproj" />
<ProjectReference Include="..\..\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj" />
Expand Down
15 changes: 4 additions & 11 deletions src/Java.Interop/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(BuildToolOutputFullPath)jnienv-gen.dll</_JNIEnvGenPath>
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(BuildToolOutputFullPath)jnienv-gen.exe</_JNIEnvGenPath>
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">dotnet "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
</PropertyGroup>
<ItemGroup>
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\internal\JavaProxyObject.java" />
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\internal\JavaProxyThrowable.java" />
Expand All @@ -21,16 +14,16 @@
<Target Name="BuildJniEnvironment_g_cs"
BeforeTargets="BeforeCompile"
Inputs="$(_JNIEnvGenPath)"
Outputs="Java.Interop\JniEnvironment.g.cs;$(IntermediateOutputPath)\jni.c">
Outputs="Java.Interop/JniEnvironment.g.cs;$(IntermediateOutputPath)jni.c">
<MakeDir Directories="$(IntermediateOutputPath)" />
<PropertyGroup>
<_AddCompile Condition=" !Exists('Java.Interop\JniEnvironment.g.cs') ">True</_AddCompile>
<_AddCompile Condition=" !Exists('Java.Interop/JniEnvironment.g.cs') ">True</_AddCompile>
</PropertyGroup>
<Exec
Command="$(_RunJNIEnvGen) Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
Command="$(_RunJNIEnvGen) Java.Interop/JniEnvironment.g.cs $(IntermediateOutputPath)jni.c"
/>
<ItemGroup>
<Compile Include="Java.Interop\JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
<Compile Include="Java.Interop/JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
</ItemGroup>
</Target>
<Target Name="BuildInteropJar"
Expand Down
6 changes: 5 additions & 1 deletion src/java-interop/java-interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
</ItemGroup>

<Import Project="java-interop.targets" />


<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
Expand Down
16 changes: 7 additions & 9 deletions src/java-interop/java-interop.targets
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
</PropertyGroup>
<Target Name="BuildJni_c"
Inputs="$(JNIEnvGenPath)\jnienv-gen.exe"
Inputs="$(_JNIEnvGenPath)"
Outputs="jni.c">
<MakeDir Directories="$(OutputPath)" />
<Exec Command="$(Runtime) &quot;$(JNIEnvGenPath)\jnienv-gen.exe&quot; jni.g.cs jni.c" />
<Exec Command="$(_RunJNIEnvGen) jni.g.cs jni.c" />
</Target>

<PropertyGroup>
<_MacLib>$(OutputPath)\lib$(OutputName).dylib</_MacLib>
<_MacLib>$(OutputPath)/lib$(OutputName).dylib</_MacLib>
</PropertyGroup>

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

Expand All @@ -47,7 +44,8 @@
<_Libs>$(MonoLibs)</_Libs>
<_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ')</_Files>
</PropertyGroup>
<Exec Command="gcc -g -shared -m64 -std=c99 -fPIC -o &quot;$(_MacLib)&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
<!-- Use 'IgnoreStandardErrorWarningFormat' to ignore 'ld: warning: text-based stub file X and and library file Y are out of sync' warnings. -->
<Exec Command="gcc -g -shared -m64 -std=c99 -fPIC -o &quot;$(_MacLib)&quot; $(_LinkFlags) $(_Libs) $(_Files)" IgnoreStandardErrorWarningFormat="true" />
<!-- Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) has an incorrect shared library name. Fix it -->
<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;" />
</Target>
Expand All @@ -69,7 +67,7 @@
<_Libs>$(MonoLibs)</_Libs>
<_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ')</_Files>
</PropertyGroup>
<Exec Command="g++ -g -shared -o &quot;$(OutputPath)\lib$(OutputName).so&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
<Exec Command="g++ -g -shared -o &quot;$(OutputPath)/lib$(OutputName).so&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
</Target>

<Target Name="Clean">
Expand Down
Loading

0 comments on commit 1de5501

Please sign in to comment.