Skip to content

Commit 5c756b1

Browse files
authored
[Java.Interop-PerformanceTests] Support .NET Core 3.1 (#808)
Context: #808 (comment) Context: https://github.com./dotnet/runtime/blob/e1e46a8d2ca9c2c932c8ceb61f884c7c82351442/eng/native/init-compiler-and-cmake.cmd Context: https://github.com./dotnet/runtime/blob/e1e46a8d2ca9c2c932c8ceb61f884c7c82351442/src/mono/mono.proj#L362 Build `Java.Interop-PerformanceTests.csproj` for `netstandard2.0`, and run it using `dotnet test`. This in turn requires building the `tests/NativeTiming` native library for .NET Core, which in turn requires moving away from the Visual Studio for Mac (née Xamarin Studio) -based `.cproj` file. Replace `NativeTiming.cproj` with a `Microsoft.Build.NoTargets`- based `NativeTiming.csproj` file, so that it can be referenced and built by `msbuild` and `dotnet build`. Update `core-tests.yaml` so that `dotnet test` is used to run both the net472 and netcoreapp3.1 versions of `Java.Interop-PerformanceTests.dll.` Note (for posterity): if a `.*proj` file depends upon `$(Configuration)`, it *must also* be added to `Java.Interop.sln`. Failure to do so will mean that when building the project in *Release* configuration, the *new* project will instead be built in *Debug* configuration, resulting in all manner of head-scratching. ~~ cmake & Windows & C, Oh My! ~~ Add a `cmake`+"Makefile"-based build system for `tests/NativeTiming`. Note that in order to build on Windows, `vcvarsall.bat` *must* be executed *before* using any "native Visual Studio toolchain" commands such as `cl.exe`. Additionally, for reasons not currently understood, running `vcvarsall.bat` *from YAML* -- on the hope/assumption that this would add`cl.exe`/etc. to `%PATH%` and usable everywhere -- *did not work*. (Note that `vcvarsall.bat` requires that you specify which CPU architecture to support; we currently use `x86_amd64`.) In order for the .NET Core-based build to *find* `vcvarsall.bat`, add a new `VSInstallRoot` YAML variable. The .NET Framework-based builds already have a `%VSINSTALLROOT%` environmemnt variable, as do the **Developer Command Prompt for VS\*** commands. Thus, on Windows, we do: call "%VSINSTALLROOT%\VC\Auxiliary\Build\vcvarsall.bat x86_amd64 && ^ cmake -G "NMake Makefiles" -S . -B obj\Debug -DJDK_INCLUDE_LIST=…" … call "%VSINSTALLROOT%\VC\Auxiliary\Build\vcvarsall.bat x86_amd64 && ^ cd obj\Debug && ^ nmake VERSION=1
1 parent daec07b commit 5c756b1

11 files changed

+184
-44
lines changed

Directory.Build.props

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<XamarinAndroidToolsDirectory Condition=" '$(XamarinAndroidToolsDirectory)' == '' ">$(MSBuildThisFileDirectory)external\xamarin-android-tools</XamarinAndroidToolsDirectory>
5151
</PropertyGroup>
5252
<PropertyGroup>
53+
<CmakePath Condition=" '$(CmakePath)' == '' ">cmake</CmakePath>
5354
<GradleHome Condition=" '$(GradleHome)' == '' ">$(MSBuildThisFileDirectory)build-tools\gradle</GradleHome>
5455
<GradleWPath Condition=" '$(GradleWPath)' == '' ">$(GradleHome)\gradlew</GradleWPath>
5556
<GradleArgs Condition=" '$(GradleArgs)' == '' ">--stacktrace --no-daemon</GradleArgs>

Java.Interop.sln

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Localization",
9999
EndProject
100100
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "invocation-overhead", "tests\invocation-overhead\invocation-overhead.csproj", "{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}"
101101
EndProject
102+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeTiming", "tests\NativeTiming\NativeTiming.csproj", "{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}"
103+
EndProject
102104
Global
103105
GlobalSection(SharedMSBuildProjectFiles) = preSolution
104106
src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5
@@ -278,6 +280,10 @@ Global
278280
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Debug|Any CPU.Build.0 = Debug|Any CPU
279281
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Release|Any CPU.ActiveCfg = Release|Any CPU
280282
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Release|Any CPU.Build.0 = Release|Any CPU
283+
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
284+
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Debug|Any CPU.Build.0 = Debug|Any CPU
285+
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Release|Any CPU.ActiveCfg = Release|Any CPU
286+
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Release|Any CPU.Build.0 = Release|Any CPU
281287
EndGlobalSection
282288
GlobalSection(SolutionProperties) = preSolution
283289
HideSolutionNode = FALSE
@@ -325,6 +331,7 @@ Global
325331
{6CF94627-BA74-4336-88CD-7EDA20C8F292} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
326332
{998D178B-F4C7-48B5-BDEE-44E2F869BB22} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
327333
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
334+
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
328335
EndGlobalSection
329336
GlobalSection(ExtensibilityGlobals) = postSolution
330337
SolutionGuid = {29204E0C-382A-49A0-A814-AD7FBF9774A5}

build-tools/automation/azure-pipelines.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ variables:
2222
HostedMacImage: macOS-10.15
2323
HostedWinVS2019: Hosted Windows 2019 with VS2019
2424
NetCoreTargetFrameworkPathSuffix: -netcoreapp3.1
25+
VSInstallRoot: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
2526

2627
jobs:
2728
- job: windows_build

build-tools/automation/templates/core-tests.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,19 @@ steps:
9090
command: test
9191
arguments: bin/Test$(Build.Configuration)/Java.Interop.Export-Tests.dll
9292
continueOnError: true
93+
94+
- task: DotNetCoreCLI@2
95+
displayName: 'Tests: Java.Interop'
96+
condition: eq('${{ parameters.runNativeTests }}', 'true')
97+
inputs:
98+
command: test
99+
arguments: bin/Test$(Build.Configuration)/Java.Interop-PerformanceTests.dll
100+
continueOnError: true
101+
102+
- task: DotNetCoreCLI@2
103+
displayName: 'Tests: Java.Interop'
104+
condition: eq('${{ parameters.runNativeTests }}', 'true')
105+
inputs:
106+
command: test
107+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop-PerformanceTests.dll
108+
continueOnError: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
3+
<Target Name="BuildPerformanceTestJar"
4+
BeforeTargets="BeforeBuild"
5+
Inputs="@(JavaPerformanceTestJar)"
6+
Outputs="$(OutputPath)performance-test.jar">
7+
<MakeDir Directories="$(IntermediateOutputPath)pt-classes" />
8+
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar->'%(Identity)', ' ')" />
9+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
10+
</Target>
11+
12+
</Project>

