Skip to content

Commit 86bcee0

Browse files
sfreilichcopybara-github
authored andcommitted
Make libink build compatible with Mac on arm64
PiperOrigin-RevId: 900244650
1 parent 9be341f commit 86bcee0

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

ink/geometry/internal/jni/partitioned_mesh_jni.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ JNI_METHOD(geometry, PartitionedMeshNative, jlongArray,
3636
PartitionedMeshNative_fillRenderGroupMeshPointers(native_pointer, group_index,
3737
meshes_ptrs.data());
3838
jlongArray mesh_pointers = env->NewLongArray(group_mesh_count);
39+
// Both `jlong` and `int64_t` are required to be 64-bit integers which JNI and
40+
// Kotlin-cinterop respectively both map to Kotlin `Long`. However, on MacOS
41+
// they represent two distinct (though equivalent) types, `jlong` is `long`
42+
// but `int64_t` is `long long`.
43+
static_assert(sizeof(jlong) == sizeof(int64_t));
3944
env->SetLongArrayRegion(mesh_pointers, 0, group_mesh_count,
40-
meshes_ptrs.data());
45+
reinterpret_cast<jlong*>(meshes_ptrs.data()));
4146
return mesh_pointers;
4247
}
4348

ink/jni/BUILD.bazel

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,24 @@ package(
2121

2222
cc_binary(
2323
name = "libink.so",
24-
additional_linker_inputs = ["jni.lds"],
25-
features = ["-legacy_whole_archive"],
26-
linkopts = [
27-
# Use a linker script to limit exported symbols to JNI functions.
28-
"-Wl,--version-script=$(location :jni.lds)",
24+
additional_linker_inputs = [
25+
"exported_symbols.txt",
26+
"jni.lds",
2927
],
28+
features = ["-legacy_whole_archive"],
29+
linkopts = select({
30+
"@platforms//os:macos": [
31+
"-Wl,-exported_symbols_list,$(location :exported_symbols.txt)",
32+
],
33+
"//conditions:default": [
34+
# Use a linker script to limit exported symbols to JNI functions.
35+
"-Wl,--version-script=$(location :jni.lds)",
36+
],
37+
}),
3038
linkshared = 1,
3139
linkstatic = 1,
3240
deps = [
3341
":android_all_jni",
34-
":jni.lds",
3542
],
3643
)
3744

ink/jni/exported_symbols.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Java_*;
2+
JNI_*;

0 commit comments

Comments
 (0)