-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[java-interop] Windows build system support #816
Merged
jonpryor
merged 29 commits into
dotnet:main
from
jonpryor:jonp-java-interop-windows-build
Mar 17, 2021
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
dfa97b2
[java-interop] Add `cmake`-based build system
jonpryor 6ede47a
Enable tests on Windows+.NET Core!
jonpryor e134baf
Upload `bin` dir fir windows_dotnet_build
jonpryor 0969a84
Explicitly set RunConfiguration.TargetPlatform=x64 ?
jonpryor 6babd68
What *is* dotnet.exe? 32-bit or 64-bit?
jonpryor c14ebb6
Take 2?
jonpryor 08348d3
*Are* we in a 32-bit process?
jonpryor e4be4ed
Install .NET 5.0.103.
jonpryor f4d1109
Build java-interop.dll for x86, x64
jonpryor ea91ce2
Revert "*Are* we in a 32-bit process?"
jonpryor c45db89
Revert "Take 2?"
jonpryor 53531d8
Revert "What *is* dotnet.exe? 32-bit or 64-bit?"
jonpryor d1eadab
Revert "Explicitly set RunConfiguration.TargetPlatform=x64 ?"
jonpryor 94c694a
Fix NativeTiming build
jonpryor 300f1c4
Now it doesn't build on Windows. Why?
jonpryor e17afe3
Build is failing because the `&&` isn't present.
jonpryor 9468871
Doh; NativeTiming was missing &&
jonpryor e30a583
Cleanup!
jonpryor 958372c
Revert "Now it doesn't build on Windows. Why?"
jonpryor 95ec6a1
Revert "Upload `bin` dir fir windows_dotnet_build"
jonpryor cc2ef8b
Use target batching
jonpryor 7016a28
"Multitarget" NativeTiming as well
jonpryor eb4eab1
Use Ninja instead of Makefiles.
jonpryor 14d3b11
Revert "Use Ninja instead of Makefiles."
jonpryor 5b1b04c
C++ warning cleanup
jonpryor 44f83ce
Avoid $(OS)
jonpryor 4f46058
set CMAKE_C_STANDARD to 11
jonpryor 0bccb2d
Remove diagnostic messages.
jonpryor edf6d9d
ITEM GROUP
jonpryor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project> | ||
<Target Name="GetNativeBuildCommands"> | ||
<ItemGroup Condition=" '$(VSINSTALLROOT)' != '' And Exists('$(VSINSTALLROOT)') "> | ||
<_Vcvarsall | ||
Include="$(VSINSTALLROOT)\VC\Auxiliary\Build\vcvarsall.bat" | ||
/> | ||
</ItemGroup> | ||
<PropertyGroup Condition=" '@(_Vcvarsall->Count())' != '0' "> | ||
<_Vcvarsall>%(_Vcvarsall.Identity)</_Vcvarsall> | ||
<PrepareNativeToolchain>call "$(_Vcvarsall)" </PrepareNativeToolchain> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<CmakeGenerator Condition=" $([MSBuild]::IsOSPlatform ('windows')) ">-G "NMake Makefiles"</CmakeGenerator> | ||
<CmakeGenerator Condition=" !$([MSBuild]::IsOSPlatform ('windows')) ">-G "Unix Makefiles"</CmakeGenerator> | ||
</PropertyGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Prepare" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Target Name="Cmake" | ||
DependsOnTargets="_ValidateCmake;_RunCmake" | ||
/> | ||
<Target Name="_ValidateCmake"> | ||
<Error | ||
Condition=" '$(CmakePath)' == '' " | ||
Text="Set the `%24(CmakePath)` property." | ||
/> | ||
<Error | ||
Condition=" '$(CmakeGenerator)' == '' " | ||
Text="Set the `%24(CmakeGenerator)` property." | ||
/> | ||
<Error | ||
Condition=" '$(CmakeSourceDir)' == '' " | ||
Text="Set the `%24(CmakeSourceDir)` property." | ||
/> | ||
<Error | ||
Condition=" '$(CmakeBuildDir)' == '' " | ||
Text="Set the `%24(CmakeBuildDir)` property." | ||
/> | ||
</Target> | ||
|
||
<Target Name="_RunCmake"> | ||
<PropertyGroup> | ||
<_Prepare>$(PrepareNativeToolchain)</_Prepare> | ||
<_Prepare Condition=" '$(_Prepare)' != '' And !$(_Prepare.Trim().EndsWith('&&')) ">$(_Prepare) &&</_Prepare> | ||
<_SourceDir>$(CmakeSourceDir.Replace('%5c', '/'))</_SourceDir> | ||
<_BuildDir>$(CmakeBuildDir.Replace('%5c', '/'))</_BuildDir> | ||
<_ExtraArgs>$(CmakeExtraArgs.Replace('%5c', '/'))</_ExtraArgs> | ||
</PropertyGroup> | ||
<Exec | ||
ContinueOnError="WarnAndContinue" | ||
Command="$(_Prepare) $(CmakePath) $(CmakeGenerator) -S "$(_SourceDir)" -B "$(_BuildDir)" $(_ExtraArgs) && $(CmakePath) --build "$(_BuildDir)" -v" | ||
/> | ||
<PropertyGroup> | ||
<_CmakeStatus>$(MSBuildLastTaskResult)</_CmakeStatus> | ||
</PropertyGroup> | ||
<ReadLinesFromFile | ||
Condition=" '$(_CmakeStatus)' == 'false' " | ||
File="$(CmakeBuildDir)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="$(CmakeBuildDir)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." | ||
/> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
set(CMAKE_OSX_ARCHITECTURES x86_64 arm64) | ||
|
||
project( | ||
java-interop | ||
DESCRIPTION "Java.Interop native support" | ||
HOMEPAGE_URL "https://github.com/xamarin/java.interop/" | ||
LANGUAGES CXX C | ||
) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
|
||
jonpryor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
option(ENABLE_MONO_INTEGRATION "Require Mono runtime" OFF) | ||
|
||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(JAVA_INTEROP_CORE_SOURCES | ||
java-interop-dlfcn.cc | ||
java-interop-jvm.cc | ||
java-interop-logger.cc | ||
java-interop-util.cc | ||
java-interop.cc | ||
${JNI_C_PATH} | ||
) | ||
set(JAVA_INTEROP_MONO_SOURCES | ||
java-interop-gc-bridge-mono.cc | ||
java-interop-mono.cc | ||
) | ||
|
||
add_compile_definitions("JAVA_INTEROP_DLL_EXPORT") | ||
add_compile_definitions("JI_DLL_EXPORT") | ||
|
||
foreach(dir in ${JDK_INCLUDE_LIST}) | ||
include_directories(${dir}) | ||
endforeach() | ||
|
||
set(LINK_FLAGS "") | ||
|
||
if(ENABLE_MONO_INTEGRATION) | ||
foreach(dir in ${MONO_INCLUDE_LIST}) | ||
include_directories(${dir}) | ||
endforeach() | ||
list(APPEND LINK_FLAGS ${MONO_LINK_FLAGS}) | ||
list(APPEND LINK_FLAGS "-Wl,-undefined -Wl,suppress -Wl,-flat_namespace") | ||
set(JAVA_INTEROP_SOURCES ${JAVA_INTEROP_CORE_SOURCES} ${JAVA_INTEROP_MONO_SOURCES}) | ||
else() | ||
set(JAVA_INTEROP_SOURCES ${JAVA_INTEROP_CORE_SOURCES}) | ||
endif() | ||
|
||
add_library( | ||
java-interop | ||
SHARED | ||
${JAVA_INTEROP_SOURCES} | ||
) | ||
target_link_libraries( | ||
java-interop | ||
${LINK_FLAGS} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<Project> | ||
|
||
<Import Project="..\..\build-tools\scripts\NativeToolchain.targets" /> | ||
|
||
<PropertyGroup> | ||
<_JavaInteropLibName Condition=" $([MSBuild]::IsOSPlatform ('osx')) ">libjava-interop.dylib</_JavaInteropLibName> | ||
<_JavaInteropLibName Condition=" $([MSBuild]::IsOSPlatform ('linux')) ">libjava-interop.so</_JavaInteropLibName> | ||
<_JavaInteropLibName Condition=" $([MSBuild]::IsOSPlatform ('windows')) ">java-interop.dll</_JavaInteropLibName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition=" $([MSBuild]::IsOSPlatform ('windows')) "> | ||
<_JavaInteropNativeLib Include="CMakeLists.txt"> | ||
<Arch>x86_amd64</Arch> | ||
<Dir>win-x64\</Dir> | ||
</_JavaInteropNativeLib> | ||
<_JavaInteropNativeLib Include="CMakeLists.txt"> | ||
<Arch>x86</Arch> | ||
<Dir>win-x86\</Dir> | ||
</_JavaInteropNativeLib> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" !$([MSBuild]::IsOSPlatform ('windows')) "> | ||
<_JavaInteropNativeLib Include="CMakeLists.txt" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="@(_JavaInteropNativeLib->'$(OutputPath)%(Dir)$(_JavaInteropLibName)')"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Link>%(Dir)$(_JavaInteropLibName)</Link> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ClInclude Include="*.h" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ClCompile Include="$(IntermediateOutputPath)jni.c" /> | ||
<ClCompile Include="*.cc" /> | ||
</ItemGroup> | ||
|
||
<Target Name="_BuildJni_c" | ||
Inputs="$(_JNIEnvGenPath)" | ||
Outputs="$(IntermediateOutputPath)jni.c"> | ||
<MakeDir Directories="$(OutputPath)" /> | ||
<Exec Command="$(_RunJNIEnvGen) $(IntermediateOutputPath)jni.g.cs $(IntermediateOutputPath)jni.c" /> | ||
</Target> | ||
|
||
<Target Name="_GetCmakeOptions"> | ||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net472' And '@(MonoIncludePath->Count())' != '0' "> | ||
<_MonoDirs>"-DMONO_INCLUDE_LIST=@(MonoIncludePath, ';')"</_MonoDirs> | ||
<_MonoLib>"-DMONO_LINK_FLAGS=$(MonoLibs)"</_MonoLib> | ||
<_EnableMono>-DENABLE_MONO_INTEGRATION=ON</_EnableMono> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<_JdkDirs>"-DJDK_INCLUDE_LIST=@(JdkIncludePath, ';')"</_JdkDirs> | ||
<_Jni_c>"-DJNI_C_PATH=$(MSBuildThisFileDirectory)$(IntermediateOutputPath)jni.c"</_Jni_c> | ||
<_ExtraArgs>$([MSBuild]::Escape('$(_JdkDirs) $(_Jni_c) $(_EnableMono) $(_MonoDirs) $(_MonoLib)'))</_ExtraArgs> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Target Name="_BuildLibs" | ||
DependsOnTargets="GetNativeBuildCommands;_BuildJni_c;_GetCmakeOptions" | ||
BeforeTargets="Build" | ||
Inputs="@(_JavaInteropNativeLib);$(MSBuildThisFileFullPath);java-interop.csproj;@(ClInclude);@(ClCompile)" | ||
Outputs="$(OutputPath)%(_JavaInteropNativeLib.Dir)$(_JavaInteropLibName)"> | ||
<MakeDir Directories="$(IntermediateOutputPath)%(_JavaInteropNativeLib.Dir)" /> | ||
<ItemGroup> | ||
<_Cmake | ||
Condition=" '$(PrepareNativeToolchain)' != '' " | ||
Include="PrepareNativeToolchain=$(PrepareNativeToolchain) %(_JavaInteropNativeLib.Arch)" | ||
/> | ||
<_Cmake Include="CmakePath=$(CmakePath)" /> | ||
<_Cmake Include="CmakeGenerator=$(CmakeGenerator)" /> | ||
<_Cmake Include="CmakeSourceDir=$(MSBuildThisFileDirectory)" /> | ||
<_Cmake Include="CmakeBuildDir=$(MSBuildThisFileDirectory)$(IntermediateOutputPath)%(_JavaInteropNativeLib.Dir)" /> | ||
<_Cmake Include="CmakeExtraArgs=$(_ExtraArgs)" /> | ||
</ItemGroup> | ||
<MSBuild | ||
Projects="..\..\build-tools\scripts\RunCmake.proj" | ||
Properties="@(_Cmake)" | ||
Targets="Cmake" | ||
/> | ||
<MakeDir Directories="$(OutputPath)%(_JavaInteropNativeLib.Dir)" /> | ||
<ItemGroup> | ||
<_Libs Include="$(IntermediateOutputPath)%(_JavaInteropNativeLib.Dir)$(_JavaInteropLibName)*" /> | ||
</ItemGroup> | ||
<Copy | ||
SourceFiles="@(_Libs)" | ||
DestinationFolder="$(OutputPath)%(_JavaInteropNativeLib.Dir)" | ||
/> | ||
<Touch Files="$(OutputPath)%(_JavaInteropNativeLib.Dir)$(_JavaInteropLibName)" /> | ||
</Target> | ||
|
||
<Target Name="_Clean" | ||
AfterTargets="Clean"> | ||
<Delete Files="@(None)" /> | ||
</Target> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already working, this is fine probably fine. But was the main issue here the
<Exec/>
task?Maybe it would work to make a small
<UnixExec/>
task that subclasses<Exec/>
and replaces all the\
with/
inCommand
? Thenbase.Execute()
would succeed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanpeppers : the problem isn't "unix", the problem is double quotes. :-)
"General guidelines", at least on Unix, is to quote anything which could possibly have a space…such as path names! The problem is when:
\
.The result is that you escape the quote!
Here,
$(_SourceDir)
will be e.g.$(MSBuildThisFileDirectory)
, which aways ends with\
. If we didn't "fix"$(_SourceDir)
, we'd have:The attempt to "sanely" quote the directory name results in an invalid command line.
Does this mean that
s,\,/,g
is "best"? No; we could instead do:But! If a value can be "part of" the Cmake files, e.g. Cmake variables, those values must use
/
, not\
, because Cmake otherwise attempts to treat\
as an escape character. Thus,$(CmakeExtraArgs)
must replace\
with/
, as it contains Cmake property overrides that contain paths.In neither case does a
<UnixExec/>
class help, unless a "command global"s,\,/,g
is desired. Note however that we don't "fixup"$(PrepareNativeToolchain)
or$(CmakePath)
.