Skip to content

Commit 71fd598

Browse files
committed
java: Add support for MacOS ; drop shared library linking support
1 parent be122c2 commit 71fd598

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

.github/workflows/gs1encoders.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,11 @@ jobs:
185185
java-version: '17'
186186
distribution: 'temurin'
187187

188-
- name: Java standalone
188+
- name: Java CI
189189
run: |
190190
make -C src/c-lib -j `nproc` libstatic
191191
ant -f src/java/build.xml test
192192
193-
- name: Java linked dynamically
194-
run: |
195-
make -C src/c-lib -j `nproc` libshared
196-
ant -f src/java/build.xml test -Dlink_to_shared_lib=true
197-
198193
ci-wasm:
199194

200195
runs-on: ubuntu-latest

src/java/build.xml

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,53 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
1818
19-
By default, we build a JNI library (.jar and .so files) that is statically
20-
linked against the GS1 Syntax Engine.
19+
This solution builds a JNI library (.jar and .so files) that wraps the GS1
20+
Syntax Engine.
2121
2222
It is sufficient to place the built libgs1encoders.{jar,so} files into
2323
accessible locations, then at runtime:
2424
2525
- Add the .jar file into the classpath.
2626
- Add the directory containing the .so file into java.library.path.
2727
28+
-->
2829

29-
Alternatively, you can build a JNI library that is dynamically linked against
30-
the GS1 Syntax Engine with:
30+
<project name="gs1encoders" default="all" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
3131

32-
ant -Dlink_to_shared_lib=true
32+
<description>
33+
Java binding for GS1 Syntax Engine.
34+
</description>
3335

34-
This assumes that the GS1 Syntax Engine will be made available as a shared
35-
library pre-installed on any system to which projects using this JNI library
36-
are deployed.
36+
<condition property="no_strip" value="true">
37+
<os family="mac"/>
38+
</condition>
3739

38-
In addition to setting the classpath and java.library.path as above, when
39-
linking to a shared library instance of the GS1 Syntax Engine that is not
40-
installed in the system's regular library location, it is necessary to include
41-
the actual location in the dynamic linker's search path. For example by setting
42-
the environment variables:
40+
<condition property="dyn_lib_suffix" value="dylib" else="so">
41+
<os family="mac"/>
42+
</condition>
4343

44-
- LD_LIBRARY_PATH (Linux)
45-
- DYLD_LIBRARY_PATH (MacOS)
44+
<condition property="os.family" value="darwin" else="linux">
45+
<os family="mac"/>
46+
</condition>
4647

47-
-->
48+
<condition property="ldargs" value="" else="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--no-as-needed">
49+
<os family="mac"/>
50+
</condition>
4851

49-
<project name="gs1encoders" default="all" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
52+
<condition property="ldwholearchive" value="" else="-Wl,--whole-archive">
53+
<os family="mac"/>
54+
</condition>
5055

51-
<description>
52-
Java binding for GS1 Syntax Engine.
53-
</description>
56+
<condition property="ldnowholearchive" value="" else="-Wl,--no-whole-archive">
57+
<os family="mac"/>
58+
</condition>
5459

5560
<property name="src" location="."/>
5661
<property name="build" location="build"/>
5762
<property name="classes" location="${build}/classes"/>
5863
<property name="jar" location="libgs1encoders.jar"/>
59-
6064
<property name="wrapfile" location="gs1encoders_wrap.c"/>
61-
<property name="sofile" location="libgs1encoders.so"/>
62-
65+
<property name="sofile" location="libgs1encoders.${dyn_lib_suffix}"/>
6366
<property name="clib" location="../c-lib"/>
6467

6568
<target name="init">
@@ -68,17 +71,15 @@ the environment variables:
6871
</target>
6972

7073
<target name="cc">
71-
<exec executable="gcc" failonerror="true">
74+
<exec executable="cc" failonerror="true">
7275
<arg line="-fPIC -O2 -g -Werror" />
7376
<arg line="-I${clib}" />
7477
<arg line="-I${java.home}/../include" />
75-
<arg line="-I${java.home}/../include/linux" />
78+
<arg line="-I${java.home}/../include/${os.family}" />
7679
<arg line="-I${java.home}/include" />
77-
<arg line="-I${java.home}/include/linux" />
78-
<arg line="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--no-as-needed" />
79-
<arg line="-Wl,--whole-archive -Wl,-Bstatic" unless:set="link_to_shared_lib" />
80-
<arg line="-L${clib}/build -lgs1encoders" />
81-
<arg line="-Wl,--no-whole-archive -Wl,-Bdynamic" unless:set="link_to_shared_lib" />
80+
<arg line="-I${java.home}/include/${os.family}" />
81+
<arg line="${ldargs}" />
82+
<arg line="${ldwholearchive} ${clib}/build/libgs1encoders.a ${ldnowholearchive}" />
8283
<arg line="-shared" />
8384
<arg line="-o ${sofile}" />
8485
<arg line="${wrapfile}" />
@@ -116,13 +117,11 @@ the environment variables:
116117
<javac includes="Example.java" srcdir="${src}" destdir="${src}" includeantruntime="false" classpath=".:${jar}">
117118
<compilerarg value="-Werror"/>
118119
</javac>
119-
<echo unless:set="link_to_shared_lib">To run: java -Djava.library.path=${src} -classpath ${src}:${jar} Example</echo>
120-
<echo if:set="link_to_shared_lib" >To run: LD_LIBRARY_PATH=${clib}/build:$LD_LIBRARY_PATH java -Djava.library.path=${src} -classpath ${src}:${jar} Example</echo>
120+
<echo>To run: java -Djava.library.path=${src} -classpath ${src}:${jar} Example</echo>
121121
</target>
122122

123123
<target name="test" depends="example">
124124
<java classname="Example" failonerror="true" classpath="${src}:${jar}" fork="true">
125-
<env key="LD_LIBRARY_PATH" value="${clib}/build:$LD_LIBRARY_PATH" if:set="link_to_shared_lib" />
126125
<sysproperty key="java.library.path" path="${src}"/>
127126
<arg value="--version"/>
128127
</java>

0 commit comments

Comments
 (0)