tests/Java.Interop-PerformanceTests/Java.Interop-PerformanceTests.csproj

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>
@@ -25,17 +25,12 @@
2525
<ProjectReference Include="..\..\src\Java.Interop\Java.Interop.csproj" />
2626
<ProjectReference Include="..\..\src\Java.Interop.GenericMarshaler\Java.Interop.GenericMarshaler.csproj" />
2727
<ProjectReference Include="..\..\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj" />
28+
<ProjectReference Include="..\NativeTiming\NativeTiming.csproj" />
2829
<ProjectReference Include="..\TestJVM\TestJVM.csproj" />
2930
</ItemGroup>
3031

3132
<ItemGroup>
3233
<JavaPerformanceTestJar Include="$(MSBuildThisFileDirectory)java\com\xamarin\interop\performance\JavaTiming.java" />
3334
</ItemGroup>
34-
35-
<Target Name="BuildPerformanceTestJar" BeforeTargets="BeforeBuild" Inputs="@(JavaPerformanceTestJar)" Outputs="$(OutputPath)performance-test.jar">
36-
<MakeDir Directories="$(IntermediateOutputPath)pt-classes" />
37-
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar->'%(Identity)', ' ')" />
38-
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
39-
</Target>
4035

4136
</Project>

tests/NativeTiming/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(CMAKE_OSX_ARCHITECTURES x86_64 arm64)
2+
3+
project(NativeTiming C)
4+
5+
cmake_minimum_required(VERSION 3.10.2)
6+
7+
foreach(dir in ${JDK_INCLUDE_LIST})
8+
include_directories(${dir})
9+
endforeach()
10+
11+
add_library(NativeTiming SHARED timing.c)
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<_NativeTimingLibName Condition=" '$(OS)' != 'Windows_NT' And Exists ('/Library/Frameworks/') ">libNativeTiming.dylib</_NativeTimingLibName>
5+
<_NativeTimingLibName Condition=" '$(OS)' != 'Windows_NT' And !Exists ('/Library/Frameworks/') ">libNativeTiming.so</_NativeTimingLibName>
6+
<_NativeTimingLibName Condition=" '$(OS)' == 'Windows_NT' ">NativeTiming.dll</_NativeTimingLibName>
7+
<_NativeTimingOutputPath>$(OutputPath)$(_NativeTimingLibName)</_NativeTimingOutputPath>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Include="$(_NativeTimingOutputPath)">
12+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
13+
</None>
14+
</ItemGroup>
15+
16+
<Target Name="_BuildLibs"
17+
BeforeTargets="Build"
18+
DependsOnTargets="_PrepareCmake;_BuildNativeTiming">
19+
</Target>
20+
21+
<Target Name="_GetBuildComands">
22+
<ItemGroup>
23+
<_Vcvarsall
24+
Condition=" '$(VSINSTALLROOT)' != '' And Exists('$(VSINSTALLROOT)') "
25+
Include="$(VSINSTALLROOT)\VC\Auxiliary\Build\vcvarsall.bat"
26+
/>
27+
</ItemGroup>
28+
<PropertyGroup Condition=" '@(_Vcvarsall->Count())' != '0' ">
29+
<_Vcvarsall>%(_Vcvarsall.Identity)</_Vcvarsall>
30+
<_PrepareToolchain>call "$(_Vcvarsall)" x86_amd64 &amp;&amp; </_PrepareToolchain>
31+
</PropertyGroup>
32+
<PropertyGroup>
33+
<_Make Condition=" '$(OS)' != 'Windows_NT' ">make</_Make>
34+
<_Make Condition=" '$(OS)' == 'Windows_NT' ">nmake</_Make>
35+
</PropertyGroup>
36+
</Target>
37+
38+
<Target Name="_PrepareCmake"
39+
DependsOnTargets="_GetBuildComands"
40+
Inputs="CMakeLists.txt;$(MSBuildThisFileFullPath);NativeTiming.csproj"
41+
Outputs="$(IntermediateOutputPath)CMakeCache.txt">
42+
<MakeDir Directories="$(IntermediateOutputPath)" />
43+
<PropertyGroup>
44+
<_JdkDirs>"-DJDK_INCLUDE_LIST=@(JdkIncludePath, ';')"</_JdkDirs>
45+
<_CmakeGenerator Condition=" '$(OS)' != 'Windows_NT' ">-G "Unix Makefiles"</_CmakeGenerator>
46+
<_CmakeGenerator Condition=" '$(OS)' == 'Windows_NT' ">-G "NMake Makefiles"</_CmakeGenerator>
47+
</PropertyGroup>
48+
<Exec
49+
ContinueOnError="WarnAndContinue"
50+
Command="$(_PrepareToolchain) $(CmakePath) $(_CmakeGenerator) -S . -B $(IntermediateOutputPath) $(_JdkDirs)"
51+
/>
52+
<PropertyGroup>
53+
<_CmakeStatus>$(MSBuildLastTaskResult)</_CmakeStatus>
54+
</PropertyGroup>
55+
<ReadLinesFromFile
56+
Condition=" '$(_CmakeStatus)' == 'false' "
57+
File="$(IntermediateOutputPath)CMakeFiles/CMakeOutput.log">
58+
<Output TaskParameter="Lines" ItemName="_CmakeLog" />
59+
</ReadLinesFromFile>
60+
<Message
61+
Condition=" '$(_CmakeStatus)' == 'false' "
62+
Text="CMakeOutput.log"
63+
/>
64+
<Message
65+
Condition=" '$(_CmakeStatus)' == 'false' "
66+
Text="@(_CmakeLog, '
67+
')"
68+
/>
69+
<ReadLinesFromFile
70+
Condition=" '$(_CmakeStatus)' == 'false' "
71+
File="$(IntermediateOutputPath)CMakeFiles/CMakeError.log">
72+
<Output TaskParameter="Lines" ItemName="_CmakeErrorLog" />
73+
</ReadLinesFromFile>
74+
<Message
75+
Condition=" '$(_CmakeStatus)' == 'false' "
76+
Text="CMakeError.log"
77+
/>
78+
<Message
79+
Condition=" '$(_CmakeStatus)' == 'false' "
80+
Text="@(_CmakeErrorLog, '
81+
')"
82+
/>
83+
<Error
84+
Condition=" '$(_CmakeStatus)' == 'false' "
85+
Text="`cmake` failed. See previous messages."
86+
/>
87+
<Touch Files="$(IntermediateOutputPath)CMakeCache.txt" />
88+
</Target>
89+
90+
<Target Name="_BuildNativeTiming"
91+
DependsOnTargets="_GetBuildComands"
92+
Inputs="timing.c"
93+
Outputs="$(_NativeTimingOutputPath)">
94+
<Exec
95+
Command="$(_PrepareToolchain) $(_Make) VERBOSE=1"
96+
WorkingDirectory="$(IntermediateOutputPath)"
97+
/>
98+
<ItemGroup>
99+
<_Libs Include="$(IntermediateOutputPath)$(_NativeTimingLibName)*" />
100+
</ItemGroup>
101+
<Copy
102+
SourceFiles="@(_Libs)"
103+
DestinationFolder="$(OutputPath)"
104+
/>
105+
<Touch Files="$(_NativeTimingOutputPath)" />
106+
</Target>
107+
108+
<Target Name="_Clean"
109+
AfterTargets="Clean">
110+
<Delete Files="$(_NativeTimingOutputPath)" />
111+
</Target>
112+
113+
</Project>

tests/NativeTiming/NativeTiming.cproj

-36
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.Build.NoTargets">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<OutputPath>$(TestOutputFullPath)</OutputPath>
9+
</PropertyGroup>
10+
11+
</Project>

tests/NativeTiming/timing.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#include <stdio.h>
2-
#include <sys/time.h>
32
#include <jni.h>
43

4+
#if WIN32
5+
#include <windows.h>
6+
#else /* !def WIN32 */
7+
#include <sys/time.h>
8+
#endif /* def WIN32 */
9+
510
#ifdef PLATFORM_ANDROID
611
#include <android/log.h>
712
#endif /* def PLATFORM_ANDROID */
@@ -211,11 +216,15 @@ foo_init (JNIEnv *env)
211216
static long long
212217
current_time_millis (void)
213218
{
219+
#if defined (WIN32)
220+
return (long long) GetTickCount64 ();
221+
#else /* !def WIN32 */
214222
struct timeval tv;
215223

216224
gettimeofday(&tv, (struct timezone *) NULL);
217225
long long when = tv.tv_sec * 1000LL + tv.tv_usec / 1000;
218226
return when;
227+
#endif /* def WIN32 */
219228
}
220229

221230
void

0 commit comments

Comments
 (0)