Skip to content

Commit

Permalink
[Java.Interop-PerformanceTests] Support .NET Core 3.1 (#808)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonpryor authored Mar 8, 2021
1 parent daec07b commit 5c756b1
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 44 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<XamarinAndroidToolsDirectory Condition=" '$(XamarinAndroidToolsDirectory)' == '' ">$(MSBuildThisFileDirectory)external\xamarin-android-tools</XamarinAndroidToolsDirectory>
</PropertyGroup>
<PropertyGroup>
<CmakePath Condition=" '$(CmakePath)' == '' ">cmake</CmakePath>
<GradleHome Condition=" '$(GradleHome)' == '' ">$(MSBuildThisFileDirectory)build-tools\gradle</GradleHome>
<GradleWPath Condition=" '$(GradleWPath)' == '' ">$(GradleHome)\gradlew</GradleWPath>
<GradleArgs Condition=" '$(GradleArgs)' == '' ">--stacktrace --no-daemon</GradleArgs>
Expand Down
7 changes: 7 additions & 0 deletions Java.Interop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Localization",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "invocation-overhead", "tests\invocation-overhead\invocation-overhead.csproj", "{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeTiming", "tests\NativeTiming\NativeTiming.csproj", "{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5
Expand Down Expand Up @@ -278,6 +280,10 @@ Global
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26}.Release|Any CPU.Build.0 = Release|Any CPU
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -325,6 +331,7 @@ Global
{6CF94627-BA74-4336-88CD-7EDA20C8F292} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{998D178B-F4C7-48B5-BDEE-44E2F869BB22} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{3CF58D34-693C-408A-BFE7-BC5E4BE44A26} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{BF5A4019-F2FF-45AC-949D-EF7E8C94196B} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29204E0C-382A-49A0-A814-AD7FBF9774A5}
Expand Down
1 change: 1 addition & 0 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ variables:
HostedMacImage: macOS-10.15
HostedWinVS2019: Hosted Windows 2019 with VS2019
NetCoreTargetFrameworkPathSuffix: -netcoreapp3.1
VSInstallRoot: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise

jobs:
- job: windows_build
Expand Down
16 changes: 16 additions & 0 deletions build-tools/automation/templates/core-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,19 @@ steps:
command: test
arguments: bin/Test$(Build.Configuration)/Java.Interop.Export-Tests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Interop'
condition: eq('${{ parameters.runNativeTests }}', 'true')
inputs:
command: test
arguments: bin/Test$(Build.Configuration)/Java.Interop-PerformanceTests.dll
continueOnError: true

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Interop'
condition: eq('${{ parameters.runNativeTests }}', 'true')
inputs:
command: test
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop-PerformanceTests.dll
continueOnError: true
12 changes: 12 additions & 0 deletions tests/Java.Interop-PerformanceTests/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>

<Target Name="BuildPerformanceTestJar"
BeforeTargets="BeforeBuild"
Inputs="@(JavaPerformanceTestJar)"
Outputs="$(OutputPath)performance-test.jar">
<MakeDir Directories="$(IntermediateOutputPath)pt-classes" />
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar->'%(Identity)', ' ')" />
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand All @@ -25,17 +25,12 @@
<ProjectReference Include="..\..\src\Java.Interop\Java.Interop.csproj" />
<ProjectReference Include="..\..\src\Java.Interop.GenericMarshaler\Java.Interop.GenericMarshaler.csproj" />
<ProjectReference Include="..\..\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj" />
<ProjectReference Include="..\NativeTiming\NativeTiming.csproj" />
<ProjectReference Include="..\TestJVM\TestJVM.csproj" />
</ItemGroup>

<ItemGroup>
<JavaPerformanceTestJar Include="$(MSBuildThisFileDirectory)java\com\xamarin\interop\performance\JavaTiming.java" />
</ItemGroup>

<Target Name="BuildPerformanceTestJar" BeforeTargets="BeforeBuild" Inputs="@(JavaPerformanceTestJar)" Outputs="$(OutputPath)performance-test.jar">
<MakeDir Directories="$(IntermediateOutputPath)pt-classes" />
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar->'%(Identity)', ' ')" />
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
</Target>

</Project>
11 changes: 11 additions & 0 deletions tests/NativeTiming/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(CMAKE_OSX_ARCHITECTURES x86_64 arm64)

project(NativeTiming C)

cmake_minimum_required(VERSION 3.10.2)

foreach(dir in ${JDK_INCLUDE_LIST})
include_directories(${dir})
endforeach()

add_library(NativeTiming SHARED timing.c)
113 changes: 113 additions & 0 deletions tests/NativeTiming/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<Project>

<PropertyGroup>
<_NativeTimingLibName Condition=" '$(OS)' != 'Windows_NT' And Exists ('/Library/Frameworks/') ">libNativeTiming.dylib</_NativeTimingLibName>
<_NativeTimingLibName Condition=" '$(OS)' != 'Windows_NT' And !Exists ('/Library/Frameworks/') ">libNativeTiming.so</_NativeTimingLibName>
<_NativeTimingLibName Condition=" '$(OS)' == 'Windows_NT' ">NativeTiming.dll</_NativeTimingLibName>
<_NativeTimingOutputPath>$(OutputPath)$(_NativeTimingLibName)</_NativeTimingOutputPath>
</PropertyGroup>

