Skip to content

Commit

Permalink
feat: working bzlmod support
Browse files Browse the repository at this point in the history
  • Loading branch information
sgammon committed Aug 13, 2023
1 parent 0829401 commit b3d18cf
Show file tree
Hide file tree
Showing 8 changed files with 670 additions and 6 deletions.
13 changes: 13 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,16 @@ use_repo(
"maven_gvm",
"unpinned_maven_gvm",
)

gvm = use_extension(":extensions.bzl", "graalvm")

gvm.graalvm(
name = "graalvm",
version = "20.0.2",
distribution = "oracle",
java_version = "20",
)
use_repo(
gvm,
"graalvm",
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@rules_graalvm//graalvm:repositories.bzl", "graalvm_repository")

graalvm_repository(
name = "graalvm", # anything you want
version = "20.0.1", # exact version of a GraalVM CE or Oracle GVM release
version = "20.0.2", # exact version of a GraalVM CE or Oracle GVM release
distribution = "oracle", # required for newer GVM releases (`oracle`, `ce`, or `community`)
java_version = "20", # java language version to use/declare
)
Expand Down
1 change: 1 addition & 0 deletions example/bzlmod/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.0-pre.20230724.1
13 changes: 13 additions & 0 deletions example/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ local_path_override(
module_name = "rules_graalvm",
path = "../..",
)

gvm = use_extension("@rules_graalvm//:extensions.bzl", "graalvm")

gvm.graalvm(
name = "graalvm",
version = "20.0.2",
distribution = "oracle",
java_version = "20",
)
use_repo(
gvm,
"graalvm",
)
588 changes: 584 additions & 4 deletions example/bzlmod/MODULE.bazel.lock

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"Defines extensions for use with Bzlmod."

load(
"//graalvm:repositories.bzl",
"graalvm_repository",
)

def _gvm_impl(mctx):
"""Implementation of the GraalVM module extension."""

selected = None
all_components = []
for mod in mctx.modules:
for gvm in mod.tags.graalvm:
selected = gvm
if len(gvm.components) > 0:
all_components += [i for i in gvm.components if not i in all_components]
for extra_component in mod.tags.component:
if extra_component.name not in all_components:
all_components.append(extra_component.name)

graalvm_repository(
name = selected.name,
version = selected.version,
java_version = selected.java_version,
distribution = selected.distribution,
toolchain_prefix = selected.toolchain_prefix,
components = all_components,
setup_actions = selected.setup_actions,
sha256 = selected.sha256,
)


_graalvm = tag_class(attrs = {
"name": attr.string(mandatory = True),
"version": attr.string(mandatory = True),
"java_version": attr.string(mandatory = True),
"distribution": attr.string(mandatory = False),
"toolchain_prefix": attr.string(mandatory = False),
"components": attr.string_list(mandatory = False),
"setup_actions": attr.string_list(mandatory = False),
"sha256": attr.string(mandatory = False),
})

_component = tag_class(attrs = {
"name": attr.string(mandatory = True),
})

graalvm = module_extension(
implementation = _gvm_impl,
tag_classes = {
"graalvm": _graalvm,
"component": _component,
},
)
2 changes: 1 addition & 1 deletion graalvm/nativeimage/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ native_image = rule(
"native_features": attr.string_list(),
"graalvm": attr.label(
cfg = "exec",
default = "@graalvm//:bin/native-image",
default = Label("@graalvm//:bin/native-image"),
allow_files = True,
executable = True,
),
Expand Down
2 changes: 2 additions & 0 deletions graalvm/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"Defines toolchain types for GraalVM."

package(default_visibility = ["//visibility:public"])

# Toolchain type: `graalvm`
#
# Describes a regular GraalVM toolchain; this type is satisfied by either GraalVM Community Edition
Expand Down

0 comments on commit b3d18cf

Please sign in to comment.