Skip to content

Commit

Permalink
Update JNI headers for Bzlmod
Browse files Browse the repository at this point in the history
Centralizes the repository definitions instead of duplicating them.
  • Loading branch information
fmeum committed Aug 29, 2023
1 parent 4f74c0b commit 49a7642
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module(
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")

download_jni_headers = use_extension(
download_jdk_deps = use_extension(
"@rules_jni//bzlmod:extensions.bzl",
"download_jni_headers",
"download_jdk_deps",
)
use_repo(
download_jni_headers,
download_jdk_deps,
"com_github_openjdk_jdk_jni_h",
"com_github_openjdk_jdk_unix_jni_md_h",
"com_github_openjdk_jdk_windows_jni_md_h",
Expand Down
32 changes: 11 additions & 21 deletions bzlmod/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,17 @@
# limitations under the License.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
load("//jni/internal:repositories.bzl", "jdk_deps")

def _download_jni_headers(ctx):
http_file(
name = "com_github_openjdk_jdk_jni_h",
downloaded_file_path = "jni.h",
sha256 = "91f19e0a31a518631ba1ba201238a3af07af754fe541ff1f2a6b62d6358914e7",
urls = ["https://raw.githubusercontent.com/openjdk/jdk/jdk-19%2B36/src/java.base/share/native/include/jni.h"],
)
http_file(
name = "com_github_openjdk_jdk_unix_jni_md_h",
downloaded_file_path = "jni_md.h",
sha256 = "88cb5c33e306900dd35a78d5a439087123b8e91b0986bb5acb42cc9bd2fcc42e",
urls = ["https://raw.githubusercontent.com/openjdk/jdk/jdk-19%2B36/src/java.base/unix/native/include/jni_md.h"],
)
http_file(
name = "com_github_openjdk_jdk_windows_jni_md_h",
downloaded_file_path = "jni_md.h",
sha256 = "dbf96659c4c840b15ef40237db0c65657eca7a70904225fc984deb38999df515",
urls = ["https://raw.githubusercontent.com/openjdk/jdk/jdk-19%2B36/src/java.base/windows/native/include/jni_md.h"],
)
def _download_jdk_deps_impl(ctx):
jdk_deps()
extension_metadata = getattr(ctx, "extension_metadata", None)
if extension_metadata:
return extension_metadata(
root_module_direct_deps = "all",
root_module_direct_dev_deps = [],
)

download_jni_headers = module_extension(
implementation = _download_jni_headers,
download_jdk_deps = module_extension(
implementation = _download_jdk_deps_impl,
)
45 changes: 24 additions & 21 deletions jni/internal/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,7 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_jni_dependencies():
"""Adds all external repositories required for rules_jni.
This should be called from a `WORKSPACE` file after the declaration of `fmeum_rules_jni` itself.
Currently, rules_jni depends on:
* [bazel_skylib](https://github.com/bazelbuild/bazel-skylib)
* [platforms](https://github.com/bazelbuild/platforms)
* individual files of the [OpenJDK](https://github.com/openjdk/jdk)
"""
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)
def jdk_deps():
maybe(
http_file,
name = "com_github_openjdk_jdk_jni_h",
Expand All @@ -57,6 +37,28 @@ Currently, rules_jni depends on:
sha256 = "3cacac1e4802ec246ea7c0c6772d4ac40c9f7255d4df095cfffe601137689771",
urls = ["https://raw.githubusercontent.com/openjdk/jdk/jdk-22%2B12/src/java.base/windows/native/include/jni_md.h"],
)

def rules_jni_dependencies():
"""Adds all external repositories required for rules_jni.
This should be called from a `WORKSPACE` file after the declaration of `fmeum_rules_jni` itself.
Currently, rules_jni depends on:
* [bazel_skylib](https://github.com/bazelbuild/bazel-skylib)
* [platforms](https://github.com/bazelbuild/platforms)
* individual files of the [OpenJDK](https://github.com/openjdk/jdk)
"""
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)
maybe(
http_archive,
name = "platforms",
Expand All @@ -77,3 +79,4 @@ Currently, rules_jni depends on:
"https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz",
],
)
jdk_deps()

0 comments on commit 49a7642

Please sign in to comment.