Skip to content

Commit 5c89b90

Browse files
committed
[java-interop] Add java-interop native library.
Context: #13 Context: https://bugzilla.xamarin.com/show_bug.cgi?id=28141 The current "GC bridge" implementation is bunk. Not only is it bunk, it's *horribly broken* bunk (see commit eb69a47). (Well, it was just for bootstrapping anyway...) A "proper" fix is to copy Xamarin.Android's Mono GC bridge implementation, which has been thoroughly debugged by now. This in turn requires that Java.Interop now provide a native library to contain the Mono GC bridge glue code...which raises a new set of conundrums, related to: the build system. The problem is that most of our projects which build native code use make(1) and/or GNU Auto* (autoconf, automake, etc.), which this project isn't currently using, and I don't *want* to use it. (I'm attempting to use the IDE as much as possible, which in turn *usually* means using `xbuild`.) Fortunately, Xamarin Studio supports C projects, which use an MSBuild-compatible project format. (Yay!) Unfortunately, Xamarin Studio is "faking" this support, because it's not a *real* MSBuild project, in that it can't be built with xbuild: $ xbuild src/java-interop/java-interop.cproj error : Target named 'Build' not found in the project. Doh! (Additionally, the contents of the .cproj file bear ~no resemblance to a VS2012-generated .vcproj file, so there's ~no compatibility with Visual Studio here. Windows build support is "when needed.") Furthermore, due to Bug #28141, the shared library that Xamarin Studio generates has the *wrong file name suffix*: it's using `.so` on OS X when it should really be using `.dylib`. There are thus four options for providing a native lib with Java.Interop: 1. Don't. :-) (i.e. build the native lib code in other repo's.) 2. Start using auto* 3. Actually rely on make(1), instead of just having Makefile delegate to xbuild for everything. 4. Hack things until they work. Option (4) is clearly the winner (?), at least for now, so what does *that* look like? First, src/java-interop is the source code for the new native library, currently named libjava-interop.dylib. Secondly, "fix" src/java-interop/java-interop.cproj so that: 1. It has a (manually provided) Build target, thus allowing `xbuild` to build it 2. It has a Xamarin Studio post-build step which renames the output so it creates libjava-interop.dylib instead of libjava-interop.so. 3. xbuild and XS-related sections are updated so that Mono.framework is referenced and mono's headers are available. This allows the project to be built with both xbuild (continuous integration case) and Xamarin Studio ("normal" development case), without introducing the complexities of Auto*. This commit does NOT currently add the GC bridge implementation. This commit is solely about adding build system support for the native lib.
1 parent f33ed5b commit 5c89b90

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

