-
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
Changes from 22 commits
dfa97b2
6ede47a
e134baf
0969a84
6babd68
c14ebb6
08348d3
e4be4ed
f4d1109
ea91ce2
c45db89
53531d8
d1eadab
94c694a
300f1c4
e17afe3
9468871
e30a583
958372c
95ec6a1
cc2ef8b
7016a28
eb4eab1
14d3b11
5b1b04c
44f83ce
4f46058
0bccb2d
edf6d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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=" '$(OS)' != 'Windows_NT' ">-G "Unix Makefiles"</CmakeGenerator> | ||
<CmakeGenerator Condition=" '$(OS)' == 'Windows_NT' ">-G "NMake Makefiles"</CmakeGenerator> | ||
</PropertyGroup> | ||
</Target> | ||
</Project> |
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> | ||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Maybe it would work to make a small There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,
The attempt to "sanely" quote the directory name results in an invalid command line. Does this mean that <_SourceDir>$(CmakeSourceDir.TrimEnd('%5c'))</_SourceDir> But! If a value can be "part of" the Cmake files, e.g. Cmake variables, those values must use In neither case does a |
||
</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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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_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} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<Project> | ||
|
||
<Import Project="..\..\build-tools\scripts\NativeToolchain.targets" /> | ||
|
||
<PropertyGroup> | ||
<_JavaInteropLibName Condition=" '$(OS)' != 'Windows_NT' And Exists ('/Library/Frameworks/') ">libjava-interop.dylib</_JavaInteropLibName> | ||
<_JavaInteropLibName Condition=" '$(OS)' != 'Windows_NT' And !Exists ('/Library/Frameworks/') ">libjava-interop.so</_JavaInteropLibName> | ||
<_JavaInteropLibName Condition=" '$(OS)' == 'Windows_NT' ">java-interop.dll</_JavaInteropLibName> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a lot of existing code using
I've seen DevCom issues where someone had |
||
</PropertyGroup> | ||
|
||
<ItemGroup Condition=" '$(OS)' == 'Windows_NT' "> | ||
<_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=" '$(OS)' != 'Windows_NT' "> | ||
<_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)"> | ||
<Message Text="# jonp: _Test: Building: @(_JavaInteropNativeLib->'%(Identity) for %(Arch)', ' ')" /> | ||
<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> |
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.
If you can use Ninja, it tends to be faster
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.
Alas, attempting to use
ninja
broke on the macOS CI. :-(