diff --git a/third_party/zstd-jni/Native.java.patch b/third_party/zstd-jni/Native.java.patch new file mode 100644 index 00000000000000..4990d14a728b81 --- /dev/null +++ b/third_party/zstd-jni/Native.java.patch @@ -0,0 +1,11 @@ +--- a/src/main/java/com/github/luben/zstd/util/Native.java ++++ b/src/main/java/com/github/luben/zstd/util/Native.java +@@ -59,7 +59,7 @@ public enum Native { + if (loaded) { + return; + } +- String resourceName = resourceName(); ++ String resourceName = "/libzstd-jni.so"; + + String overridePath = System.getProperty(nativePathOverride); + if (overridePath != null) { diff --git a/third_party/zstd-jni/zstd-jni.BUILD b/third_party/zstd-jni/zstd-jni.BUILD new file mode 100644 index 00000000000000..6741c6b200b4f5 --- /dev/null +++ b/third_party/zstd-jni/zstd-jni.BUILD @@ -0,0 +1,62 @@ +cc_binary( + name = "libzstd-jni.so", + srcs = glob([ + "src/main/native/**/*.c", + "src/main/native/**/*.h", + ]) + select({ + "@io_bazel//src/conditions:windows": [ + "src/windows/include/jni_md.h", + "jni/jni.h", + ], + "//conditions:default": [ + "jni/jni_md.h", + "jni/jni.h", + ] + }), + copts = select({ + "@io_bazel//src/conditions:windows": [], + "//conditions:default": [ + "-std=c99", + "-Wno-unused-variable", + "-Wno-sometimes-uninitialized", + ] + }), + linkshared = 1, + includes = select({ + "@io_bazel//src/conditions:windows": ["src/windows/include"], + "//conditions:default": [], + }) + [ + "jni", + "src/main/native", + "src/main/native/common", + ], + local_defines = [ + "ZSTD_LEGACY_SUPPORT=4", + "ZSTD_MULTITHREAD=1", + ] + select({ + "@io_bazel//src/conditions:windows": ["_JNI_IMPLEMENTATION_"], + "//conditions:default": [], + }), +) + + +genrule( + name = "version-java", + cmd_bash = 'echo "package com.github.luben.zstd.util;\n\npublic class ZstdVersion {\n\tpublic static final String VERSION = \\"$$(cat $<)\\";\n}" > $@', + cmd_ps = '$$PSDefaultParameterValues.Remove("*:Encoding"); $$version = (Get-Content $<) -join ""; Set-Content -NoNewline -Path $@ -Value "package com.github.luben.zstd.util;\n\npublic class ZstdVersion {\n\tpublic static final String VERSION = `"$${version}`";\n}\n"', + srcs = ["version"], + outs = ["ZstdVersion.java"], +) + +java_library( + name = "zstd-jni", + srcs = glob([ + "src/main/java/**/*.java", + ]) + [ + ":version-java", + ], + resources = [":libzstd-jni.so"], + visibility = [ + "//visibility:public", + ], +)