Skip to content

Commit d9149d8

Browse files
Replay JNI loader fixes (#745)
## Usage and product changes Replays (#702), updating the jni libraries to include the platform in their filename. e.g. `libtypedb_driver_jni-linux-arm64.so` in place of `libtypedb-driver-jni.so` Since the main maven package for the driver depends on all the jni packages, flattening these jars would lead to two`libtypedb-driver.so` being extracted - only one of which survives - leading to errors when the loader attempts to load it. ## Implementation Check out the files from #702, since nothing on 3.0 had changed since. Looked at the local jar contents with `jar -tf`
1 parent 4d08230 commit d9149d8

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

java/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ deploy_maven(
7171

7272
swig_native_java_library(
7373
name = "typedb_driver_jni",
74+
library_name_with_platform = "typedb_driver_jni-{platform}",
7475
lib = "//c:typedb_driver_clib_headers",
7576
package = "com.typedb.driver.jni",
7677
interface = "//c:typedb_driver.i",

java/common/Loader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@
3838
public class Loader {
3939

4040
private static final String DRIVER_JNI_LIB_RESOURCE = "typedb_driver_jni";
41-
private static final String DRIVER_JNI_LIBRARY_NAME = System.mapLibraryName(DRIVER_JNI_LIB_RESOURCE);
42-
4341
private static final Map<Pair<OS, Arch>, String> DRIVER_JNI_JAR_NAME = Map.of(new Pair<>(OS.WINDOWS, Arch.x86_64), "windows-x86_64",
4442
new Pair<>(OS.MAC, Arch.x86_64), "macosx-x86_64", new Pair<>(OS.MAC, Arch.ARM64), "macosx-arm64", new Pair<>(OS.LINUX, Arch.x86_64),
4543
"linux-x86_64", new Pair<>(OS.LINUX, Arch.ARM64), "linux-arm64");
44+
private static final String DRIVER_JNI_LIBRARY_NAME = Loader.mapLibraryName();
45+
46+
private static String mapLibraryName() {
47+
String fullName = DRIVER_JNI_LIB_RESOURCE + "-" + DRIVER_JNI_JAR_NAME.get(new Pair<>(OS.detect(), Arch.detect()));
48+
return System.mapLibraryName(fullName);
49+
}
4650

4751
private static boolean loaded = false;
4852

java/rules.bzl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,28 @@
1717

1818
load("@typedb_dependencies//builder/swig:java.bzl", "swig_java")
1919

20-
def swig_native_java_library(name, platforms, maven_coordinates, tags=[], **kwargs):
21-
swig_java(
22-
name = "__" + name,
23-
shared_lib_name = name,
24-
tags = tags,
25-
**kwargs,
26-
)
27-
20+
def swig_native_java_library(name, library_name_with_platform, platforms, maven_coordinates, tags=[], **kwargs):
2821
# generate identical libraries with different maven coordinate tags, since we can't 'select' tags
2922
for platform in platforms.values():
23+
platform_specific_name = library_name_with_platform.replace("{platform}", platform)
24+
swig_java(
25+
name = "__" + platform_specific_name,
26+
shared_lib_name = platform_specific_name,
27+
tags = tags,
28+
**kwargs,
29+
)
30+
3031
native.java_library(
31-
name = name + "__native-as__" + platform + "__do_not_reference",
32-
srcs = ["__" + name + "__swig"],
33-
resources = ["lib" + name],
32+
name = platform_specific_name + "__native-as__do_not_reference",
33+
srcs = ["__" + platform_specific_name + "__swig"],
34+
resources = ["lib" + platform_specific_name],
3435
tags = tags + ["maven_coordinates=" + maven_coordinates.replace("{platform}", platform)],
3536
)
3637

3738
native.alias(
3839
name = name,
3940
actual = select({
40-
config: name + "__native-as__" + platform + "__do_not_reference"
41+
config: library_name_with_platform.replace("{platform}", platform) + "__native-as__do_not_reference"
4142
for config, platform in platforms.items()
4243
})
4344
)

0 commit comments

Comments
 (0)