Java.Interop.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{4C173212-3
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop", "src\Java.Interop\Java.Interop.csproj", "{94BD81F7-B06F-4295-9636-F8A3B6BDC762}"
1111
EndProject
12+
Project("{2857B73E-F847-4B02-9238-064979017E93}") = "java-interop", "src\java-interop\java-interop.cproj", "{BB0AB9F7-0979-41A7-B7A9-877260655F94}"
13+
EndProject
1214
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Dynamic", "src\Java.Interop.Dynamic\Java.Interop.Dynamic.csproj", "{AD4468F8-8883-434B-9D4C-E1801BB3B52A}"
1315
EndProject
1416
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Export", "src\Java.Interop.Export\Java.Interop.Export.csproj", "{B501D075-6183-4E1D-92C9-F7B5002475B1}"
@@ -105,6 +107,14 @@ Global
105107
{94BD81F7-B06F-4295-9636-F8A3B6BDC762}.XAIntegrationDebug|Any CPU.Build.0 = XAIntegrationDebug|Any CPU
106108
{94BD81F7-B06F-4295-9636-F8A3B6BDC762}.XAIntegrationRelease|Any CPU.ActiveCfg = XAIntegrationRelease|Any CPU
107109
{94BD81F7-B06F-4295-9636-F8A3B6BDC762}.XAIntegrationRelease|Any CPU.Build.0 = XAIntegrationRelease|Any CPU
110+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.Debug|Any CPU.Build.0 = Debug|Any CPU
112+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
115+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
116+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
117+
{BB0AB9F7-0979-41A7-B7A9-877260655F94}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
108118
{A76309AB-98AC-4AE2-BA30-75481420C52F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
109119
{A76309AB-98AC-4AE2-BA30-75481420C52F}.Debug|Any CPU.Build.0 = Debug|Any CPU
110120
{A76309AB-98AC-4AE2-BA30-75481420C52F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -140,6 +150,7 @@ Global
140150
{C5176170-4025-4A87-B143-11DC64F9BDD1} = {7B305D7C-ADCF-444E-BBFD-4C5CB306B3C6}
141151
{9ECA2816-41D2-4796-8CA2-758EDCFB5C68} = {7B305D7C-ADCF-444E-BBFD-4C5CB306B3C6}
142152
{94BD81F7-B06F-4295-9636-F8A3B6BDC762} = {4C173212-371D-45D8-BA83-9226194F48DC}
153+
{BB0AB9F7-0979-41A7-B7A9-877260655F94} = {4C173212-371D-45D8-BA83-9226194F48DC}
143154
{AD4468F8-8883-434B-9D4C-E1801BB3B52A} = {4C173212-371D-45D8-BA83-9226194F48DC}
144155
{B501D075-6183-4E1D-92C9-F7B5002475B1} = {4C173212-371D-45D8-BA83-9226194F48DC}
145156
{0ADB8D72-7479-49AF-8809-E03AE4A4EAE2} = {647B3EED-85D7-45E6-A297-44DC70C79503}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{BB0AB9F7-0979-41A7-B7A9-877260655F94}</ProjectGuid>
9+
<Compiler>
10+
<Compiler ctype="GccCompiler" />
11+
</Compiler>
12+
<Language>C</Language>
13+
<Target>Bin</Target>
14+
<MacJdkHeadersPath>..\..\LocalJDK\System\Library\Frameworks\JavaVM.framework\Versions\A\Headers</MacJdkHeadersPath>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<OutputPath>..\..\bin\Debug</OutputPath>
19+
<OutputName>java-interop</OutputName>
20+
<CompileTarget>SharedLibrary</CompileTarget>
21+
<DefineSymbols>DEBUG MONODEVELOP</DefineSymbols>
22+
<SourceDirectory>.</SourceDirectory>
23+
<CustomCommands>
24+
<CustomCommands>
25+
<Command type="AfterBuild" command="cp &quot;bin/Debug/libjava-interop.so&quot; &quot;bin/Debug/libjava-interop.dylib&quot;" workingdir="${SolutionDir}" />
26+
</CustomCommands>
27+
</CustomCommands>
28+
<Includes>
29+
<Includes>
30+
<Include>/Library/Frameworks/Mono.framework/Headers/mono-2.0</Include>
31+
<Include>${CombineDir}/LocalJDK/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers</Include>
32+
</Includes>
33+
</Includes>
34+
<ExtraCompilerArguments>-F /Library/Frameworks -framework Mono</ExtraCompilerArguments>
35+
</PropertyGroup>
36+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
37+
<OutputPath>..\..\bin\Release</OutputPath>
38+
<OutputName>java-interop</OutputName>
39+
<CompileTarget>SharedLibrary</CompileTarget>
40+
<OptimizationLevel>3</OptimizationLevel>
41+
<DefineSymbols>MONODEVELOP</DefineSymbols>
42+
<SourceDirectory>.</SourceDirectory>
43+
<CustomCommands>
44+
<CustomCommands>
45+
<Command type="AfterBuild" command="cp &quot;bin/Release/libjava-interop.so&quot; &quot;bin/Release/libjava-interop.dylib&quot;" workingdir="${SolutionDir}" />
46+
</CustomCommands>
47+
</CustomCommands>
48+
</PropertyGroup>
49+
<ItemGroup>
50+
<None Include="java-interop.h" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Compile Include="mono-jni-bridge.c" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Framework Include="Mono" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Include Include="\Library\Frameworks\Mono.framework\Headers\mono-2.0" />
60+
</ItemGroup>
61+
<Target Name="Build" DependsOnTargets="BuildMac" />
62+
<Target Name="BuildMac" Condition=" '$(OS)' != 'Windows_NT' ">
63+
<PropertyGroup>
64+
<_FixedDefines>$(DefineSymbols.Replace(' ', ';'))</_FixedDefines>
65+
</PropertyGroup>
66+
<ItemGroup>
67+
<_Defines Include="$(_FixedDefines)" />
68+
</ItemGroup>
69+
<Exec Command="gcc -g -shared -o &quot;$(OutputPath)\lib$(OutputName).dylib&quot; @(_Defines -&gt; '-D%(Identity)', ' ') @(Compile -&gt; '%(Identity)', ' ') -F /Library/Frameworks @(Framework -&gt; '-framework %(Identity)', ' ') -m32 -I $(MacJdkHeadersPath) @(Include-&gt;'-I %(Identity)', ' ')" />
70+
</Target>
71+
</Project>

src/java-interop/java-interop.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef INC_JAVA_INTEROP_H
2+
#define INC_JAVA_INTEROP_H
3+
4+
/* Add function prototypes here */
5+
6+
#endif /* ndef INC_JAVA_INTEROP_H */

src/java-interop/mono-jni-bridge.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "java-interop.h"
2+
3+
#include <mono/metadata/object.h>
4+
5+
/* Add function definitions here */
6+

0 commit comments

Comments
 (0)