Skip to content

Commit

Permalink
feat: graalvm artifact mappings
Browse files Browse the repository at this point in the history
- feat: add struct which defines maven coordinates for well-known
  graalvm maven dependencies

- feat: user-facing API to easily access these coordinates and
  declare them with `rules_jvm_external`

Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Sep 4, 2023
1 parent d08e249 commit 6b178a4
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

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

9 changes: 9 additions & 0 deletions docs/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ bzl_library(
],
)

stardoc(
name = "artifacts",
out = "artifacts.md",
input = "//graalvm/artifacts:maven.bzl",
deps = [
":repo_tools",
],
)

stardoc(
name = "defs",
out = "defs.md",
Expand Down
116 changes: 116 additions & 0 deletions docs/api/artifacts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->

Defines Maven helpers and coordinates for GraalVM artifacts.

<a id="graalvm.artifact"></a>

## graalvm.artifact

<pre>
graalvm.artifact(<a href="#graalvm.artifact-maven">maven</a>, <a href="#graalvm.artifact-artifact">artifact</a>, <a href="#graalvm.artifact-version">version</a>)
</pre>

Helper which declares a Maven artifact using `rules_jvm_external` macros for the provided inputs.

Any struct can be provided as `artifact` which has the `artifact` and `group` properties. For
convenience, well-known GraalVM artifact coordinates are available at `graalvm.catalog`.

Example of use from `WORKSPACE.bazel`:

```starlark
load("@rules_jvm_external//:specs.bzl", "maven")
load("@rules_graalvm//artifacts:maven.bzl", "graalvm")

# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```

Example of use from Bzlmod:

```starlark
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
graalvm = use_extension("@rules_graalvm//:extensions.bzl", "graalvm")

# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```


**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="graalvm.artifact-maven"></a>maven | Maven artifact spawn struct provided by `rules_jvm_external`. | none |
| <a id="graalvm.artifact-artifact"></a>artifact | Artifact to use from `MavenArtifacts`, or a `struct` with `artifact` and `group`. | none |
| <a id="graalvm.artifact-version"></a>version | Version of the artifact to declare. | none |

**RETURNS**

Maven artifact specification.


<a id="graalvm_maven_artifact"></a>

## graalvm_maven_artifact

<pre>
graalvm_maven_artifact(<a href="#graalvm_maven_artifact-maven">maven</a>, <a href="#graalvm_maven_artifact-artifact">artifact</a>, <a href="#graalvm_maven_artifact-version">version</a>)
</pre>

Helper which declares a Maven artifact using `rules_jvm_external` macros for the provided inputs.

Any struct can be provided as `artifact` which has the `artifact` and `group` properties. For
convenience, well-known GraalVM artifact coordinates are available at `graalvm.catalog`.

Example of use from `WORKSPACE.bazel`:

```starlark
load("@rules_jvm_external//:specs.bzl", "maven")
load("@rules_graalvm//artifacts:maven.bzl", "graalvm")

# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```

Example of use from Bzlmod:

```starlark
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
graalvm = use_extension("@rules_graalvm//:extensions.bzl", "graalvm")

# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```


**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="graalvm_maven_artifact-maven"></a>maven | Maven artifact spawn struct provided by `rules_jvm_external`. | none |
| <a id="graalvm_maven_artifact-artifact"></a>artifact | Artifact to use from `MavenArtifacts`, or a `struct` with `artifact` and `group`. | none |
| <a id="graalvm_maven_artifact-version"></a>version | Version of the artifact to declare. | none |

**RETURNS**

Maven artifact specification.


6 changes: 5 additions & 1 deletion graalvm/artifacts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Nothing at this time.
package(default_visibility = ["//visibility:public"])

exports_files([
"maven.bzl",
])
84 changes: 84 additions & 0 deletions graalvm/artifacts/maven.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"Defines Maven helpers and coordinates for GraalVM artifacts."

# buildifier: disable=name-conventions
_MavenArtifacts = struct(
SDK = struct(
artifact = "graal-sdk",
group = "org.graalvm.sdk",
),
TRUFFLE = struct(
artifact = "truffle-api",
group = "org.graalvm.truffle",

NFI = struct(
artifact = "truffle-api",
group = "org.graalvm.truffle",
),
),
)

def _graalvm_maven_artifact(maven, artifact, version):
"""Helper which declares a Maven artifact using `rules_jvm_external` macros for the provided inputs.
Any struct can be provided as `artifact` which has the `artifact` and `group` properties. For
convenience, well-known GraalVM artifact coordinates are available at `graalvm.catalog`.
Example of use from `WORKSPACE.bazel`:
```starlark
load("@rules_jvm_external//:specs.bzl", "maven")
load("@rules_graalvm//artifacts:maven.bzl", "graalvm")
# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```
Example of use from Bzlmod:
```starlark
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
graalvm = use_extension("@rules_graalvm//:extensions.bzl", "graalvm")
# ...
graalvm.artifact(
maven,
artifact = graalvm.catalog.SDK,
version = "23.0.1",
)
```
Args:
maven: Maven artifact spawn struct provided by `rules_jvm_external`.
artifact: Artifact to use from `MavenArtifacts`, or a `struct` with `artifact` and `group`.
version: Version of the artifact to declare.
Returns:
Maven artifact specification.
"""

return maven.artifact(
artifact = artifact.artifact,
group = artifact.group,
version = version,
)


# buildifier: disable=name-conventions
_MavenTools = struct(
catalog = _MavenArtifacts,
artifact = _graalvm_maven_artifact,
)

# Exports.

# buildifier: disable=name-conventions
graalvm = _MavenTools

# buildifier: disable=name-conventions
MavenArtifacts = _MavenArtifacts

graalvm_maven_artifact = _graalvm_maven_artifact

0 comments on commit 6b178a4

Please sign in to comment.