From b61399ca555b758cc54b4a8aacff3cd51226ca2c Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Sat, 13 Jan 2024 19:21:43 -0800 Subject: [PATCH] feat: support for `neverlink` - add transitive inputs for compile-time jars - mark applicable dependencies with `neverlink` Relates-To: sgammon/rules_graalvm#243 Signed-off-by: Sam Gammon --- MODULE.bazel | 36 +++++++++++++++++++++---------- graalvm/artifacts/maven.bzl | 9 ++++++++ internal/maven.bzl | 4 ++-- internal/native_image/classic.bzl | 6 +++++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index fe9ffd18..c4aba1a6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -137,11 +137,31 @@ bazel_dep( # rules_jvm_external ################################################################################ -MAVEN_ARTIFACTS = [ - "org.graalvm.nativeimage:svm:%s" % GRAALVM_SDK_VERSION, - "org.graalvm.sdk:graal-sdk:%s" % GRAALVM_SDK_VERSION, - "org.graalvm.polyglot:polyglot:%s" % GRAALVM_SDK_VERSION, -] +maven = use_extension( + "@rules_jvm_external//:extensions.bzl", + "maven", + dev_dependency = True, +) +maven.artifact( + name = "maven_gvm", + group = "org.graalvm.nativeimage", + artifact= "svm", + version = GRAALVM_SDK_VERSION, + neverlink = True, +) +maven.artifact( + name = "maven_gvm", + group = "org.graalvm.sdk", + artifact= "graal_sdk", + version = GRAALVM_SDK_VERSION, + neverlink = True, +) +maven.artifact( + name = "maven_gvm", + group = "org.graalvm.polyglot", + artifact= "polyglot", + version = GRAALVM_SDK_VERSION, +) MAVEN_REPOSITORIES = [ "https://maven.pkg.st", @@ -149,14 +169,8 @@ MAVEN_REPOSITORIES = [ "https://repo1.maven.org/maven2", ] -maven = use_extension( - "@rules_jvm_external//:extensions.bzl", - "maven", - dev_dependency = True, -) maven.install( name = "maven_gvm", - artifacts = MAVEN_ARTIFACTS, lock_file = "//:maven_install.json", repositories = MAVEN_REPOSITORIES, ) diff --git a/graalvm/artifacts/maven.bzl b/graalvm/artifacts/maven.bzl index 6ad05531..9deb1a77 100644 --- a/graalvm/artifacts/maven.bzl +++ b/graalvm/artifacts/maven.bzl @@ -1,10 +1,18 @@ "Defines Maven helpers and coordinates for GraalVM artifacts." +load("@rules_jvm_external//:specs.bzl", "maven") + # buildifier: disable=name-conventions _MavenArtifacts = struct( + SVM = struct( + artifact = "svm", + group = "org.graalvm.nativeimage", + neverlink = True, + ), SDK = struct( artifact = "graal-sdk", group = "org.graalvm.sdk", + neverlink = True, ), POLYGLOT = struct( artifact = "polyglot", @@ -111,6 +119,7 @@ def _graalvm_maven_artifact(maven, artifact, version): artifact = artifact.artifact, group = artifact.group, version = version, + neverlink = artifact.get("neverlink", False), ) # buildifier: disable=name-conventions diff --git a/internal/maven.bzl b/internal/maven.bzl index 0b977b3e..375acdc7 100644 --- a/internal/maven.bzl +++ b/internal/maven.bzl @@ -2,7 +2,7 @@ load( "//internal:config.bzl", - "GRAALVM_VERSION", + _GRAALVM_VERSION = "GRAALVM_VERSION", ) def graalvm(artifact, repository = "@maven", version = None, group = None): @@ -25,7 +25,7 @@ def graalvm(artifact, repository = "@maven", version = None, group = None): group = (group or artifact.split(":")[0]).replace(".", "_") name = (group and artifact or artifact.split(":")[1]).replace(".", "_") - resolved_version = version or GRAALVM_VERSION + resolved_version = version or _GRAALVM_VERSION if resolved_version: formatted_version = resolved_version.replace(".", "_") diff --git a/internal/native_image/classic.bzl b/internal/native_image/classic.bzl index 62172c67..2e2f3793 100644 --- a/internal/native_image/classic.bzl +++ b/internal/native_image/classic.bzl @@ -27,9 +27,13 @@ def _graal_binary_classic_implementation(ctx): dep[JavaInfo].transitive_runtime_jars for dep in ctx.attr.deps ]) + classpath_neverlink_depset = depset(transitive = [ + dep[JavaInfo].transitive_compile_time_jars + for dep in ctx.attr.deps + ]) direct_inputs = [] - transitive_inputs = [classpath_depset] + transitive_inputs = [classpath_depset, classpath_neverlink_depset] if graal_attr != None: # otherwise, use the legacy code path. the `graal` value is used in the run