<ItemGroup>
<None Include="$(_NativeTimingOutputPath)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="_BuildLibs"
BeforeTargets="Build"
DependsOnTargets="_PrepareCmake;_BuildNativeTiming">
</Target>

<Target Name="_GetBuildComands">
<ItemGroup>
<_Vcvarsall
Condition=" '$(VSINSTALLROOT)' != '' And Exists('$(VSINSTALLROOT)') "
Include="$(VSINSTALLROOT)\VC\Auxiliary\Build\vcvarsall.bat"
/>
</ItemGroup>
<PropertyGroup Condition=" '@(_Vcvarsall->Count())' != '0' ">
<_Vcvarsall>%(_Vcvarsall.Identity)</_Vcvarsall>
<_PrepareToolchain>call "$(_Vcvarsall)" x86_amd64 &amp;&amp; </_PrepareToolchain>
</PropertyGroup>
<PropertyGroup>
<_Make Condition=" '$(OS)' != 'Windows_NT' ">make</_Make>
<_Make Condition=" '$(OS)' == 'Windows_NT' ">nmake</_Make>
</PropertyGroup>
</Target>

<Target Name="_PrepareCmake"
DependsOnTargets="_GetBuildComands"
Inputs="CMakeLists.txt;$(MSBuildThisFileFullPath);NativeTiming.csproj"
Outputs="$(IntermediateOutputPath)CMakeCache.txt">
<MakeDir Directories="$(IntermediateOutputPath)" />
<PropertyGroup>
<_JdkDirs>"-DJDK_INCLUDE_LIST=@(JdkIncludePath, ';')"</_JdkDirs>
<_CmakeGenerator Condition=" '$(OS)' != 'Windows_NT' ">-G "Unix Makefiles"</_CmakeGenerator>
<_CmakeGenerator Condition=" '$(OS)' == 'Windows_NT' ">-G "NMake Makefiles"</_CmakeGenerator>
</PropertyGroup>
<Exec
ContinueOnError="WarnAndContinue"
Command="$(_PrepareToolchain) $(CmakePath) $(_CmakeGenerator) -S . -B $(IntermediateOutputPath) $(_JdkDirs)"
/>
<PropertyGroup>
<_CmakeStatus>$(MSBuildLastTaskResult)</_CmakeStatus>
</PropertyGroup>
<ReadLinesFromFile
Condition=" '$(_CmakeStatus)' == 'false' "
File="$(IntermediateOutputPath)CMakeFiles/CMakeOutput.log">
<Output TaskParameter="Lines" ItemName="_CmakeLog" />
</ReadLinesFromFile>
<Message
Condition=" '$(_CmakeStatus)' == 'false' "
Text="CMakeOutput.log"
/>
<Message
Condition=" '$(_CmakeStatus)' == 'false' "
Text="@(_CmakeLog, '
')"
/>
<ReadLinesFromFile
Condition=" '$(_CmakeStatus)' == 'false' "
File="$(IntermediateOutputPath)CMakeFiles/CMakeError.log">
<Output TaskParameter="Lines" ItemName="_CmakeErrorLog" />
</ReadLinesFromFile>
<Message
Condition=" '$(_CmakeStatus)' == 'false' "
Text="CMakeError.log"
/>
<Message
Condition=" '$(_CmakeStatus)' == 'false' "
Text="@(_CmakeErrorLog, '
')"
/>
<Error
Condition=" '$(_CmakeStatus)' == 'false' "
Text="`cmake` failed. See previous messages."
/>
<Touch Files="$(IntermediateOutputPath)CMakeCache.txt" />
</Target>

<Target Name="_BuildNativeTiming"
DependsOnTargets="_GetBuildComands"
Inputs="timing.c"
Outputs="$(_NativeTimingOutputPath)">
<Exec
Command="$(_PrepareToolchain) $(_Make) VERBOSE=1"
WorkingDirectory="$(IntermediateOutputPath)"
/>
<ItemGroup>
<_Libs Include="$(IntermediateOutputPath)$(_NativeTimingLibName)*" />
</ItemGroup>
<Copy
SourceFiles="@(_Libs)"
DestinationFolder="$(OutputPath)"
/>
<Touch Files="$(_NativeTimingOutputPath)" />
</Target>

<Target Name="_Clean"
AfterTargets="Clean">
<Delete Files="$(_NativeTimingOutputPath)" />
</Target>

</Project>
36 changes: 0 additions & 36 deletions tests/NativeTiming/NativeTiming.cproj

This file was deleted.

11 changes: 11 additions & 0 deletions tests/NativeTiming/NativeTiming.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<PropertyGroup>
<OutputPath>$(TestOutputFullPath)</OutputPath>
</PropertyGroup>

</Project>
11 changes: 10 additions & 1 deletion tests/NativeTiming/timing.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include <stdio.h>
#include <sys/time.h>
#include <jni.h>

#if WIN32
#include <windows.h>
#else /* !def WIN32 */
#include <sys/time.h>
#endif /* def WIN32 */

#ifdef PLATFORM_ANDROID
#include <android/log.h>
#endif /* def PLATFORM_ANDROID */
Expand Down Expand Up @@ -211,11 +216,15 @@ foo_init (JNIEnv *env)
static long long
current_time_millis (void)
{
#if defined (WIN32)
return (long long) GetTickCount64 ();
#else /* !def WIN32 */
struct timeval tv;

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

void
Expand Down

0 comments on commit 5c756b1

Please sign in to comment.