From 3971f6442eca64095e7e63d597c9f19e3c5e87fd Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sat, 30 Dec 2023 16:23:08 +0100 Subject: [PATCH] feat (dist): Native Image {WIP, *BROKEN*} --- MODULE.bazel | 19 +++++++++++++++++++ cli/BUILD | 23 +++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b3ce46a70..74716d410 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -60,3 +60,22 @@ bazel_dep(name = "gazelle", version = "0.35.0") go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.host() + +# https://github.com/sgammon/rules_graalvm +bazel_dep(name = "rules_graalvm", version = "0.10.3") + +gvm = use_extension("@rules_graalvm//:extensions.bzl", "graalvm") + +gvm.graalvm( + name = "graalvm", + # TODO Upgrade from 20.0.2 to 21.0.1 (here and also bump java_version below) + version = "20.0.2", # See https://github.com/graalvm/graalvm-ce-builds/releases/ or https://www.graalvm.org/release-notes/ or https://www.graalvm.org/downloads/ ? + distribution = "ce", # `oracle`, `ce`, or `community` + java_version = "20", # `17`, `20`, or `21`, as supported by the version provided + components = [ + # if you need components like `js` or `wasm`, add them here + ], +) +use_repo(gvm, "graalvm") +register_toolchains("@graalvm//:jvm") +register_toolchains("@graalvm//:sdk") diff --git a/cli/BUILD b/cli/BUILD index 88ba32502..a58d4aa8a 100644 --- a/cli/BUILD +++ b/cli/BUILD @@ -15,11 +15,11 @@ # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary", "java_test") +load("@rules_graalvm//graalvm:defs.bzl", "native_image") -java_binary( - name = "enola", +java_library( + name = "enola_library", srcs = glob(["src/main/java/**/*.java"]), - main_class = "dev.enola.cli.Enola", deps = [ "//common/common", "//common/markdown", @@ -40,13 +40,28 @@ java_binary( ], ) +java_binary( + name = "enola", + main_class = "dev.enola.cli.Enola", + runtime_deps = [ + ":enola_library", + ] +) + +native_image( + name = "enola-native", + deps = [":enola_library"], + main_class = "dev.enola.cli.Enola", + native_image_tool = "@graalvm//:native-image", +) + [java_test( name = name[:-len(".java")], size = "small", srcs = glob(["src/test/java/**/*.java"]), resources = glob(["src/test/resources/**/*"]), deps = [ - ":enola", + ":enola_library", "//common/common", "//common/markdown", "//core/impl",