Skip to content

Commit

Permalink
Compile zstd-jni from sources
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroPatti authored and apattidb committed Oct 14, 2021
1 parent 2f54194 commit 1f82978
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 21 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
10 changes: 10 additions & 0 deletions distdir_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ java_library(
srcs = glob(["*.java"]),
deps = [
"//third_party/protobuf:protobuf_java",
"//third_party:zstd-jni",
"@zstd-jni//:zstd-jni",
],
)
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/remote/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)
19 changes: 0 additions & 19 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed third_party/zstd-jni/zstd-jni-1.5.0-4-linux_arm.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed third_party/zstd-jni/zstd-jni-1.5.0-4-win_amd64.jar
Binary file not shown.
Binary file removed third_party/zstd-jni/zstd-jni-1.5.0-4-win_x86.jar
Binary file not shown.
Binary file removed third_party/zstd-jni/zstd-jni-1.5.0-4.jar
Binary file not shown.
76 changes: 76 additions & 0 deletions third_party/zstd-jni/zstd-jni.BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)

0 comments on commit 1f82978

Please sign in to comment.