Skip to content

Commit

Permalink
feat: dependency support for components
Browse files Browse the repository at this point in the history
- feat: collect and track component dependencies in bindist
- feat: resolve and traverse dependencies (flat) on install
- chore: map initial component dependencies

Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Aug 21, 2023
1 parent 634e1ed commit 0fb0f9e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 24 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GRAALVM_DIST = "ce"
GRAALVM_SDK_VERSION = "23.0.1"
GRAALVM_COMPONENTS = [
"wasm",
"js",
]

##
Expand Down
32 changes: 16 additions & 16 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ stardoc(
"//lib:tooling",
"//lib/nativeimage:internals",
"//lib/nativeimage:rules",
"@bazel_skylib//lib:new_sets",
"@bazel_skylib//lib:paths",
],
)
Expand Down
1 change: 1 addition & 0 deletions internal/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MAVEN_REPOSITORIES = [

GRAALVM_COMPONENTS = [
"wasm",
"js",
]

TARGET_JAVA_VERSIONS = [
Expand Down
31 changes: 29 additions & 2 deletions internal/graalvm_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ load(
"@bazel_skylib//lib:paths.bzl",
"paths",
)
load(
"@bazel_skylib//lib:new_sets.bzl",
"sets",
)
load(
"//internal:jdk_build_file.bzl",
_JDK_BUILD_TEMPLATE = "JDK_BUILD_TEMPLATE",
_JDK_BUILD_TEMPLATE_BAZEL5 = "JDK_BUILD_TEMPLATE_BAZEL5",
)
load(
"//internal:graalvm_bindist_map.bzl",
"ComponentDependencies",
"VmReleaseVersions",
"resolve_distribution_artifact",
Component = "DistributionComponent",
Expand Down Expand Up @@ -151,6 +156,25 @@ alias(
path = path,
)

def _build_component_graph(components):
"""Resolve dependencies for all components, returning each set first in a list which is eventually flattened.
If there are no dependencies, the component itself is returned as the only list member."""

effective_components = []
unique_components = sets.make(components)
found_dependencies = False
for component in components:
deps = ComponentDependencies.get(component, None)
if deps != None:
found_dependencies = True
stanza = [i for i in (deps + [component]) if not sets.contains(unique_components, i)]
[sets.insert(unique_components, i) for i in stanza]
effective_components += stanza
else:
effective_components.append(component)
return effective_components

def _graal_bindist_repository_impl(ctx):
"""Implements the GraalVM repository rule (`graalvm_repository`)."""

Expand Down Expand Up @@ -325,9 +349,12 @@ def _graal_bindist_repository_impl(ctx):
if ctx.attr.components and len(ctx.attr.components) > 0:
ctx.report_progress("Downloading %s GraalVM components" % len(ctx.attr.components))

# address dependencies
resolved_components = _build_component_graph(ctx.attr.components)

all_url_hash_pairs = [
(c, _get_artifact_info(ctx, distribution, platform, version, component = c, strict = False))
for c in ctx.attr.components
for c in resolved_components
]
downloads = []
manual = []
Expand Down Expand Up @@ -369,7 +396,7 @@ def _graal_bindist_repository_impl(ctx):
stderr = exec_result.stderr,
))

all_components.extend(ctx.attr.components)
all_components.extend(resolved_components)
_bin_paths.extend(
[(n, v) for (k, n, v) in _conditional_paths if k in all_components],
)
Expand Down
10 changes: 7 additions & 3 deletions internal/graalvm_bindist_map.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ _DistributionComponent = struct(

# Lists dependencies for known components.
# buildifier: disable=name-conventions
_ComponentDependencies = struct(
JS = [_DistributionComponent.REGEX, _DistributionComponent.ICU4J],
)
_ComponentDependencies = {
"regex": [_DistributionComponent.ICU4J],
"js": [_DistributionComponent.ICU4J, _DistributionComponent.REGEX],
"python": [_DistributionComponent.LLVM],
"ruby": [_DistributionComponent.LLVM],
"llvm-toolchain": [_DistributionComponent.LLVM],
}

# Aligned GraalVM distribution versions.
# buildifier: disable=name-conventions
Expand Down
1 change: 1 addition & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ bzl_library(
":engines",
":java_toolchains",
":tooling",
"@bazel_skylib//lib:new_sets",
],
)

Expand Down
10 changes: 7 additions & 3 deletions tools/scripts/mapping_generator/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@
# Lists dependencies for known components.
# buildifier: disable=name-conventions
_ComponentDependencies = struct(
JS = [_DistributionComponent.REGEX, _DistributionComponent.ICU4J],
)
_ComponentDependencies = {
"regex": [_DistributionComponent.ICU4J],
"js": [_DistributionComponent.ICU4J, _DistributionComponent.REGEX],
"python": [_DistributionComponent.LLVM],
"ruby": [_DistributionComponent.LLVM],
"llvm-toolchain": [_DistributionComponent.LLVM],
}
# Aligned GraalVM distribution versions.
# buildifier: disable=name-conventions
Expand Down

0 comments on commit 0fb0f9e

Please sign in to comment.