Skip to content

Commit 1b59dcc

Browse files
authored
[java-interop] Update to SDK style project (#657)
Update `java-interop.csproj` to be an SDK-style style. This is a bit tricky because this is not a C# assembly, it is just hijacking a `.csproj` and overriding some targets to build a C lib. It felt cleaner to go with a more "supported" version of doing this, so the project is built on [Microsoft.Build.NoTargets][0], which is designed to run arbitrary commands without building an assembly. Also switches to a stable Mono. Not sure if this is necessary but the more modern the `MSBuild` support when working with SDK style projects, the better. The automatic downloading of the `NoTargets` package didn't work with our `globalPackagesFolder` set to `$\..\packages`, so that was changed to `packages`, which is what XA uses and it works. [0]: https://github.com/microsoft/MSBuildSdks/tree/master/src/NoTargets
1 parent b136ac9 commit 1b59dcc

File tree

4 files changed

+29
-42
lines changed

4 files changed

+29
-42
lines changed

NuGet.Config

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
-->
77
<configuration>
88
<config>
9-
<add key="globalPackagesFolder" value="$\..\packages" />
9+
<add key="globalPackagesFolder" value="packages" />
1010
</config>
1111
</configuration>

build-tools/automation/azure-pipelines.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ jobs:
161161

162162
- script: |
163163
dotnet tool install --global boots
164-
boots https://download.mono-project.com/archive/6.4.0/macos-10-universal/MonoFramework-MDK-6.4.0.198.macos10.xamarin.universal.pkg
165-
displayName: Install Mono 6.4
164+
boots --stable Mono
165+
displayName: Install Mono-Stable
166166
167167
- script: make prepare CONFIGURATION=$(Build.Configuration)
168168
displayName: make prepare

src/java-interop/java-interop.csproj

+17-35
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project Sdk="Microsoft.Build.NoTargets/1.0.110">
32
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ItemType>GenericProject</ItemType>
7-
<ProductVersion>8.0.30703</ProductVersion>
8-
<SchemaVersion>2.0</SchemaVersion>
9-
<ProjectGuid>{BB0AB9F7-0979-41A7-B7A9-877260655F94}</ProjectGuid>
10-
</PropertyGroup>
11-
<Import Project="..\..\Directory.Build.props" />
12-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13-
<DebugSymbols>true</DebugSymbols>
3+
<TargetFramework>net472</TargetFramework>
144
<OutputPath>$(ToolOutputFullPath)</OutputPath>
155
<JNIEnvGenPath>$(BuildToolOutputFullPath)</JNIEnvGenPath>
166
<OutputName>java-interop</OutputName>
17-
<CompileTarget>SharedLibrary</CompileTarget>
18-
<DefineSymbols>DEBUG JI_DLL_EXPORT MONODEVELOP MONO_DLL_EXPORT</DefineSymbols>
7+
<DefineSymbols>JI_DLL_EXPORT MONODEVELOP MONO_DLL_EXPORT</DefineSymbols>
198
<SourceDirectory>.</SourceDirectory>
209
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12+
<DefineConstants>DEBUG $(DefineConstants)</DefineConstants>
13+
</PropertyGroup>
14+
2115
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22-
<OutputPath>$(ToolOutputFullPath)</OutputPath>
23-
<OutputName>java-interop</OutputName>
24-
<JNIEnvGenPath>$(BuildToolOutputFullPath)</JNIEnvGenPath>
25-
<CompileTarget>SharedLibrary</CompileTarget>
2616
<OptimizationLevel>3</OptimizationLevel>
27-
<DefineSymbols>JI_DLL_EXPORT MONODEVELOP MONO_DLL_EXPORT</DefineSymbols>
28-
<SourceDirectory>.</SourceDirectory>
2917
</PropertyGroup>
18+
3019
<ItemGroup>
3120
<ClInclude Include="java-interop.h" />
3221
<ClInclude Include="java-interop-gc-bridge.h" />
3322
<ClInclude Include="java-interop-mono.h" />
3423
</ItemGroup>
24+
3525
<PropertyGroup>
3626
<_MonoIncludePath>@(MonoIncludePath->'%(FullPath)')</_MonoIncludePath>
3727
<_JdkIncludePath>@(JdkIncludePath->'%(FullPath)')</_JdkIncludePath>
3828
</PropertyGroup>
29+
3930
<ItemDefinitionGroup>
4031
<ClCompile>
4132
<PreprocessorDefinitions>$([MSBuild]::Unescape($(DefineSymbols.Replace(' ', ';'))))</PreprocessorDefinitions>
4233
<AdditionalIncludeDirectories>$([MSBuild]::Unescape($(_MonoIncludePath)));$([MSBuild]::Unescape($(_JdkIncludePath)))</AdditionalIncludeDirectories>
4334
</ClCompile>
4435
</ItemDefinitionGroup>
36+
4537
<ItemGroup>
4638
<ClCompile Include="jni.c" />
4739
<ClCompile Include="java-interop.cc" />
@@ -50,20 +42,10 @@
5042
<ClCompile Include="java-interop-mono.cc" />
5143
<ClCompile Include="java-interop-gc-bridge-mono.cc" />
5244
</ItemGroup>
53-
<PropertyGroup>
54-
<BuildDependsOn>
55-
BuildJni_c;
56-
BuildMac;
57-
BuildUnixLibraries;
58-
$(BuildDependsOn)
59-
</BuildDependsOn>
60-
</PropertyGroup>
45+
6146
<Import Project="java-interop.targets" />
47+
6248
<ItemGroup>
63-
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj">
64-
<Project>{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}</Project>
65-
<Name>jnienv-gen</Name>
66-
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
67-
</ProjectReference>
68-
</ItemGroup>
69-
</Project>
49+
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" />
50+
</ItemGroup>
51+
</Project>

src/java-interop/java-interop.targets

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project>
33
<PropertyGroup>
44
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
55
</PropertyGroup>
6-
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" />
76
<Target Name="BuildJni_c"
87
Inputs="$(JNIEnvGenPath)\jnienv-gen.exe"
98
Outputs="jni.c">
109
<MakeDir Directories="$(OutputPath)" />
1110
<Exec Command="$(Runtime) &quot;$(JNIEnvGenPath)\jnienv-gen.exe&quot; jni.g.cs jni.c" />
1211
</Target>
12+
1313
<PropertyGroup>
1414
<_MacLib>$(OutputPath)\lib$(OutputName).dylib</_MacLib>
1515
</PropertyGroup>
16+
1617
<Target Name="_CompileObjectFiles"
1718
Condition=" '$(OS)' != 'Windows_NT' "
19+
DependsOnTargets="BuildJni_c"
1820
Inputs="@(ClCompile)"
1921
Outputs="obj\$(Configuration)\%(Filename).o">
2022
<MakeDir Directories="obj\$(Configuration)" />
@@ -33,7 +35,9 @@
3335
Command="$(_Cc) -c -g $(_Arch) -o &quot;obj\$(Configuration)\%(ClCompile.Filename).o&quot; $(_Def) $(_Inc) &quot;%(Identity)&quot;"
3436
/>
3537
</Target>
38+
3639
<Target Name="BuildMac"
40+
AfterTargets="Build"
3741
Condition=" '$(OS)' != 'Windows_NT' And Exists ('/Library/Frameworks/')"
3842
DependsOnTargets="_CompileObjectFiles"
3943
Inputs="@(ClCompile)"
@@ -47,7 +51,9 @@
4751
<!-- Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) has an incorrect shared library name. Fix it -->
4852
<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;" />
4953
</Target>
54+
5055
<Target Name="BuildUnixLibraries"
56+
AfterTargets="Build"
5157
Condition=" '$(OS)' != 'Windows_NT' And !Exists ('/Library/Frameworks/')"
5258
DependsOnTargets="_CompileObjectFiles"
5359
Inputs="@(ClCompile)"
@@ -65,6 +71,7 @@
6571
</PropertyGroup>
6672
<Exec Command="g++ -g -shared -o &quot;$(OutputPath)\lib$(OutputName).so&quot; $(_LinkFlags) $(_Libs) $(_Files)" />
6773
</Target>
74+
6875
<Target Name="Clean">
6976
<RemoveDir Directories="obj" />
7077
<Delete Files="jni.c" />
@@ -73,6 +80,4 @@
7380
Condition=" '$(OS)' != 'Windows_NT' "
7481
/>
7582
</Target>
76-
<Target Name="Restore">
77-
</Target>
7883
</Project>

0 commit comments

Comments
 (0)