diff --git a/BUILD b/BUILD index 31430eddf8fc85..842f18bc52a74c 100644 --- a/BUILD +++ b/BUILD @@ -81,6 +81,7 @@ pkg_tar( "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", "@com_google_protobuf//:protobuf_javalite", + "@zstd-jni//:zstd-jni", ], package_dir = "derived/jars", strip_prefix = "external", diff --git a/WORKSPACE b/WORKSPACE index c3f8ab6859f1c6..9c923c062623ce 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -306,6 +306,14 @@ dist_http_archive( patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN, ) +dist_http_archive( + name = "zstd-jni", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN, + build_file = "//third_party:zstd-jni/zstd-jni.BUILD", + strip_prefix = "zstd-jni-1.5.0-4" +) + http_archive( name = "org_snakeyaml", build_file_content = """ diff --git a/distdir_deps.bzl b/distdir_deps.bzl index 1a59688a13aa3c..49cab613ad4109 100644 --- a/distdir_deps.bzl +++ b/distdir_deps.bzl @@ -172,6 +172,16 @@ DIST_DEPS = { "test_WORKSPACE_files", ], }, + "zstd-jni": { + "archive": "v1.5.0-4.zip", + "sha256": "d320d59b89a163c5efccbe4915ae6a49883ce653cdc670643dfa21c6063108e4", + "urls": [ + "https://github.com/luben/zstd-jni/archive/v1.5.0-4.zip", + ], + "used_in": [ + "additional_distfiles", + ], + }, ################################################### # # Build time dependencies for testing and packaging diff --git a/src/main/java/com/google/devtools/build/lib/remote/zstd/BUILD b/src/main/java/com/google/devtools/build/lib/remote/zstd/BUILD index c7e304ad6983ac..10f331510648cf 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/zstd/BUILD +++ b/src/main/java/com/google/devtools/build/lib/remote/zstd/BUILD @@ -12,6 +12,6 @@ java_library( srcs = glob(["*.java"]), deps = [ "//third_party/protobuf:protobuf_java", - "//third_party:zstd-jni", + "@zstd-jni//:zstd-jni", ], ) diff --git a/src/test/java/com/google/devtools/build/lib/remote/BUILD b/src/test/java/com/google/devtools/build/lib/remote/BUILD index 0694e7cc7821ea..ca1b88f45628e2 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/BUILD +++ b/src/test/java/com/google/devtools/build/lib/remote/BUILD @@ -103,7 +103,6 @@ java_test( "//third_party:netty", "//third_party:rxjava3", "//third_party:truth", - "//third_party:zstd-jni", "//third_party/grpc:grpc-jar", "//third_party/protobuf:protobuf_java", "//third_party/protobuf:protobuf_java_util", @@ -116,5 +115,6 @@ java_test( "@remoteapis//:build_bazel_remote_execution_v2_remote_execution_java_grpc", "@remoteapis//:build_bazel_remote_execution_v2_remote_execution_java_proto", "@remoteapis//:build_bazel_semver_semver_java_proto", + "@zstd-jni//:zstd-jni", ], ) diff --git a/third_party/BUILD b/third_party/BUILD index b6714545e83c8b..eee1ad1c2d8cdf 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -142,25 +142,6 @@ distrib_java_import( jars = ["apache_commons_compress/apache-commons-compress-1.19.jar"], ) -distrib_java_import( - name = "zstd-jni", - enable_distributions = ["debian"], - jars = select({ - "//src/conditions:linux_aarch64": ["zstd-jni/zstd-jni-1.5.0-4-linux_aarch64.jar"], - "//src/conditions:linux_arm": ["zstd-jni/zstd-jni-1.5.0-4-linux_arm.jar"], - "//src/conditions:linux_ppc": ["zstd-jni/zstd-jni-1.5.0-4-linux_ppc64.jar"], - "//src/conditions:linux_ppc64le": ["zstd-jni/zstd-jni-1.5.0-4-linux_ppc64le.jar"], - "//src/conditions:linux_s390x": ["zstd-jni/zstd-jni-1.5.0-4-linux_s390x.jar"], - "//src/conditions:linux_mips64": ["zstd-jni/zstd-jni-1.5.0-4-linux_mips64.jar"], - "//src/conditions:linux_x86_64": ["zstd-jni/zstd-jni-1.5.0-4-linux_amd64.jar"], - "//src/conditions:darwin_x86_64": ["zstd-jni/zstd-jni-1.5.0-4-darwin_x86_64.jar"], - "//src/conditions:darwin_arm64": ["zstd-jni/zstd-jni-1.5.0-4-darwin_aarch64.jar"], - "//src/conditions:freebsd": ["zstd-jni/zstd-jni-1.5.0-4-freebsd_amd64.jar"], - "//src/conditions:windows": ["zstd-jni/zstd-jni-1.5.0-4-win_amd64.jar"], - "//conditions:default": ["zstd-jni/zstd-jni-1.5.0-4.jar"], - }) -) - distrib_java_import( name = "apache_commons_logging", enable_distributions = ["debian"], diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_aarch64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_aarch64.jar deleted file mode 100644 index 53c65f464027a6..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_aarch64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_x86_64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_x86_64.jar deleted file mode 100644 index 072e0e6d8cd0ca..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-darwin_x86_64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-freebsd_amd64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-freebsd_amd64.jar deleted file mode 100644 index acef896ae943dc..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-freebsd_amd64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_aarch64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_aarch64.jar deleted file mode 100644 index 04e4e31fa54ecc..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_aarch64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_amd64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_amd64.jar deleted file mode 100644 index f43547b2d76eff..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_amd64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_arm.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_arm.jar deleted file mode 100644 index e117df912ef8ae..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_arm.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_mips64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_mips64.jar deleted file mode 100644 index 2b93964655a18d..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_mips64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64.jar deleted file mode 100644 index 1443894c94adf0..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64le.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64le.jar deleted file mode 100644 index 167654c9eb316f..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_ppc64le.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_s390x.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_s390x.jar deleted file mode 100644 index 184a3942ac5ade..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-linux_s390x.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-win_amd64.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-win_amd64.jar deleted file mode 100644 index 3a4a75bdbda7ea..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-win_amd64.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4-win_x86.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4-win_x86.jar deleted file mode 100644 index b8b06327be94b2..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4-win_x86.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni-1.5.0-4.jar b/third_party/zstd-jni/zstd-jni-1.5.0-4.jar deleted file mode 100644 index f51ad88288c235..00000000000000 Binary files a/third_party/zstd-jni/zstd-jni-1.5.0-4.jar and /dev/null differ diff --git a/third_party/zstd-jni/zstd-jni.BUILD b/third_party/zstd-jni/zstd-jni.BUILD new file mode 100644 index 00000000000000..e816d61decafa3 --- /dev/null +++ b/third_party/zstd-jni/zstd-jni.BUILD @@ -0,0 +1,76 @@ +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"], +) + +genrule( + name = "native-patched", + srcs = ["src/main/java/com/github/luben/zstd/util/Native.java"], + cmd_bash = "sed 's/String resourceName = resourceName();/String resourceName = \"\\/libzstd-jni.so\";/' $< > $@", + cmd_ps = "$$PSDefaultParameterValues.Remove('*:Encoding'); $$(Get-Content $<) -Replace 'String resourceName = resourceName\\(\\);', 'String resourceName = \"/libzstd-jni.so\";' | Set-Content $@", + outs = ["Native.java"], +) + +java_library( + name = "zstd-jni", + srcs = glob( + [ + "src/main/java/**/*.java", + ], + exclude = [ + "src/main/java/com/github/luben/zstd/util/Native.java", + ], + ) + [ + ":native-patched", + ":version-java", + ], + resources = [":libzstd-jni.so"], + visibility = [ + "//visibility:public", + ], +)