diff --git a/third_party/BUILD b/third_party/BUILD index 5c94347e1fab1e..880e928499324a 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -46,7 +46,6 @@ filegroup( "//third_party/py/six:srcs", "//third_party/rules_python:srcs", "//third_party/zlib:srcs", - "//third_party/zstd-jni:srcs", "@googleapis//:srcs", "@remoteapis//:srcs", ], @@ -142,9 +141,6 @@ distrib_java_import( name = "apache_commons_compress", enable_distributions = ["debian"], jars = ["apache_commons_compress/apache-commons-compress-1.19.jar"], - deps = [ - "@com_github_luben_zstd_jni//:zstd-jni", - ], ) distrib_java_import( diff --git a/third_party/zstd-jni/BUILD.bazel b/third_party/zstd-jni/BUILD.bazel deleted file mode 100644 index 399830a9556136..00000000000000 --- a/third_party/zstd-jni/BUILD.bazel +++ /dev/null @@ -1,127 +0,0 @@ -load("@rules_java//java:defs.bzl", "java_library") - -package(default_visibility = ["//visibility:private"]) - -licenses(["notice"]) # BSD License - -filegroup( - name = "srcs", - srcs = glob(["**"]), - visibility = ["//third_party:__pkg__"], -) - -# Below two rules are copied from src/main/native/BUILD. -# Move to some common place? -genrule( - name = "copy_link_jni_md_header", - srcs = select({ - "@io_bazel//src/conditions:darwin": ["@io_bazel//tools/jdk:jni_md_header-darwin"], - "@io_bazel//src/conditions:freebsd": ["@io_bazel//tools/jdk:jni_md_header-freebsd"], - "@io_bazel//src/conditions:openbsd": ["@io_bazel//tools/jdk:jni_md_header-openbsd"], - "@io_bazel//src/conditions:windows": ["@io_bazel//tools/jdk:jni_md_header-windows"], - "@io_bazel//conditions:default": ["@io_bazel//tools/jdk:jni_md_header-linux"], - }), - outs = ["jni_md.h"], - cmd = "cp -f $< $@", -) - -genrule( - name = "copy_link_jni_header", - srcs = ["@io_bazel//tools/jdk:jni_header"], - outs = ["jni.h"], - cmd = "cp -f $< $@", -) - -cc_library( - name = "jni_headers", - hdrs = [ - ":jni.h", - ":jni_md.h", - ], - includes = ["."], -) - -filegroup( - name = "zstd_sources", - srcs = glob([ - "src/main/native/**/*.c", - "src/main/native/**/*.h", - ]), -) - -cc_binary( - name = "libzstd-jni.so", - srcs = [":zstd_sources"], - copts = [ - "-std=c99", - "-Wundef", - "-Wshadow", - "-Wcast-align", - "-Wstrict-prototypes", - "-Wno-unused-variable", - "-Wpointer-arith", - "-Wno-maybe-uninitialized", - ], - includes = [ - "src/main/native", - "src/main/native/common", - "src/main/native/legacy", - ], - linkshared = 1, - local_defines = [ - "ZSTD_MULTITHREAD=1", - "ZSTD_LEGACY_SUPPORT=4", - ], - deps = [":jni_headers"], -) - -cc_binary( - name = "zstd-jni.dll", - srcs = [":zstd_sources"], - includes = [ - "src/main/native", - "src/main/native/common", - "src/main/native/legacy", - ], - linkshared = 1, - local_defines = [ - "ZSTD_MULTITHREAD=1", - "ZSTD_LEGACY_SUPPORT=4", - "_JNI_IMPLEMENTATION_", - ], - deps = [":jni_headers"], -) - -# TODO(bazel-team): Come up with a way to support platform-specific dynamic -# library extensions. This is issue #914. -genrule( - name = "mac-compat", - srcs = [":libzstd-jni.so"], - outs = ["libzstd-jni.dylib"], - cmd = "cp $< $@", - output_to_bindir = 1, -) - -filegroup( - name = "zstd-native-lib", - srcs = select({ - "@io_bazel//src/conditions:darwin": ["libzstd-jni.dylib"], - "@io_bazel//src/conditions:windows": ["zstd-jni.dll"], - "@io_bazel//conditions:default": ["libzstd-jni.so"], - }), - visibility = [ - "@io_bazel//src:__pkg__", - ], -) - -java_library( - name = "zstd-jni", - srcs = glob( - [ - "src/main/java/**/*.java", - ], - ), - data = [":zstd-native-lib"], - visibility = ["//visibility:public"], - deps = ["@bazel_tools//tools/java/runfiles"], -) diff --git a/third_party/zstd-jni/zstd-jni_1.4.5-11.patch b/third_party/zstd-jni/zstd-jni_1.4.5-11.patch deleted file mode 100644 index 0430319d89e54b..00000000000000 --- a/third_party/zstd-jni/zstd-jni_1.4.5-11.patch +++ /dev/null @@ -1,169 +0,0 @@ -diff --git a/src/main/java/com/github/luben/zstd/util/Native.java b/src/main/java/com/github/luben/zstd/util/Native.java ---- a/src/main/java/com/github/luben/zstd/util/Native.java -+++ b/src/main/java/com/github/luben/zstd/util/Native.java -@@ -1,19 +1,13 @@ - package com.github.luben.zstd.util; - --import java.io.File; --import java.io.FileOutputStream; -+import com.google.devtools.build.runfiles.Runfiles; - import java.io.IOException; --import java.io.InputStream; - import java.lang.UnsatisfiedLinkError; - - public enum Native { - ; - - private static final String libnameShort = "zstd-jni"; -- private static final String libname = "lib" + libnameShort; -- private static final String errorMsg = "Unsupported OS/arch, cannot find " + -- resourceName() + " or load " + libnameShort + " from system libraries. Please " + -- "try building from source the jar or providing " + libname + " in your system."; - - private static String osName() { - String os = System.getProperty("os.name").toLowerCase().replace(' ', '_'); -@@ -26,8 +20,12 @@ public enum Native { - } - } - -- private static String osArch() { -- return System.getProperty("os.arch"); -+ private static String libPrefix() { -+ if (osName().contains("win")) { -+ return ""; -+ } else { -+ return "lib"; -+ } - } - - private static String libExtension() { -@@ -40,8 +38,8 @@ public enum Native { - } - } - -- private static String resourceName() { -- return "/" + osName() + "/" + osArch() + "/" + libname + "." + libExtension(); -+ private static String libraryFilename() { -+ return libPrefix() + libnameShort + "." + libExtension(); - } - - private static boolean loaded = false; -@@ -51,99 +49,34 @@ public enum Native { - } - - public static synchronized void load() { -- load(null); -- } -- -- public static synchronized void load(final File tempFolder) { - if (loaded) { - return; - } -- String resourceName = resourceName(); -- -- // try to load the shared library directly from the JAR - try { -- Class.forName("org.osgi.framework.BundleEvent"); // Simple OSGI env. check -- System.loadLibrary(libname); -- loaded = true; -- return; -- } catch (Exception e) { -- // ignore and try other methods -+ System.loadLibrary(libnameShort); -+ } catch (UnsatisfiedLinkError e) { -+ // Try to load from runfiles, esp. for Windows. -+ loadFromRunfiles(); - } -+ loaded = true; -+ } - -- InputStream is = Native.class.getResourceAsStream(resourceName); -- if (is == null) { -- // fall-back to loading the zstd-jni from the system library path. -- // It also cover loading on Android. -- try { -- System.loadLibrary(libnameShort); -- loaded = true; -- return; -- } catch (UnsatisfiedLinkError e) { -- UnsatisfiedLinkError err = new UnsatisfiedLinkError(e.getMessage() + "\n" + errorMsg); -- err.setStackTrace(e.getStackTrace()); -- throw err; -- } -- } -- File tempLib = null; -- FileOutputStream out = null; -+ private static synchronized void loadFromRunfiles() { -+ Runfiles runfiles = null; - try { -- tempLib = File.createTempFile(libname, "." + libExtension(), tempFolder); -- // try to delete on exit, does not work on Windows -- tempLib.deleteOnExit(); -- // copy to tempLib -- out = new FileOutputStream(tempLib); -- byte[] buf = new byte[4096]; -- while (true) { -- int read = is.read(buf); -- if (read == -1) { -- break; -- } -- out.write(buf, 0, read); -- } -- try { -- out.flush(); -- out.close(); -- out = null; -- } catch (IOException e) { -- // ignore -- } -- try { -- System.load(tempLib.getAbsolutePath()); -- } catch (UnsatisfiedLinkError e) { -- // fall-back to loading the zstd-jni from the system library path -- try { -- System.loadLibrary(libnameShort); -- } catch (UnsatisfiedLinkError e1) { -- // display error in case problem with loading from temp folder -- // and from system library path - concatenate both messages -- UnsatisfiedLinkError err = new UnsatisfiedLinkError( -- e.getMessage() + "\n" + -- e1.getMessage() + "\n"+ -- errorMsg); -- err.setStackTrace(e1.getStackTrace()); -- throw err; -- } -- } -- loaded = true; -+ runfiles = Runfiles.create(); - } catch (IOException e) { -- // IO errors in extacting and writing the shared object in the temp dir -- ExceptionInInitializerError err = new ExceptionInInitializerError( -- "Cannot unpack " + libname + ": " + e.getMessage()); -- err.setStackTrace(e.getStackTrace()); -- throw err; -+ throw new RuntimeException("Unable to locate runfiles after failing to load " + -+ libnameShort + " from system. Giving up.", e); - } -- finally { -- try { -- is.close(); -- if (out != null) { -- out.close(); -- } -- if (tempLib != null && tempLib.exists()) { -- tempLib.delete(); -- } -- } catch (IOException e) { -- // ignore -- } -+ String rloc = runfiles.rlocation("com_github_luben_zstd_jni/" + libraryFilename()); -+ if (rloc == null) { -+ throw new RuntimeException("Unable to find JNI library in runfiles: " + rloc); -+ } -+ try { -+ System.load(rloc); -+ } catch (UnsatisfiedLinkError e) { -+ throw new RuntimeException("Unable to load JNI library from runfiles: " + rloc, e); - } - } - }