From 4241942f988a4fd08e371a3313aa0b6bb2b061f1 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Sat, 12 Aug 2023 14:21:31 -0700 Subject: [PATCH] feat: introduce `rules_graalvm` via rewrite - feat: ability to distinguish between CE and oracle distributions - feat: ability to install and use graalvm as a java toolchain - feat: ability to download graalvm components - feat: ability to run arbitrary post-setup commands with `gu` - feat: dedicated toolchain types for `graalvm` and `native-image` - feat: provide graalvm sdk aliasing - feat: add makefile - feat: add `aspect` configs - docs: add `toolchain` doc - docs: add `components` doc - docs: add `native-image` doc - docs: add `modern-bazel` doc - fix: use conventional `workspace.bzl` and `rules.bzl` - fix: use conventional `graalvm/` prefix - fix: use on macos aarch64 - chore: add github actions for build/test - chore: support for bazel6, bazel7, upgrade to bazel7 - chore: add distribution download endpoints for newer CE/oracle - chore: docs root in github flavored markdown - chore: rewrite of main project readme --- .aspect/bazelrc/BUILD.bazel | 5 + .aspect/bazelrc/bazel5.bazelrc | 5 + .aspect/bazelrc/bazel6.bazelrc | 15 + .aspect/bazelrc/bazel7.bazelrc | 15 + .aspect/bazelrc/ci.bazelrc | 73 ++ .aspect/bazelrc/convenience.bazelrc | 28 + .aspect/bazelrc/correctness.bazelrc | 62 ++ .aspect/bazelrc/debug.bazelrc | 19 + .aspect/bazelrc/javascript.bazelrc | 28 + .aspect/bazelrc/performance.bazelrc | 38 ++ .bazelrc | 27 +- .bazelversion | 1 + .github/CODEOWNERS | 1 + .github/workflows/module.build.yml | 37 + .github/workflows/module.test.yml | 26 + .github/workflows/on.pr.yml | 10 + .github/workflows/on.push.yml | 12 + .gitignore | 2 + BUILD.bazel | 3 + MODULE.bazel | 99 +++ Makefile | 118 ++++ README.md | 66 +- WORKSPACE | 22 - WORKSPACE.bazel | 120 ++++ WORKSPACE.bzlmod | 48 ++ graal/BUILD => docs/BUILD.bazel | 0 docs/api/BUILD.bazel | 11 + docs/api/defs.md | 36 + docs/api/repositories.md | 47 ++ docs/components.md | 61 ++ docs/modern-bazel.md | 44 ++ docs/native-image.md | 40 ++ docs/toolchain.md | 59 ++ example/BUILD | 24 - example/BUILD.bazel | 0 example/native/BUILD.bazel | 34 + example/{ => native}/Main.java | 4 +- example/{ => native}/reflection.cfg | 0 graal/graal_bindist.bzl | 269 -------- graalvm/BUILD.bazel | 57 ++ graalvm/artifacts/BUILD.bazel | 1 + graalvm/defs.bzl | 10 + graalvm/nativeimage/BUILD.bazel | 15 + .../nativeimage/rules.bzl | 32 +- graalvm/repositories.bzl | 10 + graalvm/toolchain/BUILD.bazel | 13 + internal/BUILD.bazel | 50 ++ internal/config.bzl | 32 + internal/graalvm_bindist.bzl | 634 ++++++++++++++++++ internal/maven.bzl | 43 ++ internal/repositories.bzl | 109 +++ internal/setup.bzl | 30 + maven_install.json | 528 +++++++++++++++ tasks/BUILD | 10 - tasks/src/ci.sh | 26 - tools/bazel | 120 ---- tools/bazel/bazel5.bazelrc | 1 + tools/bazel/bazel6.bazelrc | 1 + tools/bazel/bazel7.bazelrc | 1 + tools/bazel/buildbuddy.bazelrc | 3 + tools/bazel/cache.bazelrc | 15 + tools/bazel/ci.bazelrc | 4 + tools/bazel/java.bazelrc | 12 + tools/bazel/profiles.bazelrc | 13 + tools/scripts/latest_version_tag.sh | 7 + tools/scripts/workspace.sh | 32 + 66 files changed, 2802 insertions(+), 516 deletions(-) create mode 100644 .aspect/bazelrc/BUILD.bazel create mode 100644 .aspect/bazelrc/bazel5.bazelrc create mode 100644 .aspect/bazelrc/bazel6.bazelrc create mode 100644 .aspect/bazelrc/bazel7.bazelrc create mode 100644 .aspect/bazelrc/ci.bazelrc create mode 100644 .aspect/bazelrc/convenience.bazelrc create mode 100644 .aspect/bazelrc/correctness.bazelrc create mode 100644 .aspect/bazelrc/debug.bazelrc create mode 100644 .aspect/bazelrc/javascript.bazelrc create mode 100644 .aspect/bazelrc/performance.bazelrc create mode 100644 .bazelversion create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/module.build.yml create mode 100644 .github/workflows/module.test.yml create mode 100644 .github/workflows/on.pr.yml create mode 100644 .github/workflows/on.push.yml create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel create mode 100644 Makefile delete mode 100644 WORKSPACE create mode 100644 WORKSPACE.bazel create mode 100644 WORKSPACE.bzlmod rename graal/BUILD => docs/BUILD.bazel (100%) create mode 100644 docs/api/BUILD.bazel create mode 100755 docs/api/defs.md create mode 100755 docs/api/repositories.md create mode 100644 docs/components.md create mode 100644 docs/modern-bazel.md create mode 100644 docs/native-image.md create mode 100644 docs/toolchain.md delete mode 100644 example/BUILD create mode 100644 example/BUILD.bazel create mode 100644 example/native/BUILD.bazel rename example/{ => native}/Main.java (60%) rename example/{ => native}/reflection.cfg (100%) delete mode 100644 graal/graal_bindist.bzl create mode 100644 graalvm/BUILD.bazel create mode 100644 graalvm/artifacts/BUILD.bazel create mode 100644 graalvm/defs.bzl create mode 100644 graalvm/nativeimage/BUILD.bazel rename graal/graal.bzl => graalvm/nativeimage/rules.bzl (89%) create mode 100644 graalvm/repositories.bzl create mode 100644 graalvm/toolchain/BUILD.bazel create mode 100644 internal/BUILD.bazel create mode 100644 internal/config.bzl create mode 100644 internal/graalvm_bindist.bzl create mode 100644 internal/maven.bzl create mode 100644 internal/repositories.bzl create mode 100644 internal/setup.bzl create mode 100644 maven_install.json delete mode 100644 tasks/BUILD delete mode 100755 tasks/src/ci.sh delete mode 100755 tools/bazel create mode 100644 tools/bazel/bazel5.bazelrc create mode 100644 tools/bazel/bazel6.bazelrc create mode 100644 tools/bazel/bazel7.bazelrc create mode 100644 tools/bazel/buildbuddy.bazelrc create mode 100644 tools/bazel/cache.bazelrc create mode 100644 tools/bazel/ci.bazelrc create mode 100644 tools/bazel/java.bazelrc create mode 100644 tools/bazel/profiles.bazelrc create mode 100755 tools/scripts/latest_version_tag.sh create mode 100755 tools/scripts/workspace.sh diff --git a/.aspect/bazelrc/BUILD.bazel b/.aspect/bazelrc/BUILD.bazel new file mode 100644 index 00000000..bfa2fb35 --- /dev/null +++ b/.aspect/bazelrc/BUILD.bazel @@ -0,0 +1,5 @@ +"Aspect bazelrc presets; see https://docs.aspect.build/guides/bazelrc" + +load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets") + +write_aspect_bazelrc_presets(name = "update_aspect_bazelrc_presets") diff --git a/.aspect/bazelrc/bazel5.bazelrc b/.aspect/bazelrc/bazel5.bazelrc new file mode 100644 index 00000000..c9d77444 --- /dev/null +++ b/.aspect/bazelrc/bazel5.bazelrc @@ -0,0 +1,5 @@ +# Performance improvement for WORKSPACE evaluation +# of slow rulesets, for example rules_k8s has been +# observed to take 10 seconds without this flag. +# See https://github.com/bazelbuild/bazel/issues/13907 +common --incompatible_existing_rules_immutable_view diff --git a/.aspect/bazelrc/bazel6.bazelrc b/.aspect/bazelrc/bazel6.bazelrc new file mode 100644 index 00000000..11a1c67f --- /dev/null +++ b/.aspect/bazelrc/bazel6.bazelrc @@ -0,0 +1,15 @@ +# Speed up all builds by not checking if external repository files have been modified. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 +build --noexperimental_check_external_repository_files +fetch --noexperimental_check_external_repository_files +query --noexperimental_check_external_repository_files + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --reuse_sandbox_directories + +# Avoid this flag being enabled by remote_download_minimal or remote_download_toplevel +# See https://meroton.com/blog/bazel-6-errors-build-without-the-bytes/ +build --noexperimental_action_cache_store_output_metadata diff --git a/.aspect/bazelrc/bazel7.bazelrc b/.aspect/bazelrc/bazel7.bazelrc new file mode 100644 index 00000000..11a1c67f --- /dev/null +++ b/.aspect/bazelrc/bazel7.bazelrc @@ -0,0 +1,15 @@ +# Speed up all builds by not checking if external repository files have been modified. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 +build --noexperimental_check_external_repository_files +fetch --noexperimental_check_external_repository_files +query --noexperimental_check_external_repository_files + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --reuse_sandbox_directories + +# Avoid this flag being enabled by remote_download_minimal or remote_download_toplevel +# See https://meroton.com/blog/bazel-6-errors-build-without-the-bytes/ +build --noexperimental_action_cache_store_output_metadata diff --git a/.aspect/bazelrc/ci.bazelrc b/.aspect/bazelrc/ci.bazelrc new file mode 100644 index 00000000..4d91ee09 --- /dev/null +++ b/.aspect/bazelrc/ci.bazelrc @@ -0,0 +1,73 @@ +# We recommend enforcing a policy that keeps your CI from being slowed down +# by individual test targets that should be optimized +# or split up into multiple test targets with sharding or manually. +# Set this flag to exclude targets that have their timeout set to eternal (>15m) from running on CI. +# Docs: https://bazel.build/docs/user-manual#test-timeout-filters +test --test_timeout_filters=-eternal + +# Set this flag to enable re-tries of failed tests on CI. +# When any test target fails, try one or more times. This applies regardless of whether the "flaky" +# tag appears on the target definition. +# This is a tradeoff: legitimately failing tests will take longer to report, +# but we can paper over flaky tests that pass most of the time. +# The alternative is to mark every flaky test with the `flaky = True` attribute, but this requires +# the buildcop to make frequent code edits. +# Not recommended for local builds so that the flakiness is observed during development and thus +# is more likely to get fixed. +# Note that when passing after the first attempt, Bazel will give a special "FLAKY" status. +# Docs: https://bazel.build/docs/user-manual#flaky-test-attempts +test --flaky_test_attempts=2 + +# Announce all announces command options read from the bazelrc file(s) when starting up at the +# beginning of each Bazel invocation. This is very useful on CI to be able to inspect what Bazel rc +# settings are being applied on each run. +# Docs: https://bazel.build/docs/user-manual#announce-rc +build --announce_rc + +# Add a timestamp to each message generated by Bazel specifying the time at which the message was +# displayed. +# Docs: https://bazel.build/docs/user-manual#show-timestamps +build --show_timestamps + +# Only show progress every 60 seconds on CI. +# We want to find a compromise between printing often enough to show that the build isn't stuck, +# but not so often that we produce a long log file that requires a lot of scrolling. +# https://bazel.build/reference/command-line-reference#flag--show_progress_rate_limit +build --show_progress_rate_limit=60 + +# Use cursor controls in screen output. +# Docs: https://bazel.build/docs/user-manual#curses +build --curses=yes + +# Use colors to highlight output on the screen. Set to `no` if your CI does not display colors. +# Docs: https://bazel.build/docs/user-manual#color +build --color=yes + +# The terminal width in columns. Configure this to override the default value based on what your CI system renders. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/runtime/UiOptions.java#L151 +build --terminal_columns=143 + +###################################### +# Generic remote cache configuration # +###################################### + +# Only download remote outputs of top level targets to the local machine. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_download_toplevel +build --remote_download_toplevel + +# The maximum amount of time to wait for remote execution and cache calls. +# https://bazel.build/reference/command-line-reference#flag--remote_timeout +build --remote_timeout=3600 + +# Upload locally executed action results to the remote cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results +build --remote_upload_local_results + +# Fall back to standalone local execution strategy if remote execution fails. If the grpc remote +# cache connection fails, it will fail the build, add this so it falls back to the local cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_local_fallback +build --remote_local_fallback + +# Fixes builds hanging on CI that get the TCP connection closed without sending RST packets. +# Docs: https://bazel.build/reference/command-line-reference#flag--grpc_keepalive_time +build --grpc_keepalive_time=30s diff --git a/.aspect/bazelrc/convenience.bazelrc b/.aspect/bazelrc/convenience.bazelrc new file mode 100644 index 00000000..c674569f --- /dev/null +++ b/.aspect/bazelrc/convenience.bazelrc @@ -0,0 +1,28 @@ +# Attempt to build & test every target whose prerequisites were successfully built. +# Docs: https://bazel.build/docs/user-manual#keep-going +build --keep_going + +# Output test errors to stderr so users don't have to `cat` or open test failure log files when test +# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for +# users. +# Docs: https://bazel.build/docs/user-manual#test-output +test --test_output=errors + +# Show the output files created by builds that requested more than one target. This helps users +# locate the build outputs in more cases +# Docs: https://bazel.build/docs/user-manual#show-result +build --show_result=20 + +# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is +# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS +# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is +# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc. +# Docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config +common --enable_platform_specific_config + +# Output a heap dump if an OOM is thrown during a Bazel invocation +# (including OOMs due to `--experimental_oom_more_eagerly_threshold`). +# The dump will be written to `/.heapdump.hprof`. +# You may need to configure CI to capture this artifact and upload for later use. +# Docs: https://bazel.build/reference/command-line-reference#flag--heap_dump_on_oom +common --heap_dump_on_oom diff --git a/.aspect/bazelrc/correctness.bazelrc b/.aspect/bazelrc/correctness.bazelrc new file mode 100644 index 00000000..56fad5fd --- /dev/null +++ b/.aspect/bazelrc/correctness.bazelrc @@ -0,0 +1,62 @@ +# Do not upload locally executed action results to the remote cache. +# This should be the default for local builds so local builds cannot poison the remote cache. +# It should be flipped to `--remote_upload_local_results` on CI +# by using `--bazelrc=.aspect/bazelrc/ci.bazelrc`. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results +build --noremote_upload_local_results + +# Don't allow network access for build actions in the sandbox. +# Ensures that you don't accidentally make non-hermetic actions/tests which depend on remote +# services. +# Developers should tag targets with `tags=["requires-network"]` to opt-out of the enforcement. +# Docs: https://bazel.build/reference/command-line-reference#flag--sandbox_default_allow_network +build --sandbox_default_allow_network=false + +# Warn if a test's timeout is significantly longer than the test's actual execution time. +# Bazel's default for test_timeout is medium (5 min), but most tests should instead be short (1 min). +# While a test's timeout should be set such that it is not flaky, a test that has a highly +# over-generous timeout can hide real problems that crop up unexpectedly. +# For instance, a test that normally executes in a minute or two should not have a timeout of +# ETERNAL or LONG as these are much, much too generous. +# Docs: https://bazel.build/docs/user-manual#test-verbose-timeout-warnings +test --test_verbose_timeout_warnings + +# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server +# notices when a directory changes, if you have a directory listed in the srcs of some target. +# Recommended when using +# [copy_directory](https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md) and +# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories +# inputs to copy_directory actions. +# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args +startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1 + +# Allow exclusive tests to run in the sandbox. Fixes a bug where Bazel doesn't enable sandboxing for +# tests with `tags=["exclusive"]`. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed +test --incompatible_exclusive_test_sandboxed + +# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment +# variables like `PATH` sneak into the build, which can cause massive cache misses when they change. +# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the +# client, but note that doing so can prevent cross-user caching if a shared cache is used. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env +build --incompatible_strict_action_env + +# Propagate tags from a target declaration to the actions' execution requirements. +# Ensures that tags applied in your BUILD file, like `tags=["no-remote"]` +# get propagated to actions created by the rule. +# Without this option, you rely on rules authors to manually check the tags you passed +# and apply relevant ones to the actions they create. +# See https://github.com/bazelbuild/bazel/issues/8830 for details. +# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_allow_tags_propagation +build --experimental_allow_tags_propagation +fetch --experimental_allow_tags_propagation +query --experimental_allow_tags_propagation + +# Do not automatically create `__init__.py` files in the runfiles of Python targets. Fixes the wrong +# default that comes from Google's internal monorepo by using `__init__.py` to delimit a Python +# package. Precisely, when a `py_binary` or `py_test` target has `legacy_create_init` set to `auto (the +# default), it is treated as false if and only if this flag is set. See +# https://github.com/bazelbuild/bazel/issues/10076. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py +build --incompatible_default_to_explicit_init_py diff --git a/.aspect/bazelrc/debug.bazelrc b/.aspect/bazelrc/debug.bazelrc new file mode 100644 index 00000000..bfb0bdd4 --- /dev/null +++ b/.aspect/bazelrc/debug.bazelrc @@ -0,0 +1,19 @@ +############################################################ +# Use `bazel test --config=debug` to enable these settings # +############################################################ + +# Stream stdout/stderr output from each test in real-time. +# Docs: https://bazel.build/docs/user-manual#test-output +test:debug --test_output=streamed + +# Run one test at a time. +# Docs: https://bazel.build/reference/command-line-reference#flag--test_strategy +test:debug --test_strategy=exclusive + +# Prevent long running tests from timing out. +# Docs: https://bazel.build/docs/user-manual#test-timeout +test:debug --test_timeout=9999 + +# Always run tests even if they have cached results. +# Docs: https://bazel.build/docs/user-manual#cache-test-results +test:debug --nocache_test_results diff --git a/.aspect/bazelrc/javascript.bazelrc b/.aspect/bazelrc/javascript.bazelrc new file mode 100644 index 00000000..dc768641 --- /dev/null +++ b/.aspect/bazelrc/javascript.bazelrc @@ -0,0 +1,28 @@ +# Aspect recommended Bazel flags when using Aspect's JavaScript rules: https://github.com/aspect-build/rules_js +# Docs for Node.js flags: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options + +# Support for debugging Node.js tests. Use bazel run with `--config=debug` to turn on the NodeJS +# inspector agent. The node process will break before user code starts and wait for the debugger to +# connect. Pass the --inspect-brk option to all tests which enables the node inspector agent. See +# https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more +# details. +# Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options +run:debug -- --node_options=--inspect-brk + +# Enable runfiles on all platforms. Runfiles are on by default on Linux and MacOS but off on +# Windows. +# +# In general, rules_js and derivate rule sets assume that runfiles are enabled and do not support no +# runfiles case because it does not scale to teach all Node.js tools to use the runfiles manifest. +# +# If you are developing on Windows, you must either run bazel with administrator privileges or +# enable developer mode. If you do not you may hit this error on Windows: +# +# Bazel needs to create symlinks to build the runfiles tree. +# Creating symlinks on Windows requires one of the following: +# 1. Bazel is run with administrator privileges. +# 2. The system version is Windows 10 Creators Update (1703) or later +# and developer mode is enabled. +# +# Docs: https://bazel.build/reference/command-line-reference#flag--enable_runfiles +build --enable_runfiles diff --git a/.aspect/bazelrc/performance.bazelrc b/.aspect/bazelrc/performance.bazelrc new file mode 100644 index 00000000..fff4c7c5 --- /dev/null +++ b/.aspect/bazelrc/performance.bazelrc @@ -0,0 +1,38 @@ +# Speed up all builds by not checking if output files have been modified. Lets you make changes to +# the output tree without triggering a build for local debugging. For example, you can modify +# [rules_js](https://github.com/aspect-build/rules_js) 3rd party npm packages in the output tree +# when local debugging. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/pkgcache/PackageOptions.java#L185 +build --noexperimental_check_output_files +fetch --noexperimental_check_output_files +query --noexperimental_check_output_files + +# Don't apply `--noremote_upload_local_results` and `--noremote_accept_cached` to the disk cache. +# If you have both `--noremote_upload_local_results` and `--disk_cache`, then this fixes a bug where +# Bazel doesn't write to the local disk cache as it treats as a remote cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_remote_results_ignore_disk +build --incompatible_remote_results_ignore_disk + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# No longer experimental in Bazel 6: https://github.com/bazelbuild/bazel/commit/c1a95501a5611878e5cc43a3cc531f2b9e47835b +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --experimental_reuse_sandbox_directories + +# Do not build runfiles symlink forests for external repositories under +# `.runfiles/wsname/external/repo` (in addition to `.runfiles/repo`). This reduces runfiles & +# sandbox creation times & prevents accidentally depending on this feature which may flip to off by +# default in the future. Note, some rules may fail under this flag, please file issues with the rule +# author. +# Docs: https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles +build --nolegacy_external_runfiles + +# Some actions are always IO-intensive but require little compute. It's wasteful to put the output +# in the remote cache, it just saturates the network and fills the cache storage causing earlier +# evictions. It's also not worth sending them for remote execution. +# For actions like PackageTar it's usually faster to just re-run the work locally every time. +# You'll have to look at an execution log to figure out what other action mnemonics you care about. +# In some cases you may need to patch rulesets to add a mnemonic to actions that don't have one. +# https://bazel.build/reference/command-line-reference#flag--modify_execution_info +build --modify_execution_info=PackageTar=+no-remote diff --git a/.bazelrc b/.bazelrc index eecdd933..7e03bfeb 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,16 +1,25 @@ -common --announce_rc +common:verbose --announce_rc + +# Import Aspect bazelrc presets +import %workspace%/.aspect/bazelrc/bazel7.bazelrc +import %workspace%/.aspect/bazelrc/convenience.bazelrc +import %workspace%/.aspect/bazelrc/correctness.bazelrc +import %workspace%/.aspect/bazelrc/debug.bazelrc +import %workspace%/.aspect/bazelrc/performance.bazelrc + +# Import project-level presets +import %workspace%/tools/bazel/bazel7.bazelrc +import %workspace%/tools/bazel/buildbuddy.bazelrc +import %workspace%/tools/bazel/cache.bazelrc +import %workspace%/tools/bazel/ci.bazelrc +import %workspace%/tools/bazel/java.bazelrc + common --color=auto -build --experimental_strict_action_env -build --worker_max_instances=4 build --worker_sandboxing build --verbose_failures -test --test_output=all -test --test_env=PATH - -common:v0.24 --config=noop -common:v0.26 --config=noop - # pick something trivial as a "noop" common:noop --logging=3 + +try-import %workspace%/local.bazelrc diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..a585a9bd --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.0.0-pre.20230724.1 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..e84bec6a --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +*.* @sgammon diff --git a/.github/workflows/module.build.yml b/.github/workflows/module.build.yml new file mode 100644 index 00000000..ba09c099 --- /dev/null +++ b/.github/workflows/module.build.yml @@ -0,0 +1,37 @@ +name: "Build" + +on: + workflow_dispatch: {} + workflow_call: + secrets: + BUILDBUDDY_APIKEY: + required: true + BUILDLESS_APIKEY: + required: true + +jobs: + build: + name: "Build" + runs-on: ubuntu-latest + steps: + - name: "Setup: Checkout" + uses: actions/checkout@v3 + - name: "Setup: Bazel" + uses: bazelbuild/setup-bazelisk@v2 + - name: "Setup: Cache" + uses: actions/cache@v3 + with: + path: "~/.cache/bazel" + key: bazel-v1 + - name: "Configure: Bazel" + run: | + echo "build --remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_APIKEY }}" >> local.bazelrc + echo "build --remote_header=x-api-key=${{ secrets.BUILDLESS_APIKEY }}" >> local.bazelrc + - name: "Build: Example" + run: | + bazel build \ + --config=ci \ + --config=buildless \ + --config=buildbuddy \ + --config=disk-cache \ + //example/native diff --git a/.github/workflows/module.test.yml b/.github/workflows/module.test.yml new file mode 100644 index 00000000..8f363c68 --- /dev/null +++ b/.github/workflows/module.test.yml @@ -0,0 +1,26 @@ +name: "Test" + +on: + workflow_dispatch: {} + workflow_call: {} + +jobs: + build: + name: "Test" + runs-on: ubuntu-latest + steps: + - name: "Setup: Checkout" + uses: actions/checkout@v3 + - name: "Setup: Bazel" + uses: bazelbuild/setup-bazelisk@v2 + - name: "Setup: Cache" + uses: actions/cache@v3 + with: + path: "~/.cache/bazel" + key: bazel-v1 + - name: "Build: Example" + run: | + bazel \ + coverage \ + --config=ci \ + //tests/... diff --git a/.github/workflows/on.pr.yml b/.github/workflows/on.pr.yml new file mode 100644 index 00000000..d8565e29 --- /dev/null +++ b/.github/workflows/on.pr.yml @@ -0,0 +1,10 @@ +name: "PR" + +on: + pull_request: {} + +jobs: + build: + name: "Build" + uses: ./.github/workflows/module.build.yml + secrets: inherit diff --git a/.github/workflows/on.push.yml b/.github/workflows/on.push.yml new file mode 100644 index 00000000..e79b6a51 --- /dev/null +++ b/.github/workflows/on.push.yml @@ -0,0 +1,12 @@ +name: "CI" + +on: + push: + branches: + - main + +jobs: + build: + name: "Build" + uses: ./.github/workflows/module.build.yml + secrets: inherit diff --git a/.gitignore b/.gitignore index 99641282..570ce3be 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ hash2 /external-tools/ target/ +local.bazelrc !bazel-*.rc # Ignore files generated by IDEs. @@ -20,3 +21,4 @@ target/ /.settings /.vscode/ /bazel.iml +.bazel_cache diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..fbdbe482 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,3 @@ +exports_files([ + "maven_install.json", +]) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..06c7ff49 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,99 @@ +"Defines the GraalVM Rules for Bazel module." + +load("//internal:config.bzl", "MAVEN_ARTIFACTS", "MAVEN_REPOSITORIES") + +module( + name = "rules_graalvm", + version = "0.9.0", +) + +bazel_dep( + name = "platforms", + version = "0.0.7", +) + +bazel_dep( + name = "bazel_skylib", + version = "1.4.2", +) + +bazel_dep( + name = "bazel_features", + version = "0.2.0", +) + +bazel_dep( + name = "rules_java", + version = "6.5.0", +) + +bazel_dep( + name = "rules_license", + version = "0.0.7", +) + +bazel_dep( + name = "aspect_bazel_lib", + version = "1.33.0", +) + +bazel_dep( + name = "rules_jvm_external", + version = "5.3", +) + +bazel_dep( + name = "protobuf", + version = "21.7", +) + +## Dependencies: Dev + +bazel_dep( + name = "rules_go", + version = "0.41.0", + dev_dependency = True, +) + +bazel_dep( + name = "gazelle", + version = "0.32.0", + dev_dependency = True, +) + +bazel_dep( + name = "rules_bazel_integration_test", + version = "0.15.0", + dev_dependency = True, +) + +bazel_dep( + name = "stardoc", + version = "0.5.3", + dev_dependency = True, +) + +bazel_dep( + name = "bazel_skylib_gazelle_plugin", + version = "1.4.2", + dev_dependency = True, +) + +################################################################################ +# rules_jvm_external +################################################################################ + +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") + +maven.install( + artifacts = MAVEN_ARTIFACTS, + repositories = MAVEN_REPOSITORIES, + lock_file = "//:maven_install.json", + generate_compat_repositories = True, +) + +use_repo( + maven, + "maven", + "unpinned_maven", +) diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..776d04dc --- /dev/null +++ b/Makefile @@ -0,0 +1,118 @@ + +# +# Makefile: GraalVM Rules for Bazel +# + +# Configuration +# + +CI ?= no +DEBUG ?= no +RELEASE ?= no +VERBOSE ?= no +COVERAGE ?= yes +TARGETS ?= //example/... //docs/... +TESTS ?= //... +ARGS ?= +CONFIGS ?= + +# -------------------------------------------------------- + +CP ?= $(shell which cp) +MV ?= $(shell which mv) +RM ?= $(shell which rm) +GIT ?= $(shell which git) +BAZEL ?= $(shell which bazel) +MKDIR ?= $(shell which mkdir) + +# -------------------------------------------------------- + +_ARGS = $(ARGS) +_CONFIGS = $(CONFIGS) + +ifeq ($(COVERAGE),yes) +TEST_TASK = coverage +else +TEST_TASK = test +endif + +ifeq ($(VERBOSE),yes) +RULE = +else +RULE = @ +endif + +ifeq ($(DEBUG),yes) +_CONFIGS += debug +else +ifeq ($(RELEASE),yes) +_CONFIGS += release +else +_CONFIGS += fastbuild +endif +endif + +_ARGS += $(patsubst %,--config=%,$(_CONFIGS)) + +# -------------------------------------------------------- + +all: build test docs + + +# Targets: Build/Test +# + +build: ## Build all targets. + $(RULE)$(BAZEL) build $(TARGETS) + +test: ## Run all tests. + $(RULE)$(BAZEL) $(TEST_TASK) $(TESTS) + +docs: ## Build docs. + + +# Targets: Diagnosis +# + +args: ## Show current build args. + @echo "Printing args:" + @echo "$(_ARGS)" + +config: ## Show current build configuration. + @echo "Current configuration": + @echo "CI: $(CI)" + @echo "Debug: $(DEBUG)" + @echo "Release: $(RELEASE)" + @echo "Verbose: $(VERBOSE)" + @echo "Coverage: $(COVERAGE)" + @echo "Test task: $(TEST_TASK)" + @echo "Configs: $(CONFIGS)" + @echo "Targets: $(TARGETS)" + @echo "Tests: $(TESTS)" + @echo "Args:" + @echo "$(_ARGS)" + + +# Targets: Clean +# + +clean: ## Clean built targets. + @echo "Cleaning targets..." + $(RULE)$(BAZEL) clean + +distclean: clean ## Clean and expunge; drops all state and kills worker. + $(RULE)$(BAZEL) --expunge + +reset: distclean ## Clean, expunge, and perform a hard Git reset (DANGEROUS). + $(RULE)$(GIT) reset --hard + +forceclean: reset ## Clean, expunge, reset, and drop all ignored files (DANGEROUS). + $(RULE)$(GIT) clean -xdf + + +help: ## Show this help message. + $(info GraalVM Rules for Bazel:) + @grep -E '^[a-z1-9A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: all build test docs clean distclean reset forceclean + diff --git a/README.md b/README.md index 41f4eb05..0e25565c 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,78 @@ -# rules_graal +# `rules_graalvm` -Turn a JVM binary into a native binary. +> [!IMPORTANT] +> Currently in beta. Will probably break -## Usage +Use [GraalVM](https://graalvm.org) from Bazel, with support for: -You'll need to first load the rules in your WORKSPACE file. +- [Building native image](./docs/native-image.md) +- [Consuming components with `gu`](./docs/components.md) +- [Using GraalVM as a Java toolchain](./docs/toolchain.md) +- [Support for Bazel 6, Bazel 7, and Bzlmod](./docs/modern-bazel.md) -``` python +## Installation + +**Via `WORKSPACE`:** +```starlark load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "rules_graal", - sha256 = "", - strip_prefix = "rules_graal-master", + name = "rules_graalvm", + sha256 = "", + strip_prefix = "rules_graalvm-", urls = [ - "https://github.com/andyscott/rules_graal/archive/.zip", + "https://github.com/sgammon/rules_graalvm/archive/.tar.gz", ], ) -load("@rules_graal//graal:graal_bindist.bzl", "graal_bindist_repository") +load("@rules_graalvm//graalvm:repositories.bzl", "graalvm_repository") -graal_bindist_repository( - name = "graal", - java_version = "11", # 17 is also a valid option. 8 is an option in earlier versions. - version = "21.3.0", +graalvm_repository( + name = "graalvm", # anything you want + version = "20.0.1", # 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 ) ``` -Then, in a build file: +**Via `MODULE.bazel`:** +```starlark +# Coming soon. +``` + +## Usage: Java Toolchains + +You can use the `graalvm_repository` as a Java toolchain, by registering it like below: + +**In `WORKSPACE.bazel`:** +```starlark +# Coming soon. +``` + +**Or, in a `.bazelrc` file:** +``` +# Coming soon. +``` + +## Usage: Build a native binary +**In a `BUILD.bazel` file:** ```python -load("@rules_graal//graal:graal.bzl", "graal_binary") load("@rules_java//java:defs.bzl", "java_library") +load("@rules_graalvm//graalvm:defs.bzl", "native_image") java_library( name = "main", srcs = glob(["Main.java"]), ) -graal_binary( +native_image( name = "main-native", deps = [":main"], main_class = "Main", ) ``` + +## Acknowledgements + +Built on top of @andyscott's fantastic work with [rules_graal](https://github.com/andyscott/rules_graal). diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 93214bb8..00000000 --- a/WORKSPACE +++ /dev/null @@ -1,22 +0,0 @@ -workspace(name = "rules_graal") - -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -load("@rules_graal//graal:graal_bindist.bzl", "graal_bindist_repository") - -graal_bindist_repository( - name = "graal", - version = "19.3.1", - java_version = "8", -) - -git_repository( - name = "rules_adroit", - commit = "e98240c73746934b8cfcf05020f5e936aee5bd9f", - remote = "git://github.com/andyscott/rules_adroit", -) - -register_toolchains( - "@rules_adroit//toolchains:shellcheck_from_host_path", -) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 00000000..56501ce5 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,120 @@ +workspace(name = "rules_graalvm") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//internal:config.bzl", "RULES_JVM_EXTERNAL_TAG", "RULES_JVM_EXTERNAL_SHA", "PROTOBUF_VERSION", "PROTOBUF_SHA") + +http_archive( + name = "com_google_protobuf", + sha256 = PROTOBUF_SHA, + strip_prefix = "protobuf-%s" % PROTOBUF_VERSION, + urls = ["https://github.com/protocolbuffers/protobuf/archive/v%s.tar.gz" % PROTOBUF_VERSION], +) + +http_archive( + name = "googleapis", + sha256 = "9d1a930e767c93c825398b8f8692eca3fe353b9aaadedfbcf1fca2282c85df88", + strip_prefix = "googleapis-64926d52febbf298cb82a8f472ade4a3969ba922", + urls = [ + "https://github.com/googleapis/googleapis/archive/64926d52febbf298cb82a8f472ade4a3969ba922.zip", + ], +) + +http_archive( + name = "aspect_bazel_lib", + sha256 = "d488d8ecca98a4042442a4ae5f1ab0b614f896c0ebf6e3eafff363bcc51c6e62", + strip_prefix = "bazel-lib-1.33.0", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.33.0/bazel-lib-v1.33.0.tar.gz", +) + +http_archive( + name = "rules_java", + urls = [ + "https://github.com/bazelbuild/rules_java/releases/download/6.5.0/rules_java-6.5.0.tar.gz", + ], + sha256 = "160d1ebf33763124766fb35316329d907ca67f733238aa47624a8e3ff3cf2ef4", +) + +http_archive( + name = "platforms", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz", + ], + sha256 = "3a561c99e7bdbe9173aa653fd579fe849f1d8d67395780ab4770b1f381431d51", +) + +http_archive( + name = "bazel_skylib", + sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + ], +) + +http_archive( + name = "io_bazel_rules_go", + sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip", + ], +) + + +http_archive( + name = "bazel_gazelle", + sha256 = "29218f8e0cebe583643cbf93cae6f971be8a2484cdcfa1e45057658df8d54002", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz", + ], +) + +http_archive( + name = "bazel_skylib_gazelle_plugin", + sha256 = "3327005dbc9e49cc39602fb46572525984f7119a9c6ffe5ed69fbe23db7c1560", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-gazelle-plugin-1.4.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-gazelle-plugin-1.4.2.tar.gz", + ], +) + +http_archive( + name = "io_bazel_stardoc", + sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", + "https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", + ], +) + + +http_archive( + name = "rules_jvm_external", + strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, + sha256 = RULES_JVM_EXTERNAL_SHA, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG) +) + +# -------------------------------------------------------------------------------------------------------------- + +#load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") + +#gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel") + +load("@googleapis//:repository_rules.bzl", "switched_rules_by_language") + +switched_rules_by_language( + name = "com_google_googleapis_imports", +) + +# -------------------------------------------------------------------------------------------------------------- + +load("//internal:repositories.bzl", "rules_graalvm_repositories") + +rules_graalvm_repositories() + +load("//internal:setup.bzl", "rules_graalvm_workspace") + +rules_graalvm_workspace() diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000..dfd9df02 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,48 @@ +workspace(name = "rules_graalvm") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//internal:config.bzl", "PROTOBUF_VERSION", "PROTOBUF_SHA") + +http_archive( + name = "platforms", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz", + ], + sha256 = "3a561c99e7bdbe9173aa653fd579fe849f1d8d67395780ab4770b1f381431d51", +) + +http_archive( + name = "bazel_skylib", + sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + ], +) + +http_archive( + name = "io_bazel_stardoc", + sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz", + "https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz", + ], +) + +http_archive( + name = "com_google_protobuf", + sha256 = PROTOBUF_SHA, + strip_prefix = "protobuf-%s" % PROTOBUF_VERSION, + urls = ["https://github.com/protocolbuffers/protobuf/archive/v%s.tar.gz" % PROTOBUF_VERSION], +) + +# -------------------------------------------------------------------------------------------------------------- + +load("//internal:repositories.bzl", "rules_graalvm_repositories") + +rules_graalvm_repositories(maven = False) + +load("//internal:setup.bzl", "rules_graalvm_workspace") + +rules_graalvm_workspace(maven = False) diff --git a/graal/BUILD b/docs/BUILD.bazel similarity index 100% rename from graal/BUILD rename to docs/BUILD.bazel diff --git a/docs/api/BUILD.bazel b/docs/api/BUILD.bazel new file mode 100644 index 00000000..19d1b6f1 --- /dev/null +++ b/docs/api/BUILD.bazel @@ -0,0 +1,11 @@ +"Aliases to documentation targets for the package API." + +alias( + name = "defs", + actual = "//graalvm:defs_doc", +) + +alias( + name = "repositories", + actual = "//graalvm:repositories_doc", +) diff --git a/docs/api/defs.md b/docs/api/defs.md new file mode 100755 index 00000000..ada0fdef --- /dev/null +++ b/docs/api/defs.md @@ -0,0 +1,36 @@ + + +Target rule definitions, intended for use by rule users. + + + +## native_image + +
+native_image(name, c_compiler_option, data, deps, extra_args, graalvm, include_resources,
+             initialize_at_build_time, initialize_at_run_time, jni_configuration, main_class,
+             native_features, reflection_configuration)
+
+ + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| c_compiler_option | - | List of strings | optional | [] | +| data | - | List of labels | optional | [] | +| deps | - | List of labels | optional | [] | +| extra_args | - | List of strings | optional | [] | +| graalvm | - | Label | optional | @graalvm//:bin/native-image | +| include_resources | - | String | optional | "" | +| initialize_at_build_time | - | List of strings | optional | [] | +| initialize_at_run_time | - | List of strings | optional | [] | +| jni_configuration | - | Label | optional | None | +| main_class | - | String | optional | "" | +| native_features | - | List of strings | optional | [] | +| reflection_configuration | - | Label | optional | None | + + diff --git a/docs/api/repositories.md b/docs/api/repositories.md new file mode 100755 index 00000000..96018516 --- /dev/null +++ b/docs/api/repositories.md @@ -0,0 +1,47 @@ + + +Repository rule definitions, intended for use by rule users. + + + +## graalvm_repository + +
+graalvm_repository(name, java_version, version, distribution, toolchain, toolchain_prefix,
+                   target_compatible_with, components, setup_actions, register_all, kwargs)
+
+ +Declare a GraalVM distribution repository, and optionally a Java toolchain to match. + +To register and use the GraalVM distribution as a toolchain, follow the Toolchains guide in the docs +(`docs/toolchain.md`). + +If `distribution` is set to `oracle`, an Oracle GraalVM installation is downloaded. This variant of +GraalVM may be subject to different license obligations; please consult Oracle's docs for more info. + +Oracle GraalVM distributions are downloaded directly from Oracle, which provides a `latest` download +endpoint. Set `version` to `latest` (the default value) to download the latest available version of +GraalVM matching the provided `java_version`. + +When installing the `latest` version of GraalVM, it is probably ideal to provide your own `sha256`. +In this case, the `rules_graalvm` package does not provide an SHA256 hash otherwise. + + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | Name of the VM repository. | none | +| java_version | Java version to use/declare. | none | +| version | Version of the GraalVM release. | "latest" | +| distribution | Which GVM distribution to download - ce, community, or oracle. | "oracle" | +| toolchain | Whether to create a Java toolchain from this GVM installation. | True | +| toolchain_prefix | Name prefix to use for the toolchain; defaults to graalvm. | "graalvm" | +| target_compatible_with | Compatibility tags to apply. | [] | +| components | Components to install in the target GVM installation. | [] | +| setup_actions | GraalVM Updater commands that should be run; pass complete command strings that start with "gu". | [] | +| register_all | Register all GraalVM repositories and use target_compatible_with (experimental). | False | +| kwargs | Passed to the underlying bindist repository rule. | none | + + diff --git a/docs/components.md b/docs/components.md new file mode 100644 index 00000000..538d7c6b --- /dev/null +++ b/docs/components.md @@ -0,0 +1,61 @@ + +## Installing and using GraalVM components + +Some GraalVM distributions make available _components_, which include language implementations, tooling, and other utilities. Your project may need one or more GraalVM components installed in order to build or run correctly. + +Using these rules, you can declare your required components in the `graalvm_repository` rule, and they will be installed using the GraalVM Updater tool (`gu`). + +By default, no components are installed beyond what is present in a given distribution. Newer versions of GraalVM distribute the `native-image` tool and `js` runtime in the base distribution. + +### Installing components + +**In your `WORKSPACE.bazel`:** +```starlark +load("@rules_graalvm//graalvm:repositories.bzl", "graalvm_repository") + +# ... + +graalvm_repository( + name = "graalvm", + version = "20.0.1", + distribution = "oracle", + java_version = "20", + + # This is how you install components + components = [ + "wasm", + "js", + ], +) +``` + +This snippet assumes you've [set up the rules](../README.md). + +> [!IMPORTANT] +> If you declare `components`, make sure to declare the full set you need, including any that may be installed in the base distribution. + + +### After-install actions + +With certain GraalVM components or project configurations, you may need to run post-installation actions with the GraalVM Updater tool (`gu`): + +**In your `WORKSPACE.bazel`:** +```starlark +load("@rules_graalvm//graalvm:repositories.bzl", "graalvm_repository") + +# ... + +graalvm_repository( + name = "graalvm", + version = "20.0.1", + distribution = "oracle", + java_version = "20", + + components = [ + "espresso", + ], + setup_actions = [ + "gu rebuild-images libpolyglot -cp ${JAVA_HOME}/lib/graalvm/lib-javavm.jar", + ], +) +``` diff --git a/docs/modern-bazel.md b/docs/modern-bazel.md new file mode 100644 index 00000000..8db050ff --- /dev/null +++ b/docs/modern-bazel.md @@ -0,0 +1,44 @@ + +## Usage from modern Bazel + +See instructions below for installation and use of `rules_graalvm` on Bazel 6 or newer, via Bazel Modules: + +### Installation in `MODULE.bazel` + +```starlark +bazel_dep(name = "rules_graalvm", version = "") +``` + +**Toolchain registration in `WORKSPACE.bzlmod` (optional):** +```starlark +load("@rules_graalvm//graalvm:repositories.bzl", "graalvm_repository") + +# graalvm_repository(name = "graalvm" ...) + +register_toolchains("@graalvm//:all") +``` + +### Installation in `WORKSPACE.bazel` + +If you don't want to use Bzlmod, you can install in a `WORKSPACE` manually: + +```starlark +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + # ... paste this part from the github releases page ... # +) + +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 + distribution = "oracle", # required for newer GVM releases (`oracle`, `ce`, or `community`) + java_version = "20", # java language version to use/declare +) +``` + +## Use as a toolchain + +See the [toolchains guide](./toolchain.md) for more information. diff --git a/docs/native-image.md b/docs/native-image.md new file mode 100644 index 00000000..b4e6860f --- /dev/null +++ b/docs/native-image.md @@ -0,0 +1,40 @@ + +## Building GraalVM native images with Bazel + +After you [install the rules](./modern-bazel.md) and setup your GraalVM repository, you can easily use it to build a native image using the `native-image` tool, from a standard Bazel `java_library` or `java_binary` target. + +### Native image example + +> [!NOTE] +> This sample is present in the `rules_graalvm` repository at `example/native`. + +**In `Main.java`:** +```java +public class Main { + public static void main(String args[]) { + System.out.println("Hello, GraalVM Native!"); + } +} +``` + +**In `BUILD.bazel`:** +```starlark +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_graalvm//graalvm:defs.bzl", "native_image") + +java_library( + name = "main", + srcs = ["Main.java"], +) + +native_image( + name = "native", + deps = [":main"], + main_class = "Main", +) +``` + +Then, from your terminal: +``` +bazel build //some/package:native +``` diff --git a/docs/toolchain.md b/docs/toolchain.md new file mode 100644 index 00000000..4b95c343 --- /dev/null +++ b/docs/toolchain.md @@ -0,0 +1,59 @@ + +## Using GraalVM as a toolchain with Bazel + +> [!NOTE] +> Bazel toolchains can be hard to use. See the _Troubleshooting_ section for best-effort help. + +[Bazel Toolchains](https://bazel.build/extending/toolchains) is an optional feature which helps Bazel resolve tools on different platforms and in different project contexts. Several Bazel rule sets use toolchains in order to make the underlying tooling customizable for an end-user's goals. + +Java toolchains in Bazel are typically used to select a particular JDK to run against or build against. `rules_graalvm` integrates with Bazel toolchains by default; **if you want to use a downloaded GVM installation as your Java toolchain, follow the directions below.** + +### Toolchain registration + +> [!IMPORTANT] +> Make sure you've [installed and setup the rules](./modern-bazel.md) first. + +After you've installed `rules_graalvm` and declared a `graalvm_repository`, you can register GraalVM as a Java toolchain using the `:all` target at the repository root: + +**In your `WORKSPACE.bazel`:** +```starlark +# ... + +# graalvm_repository(name = "graalvm", ...) + +register_toolchains("@graalvm//:all") +``` + +**Or, in a `bazel.rc`:** +``` +build --extra_toolchains=@graalvm//:all +``` + +### Toolchain selection + +> [!IMPORTANT] +> You need to **register** _and_ **select** a toolchain in order to actually use it. This sample assumes the `graalvm_repository` is named `graalvm`. + +Bazel uses several JDKs throughout the course of a regular build; there is the embedded JDK which runs Bazel itself, then the _tooling_ JDK which is used to build your code, and, finally, there is the _runtime_ JDK which is used to execute JVM bytecode. This is referred to as Bazel's "[JVM sandwich](https://github.com/bazelbuild/bazel/issues/2614)." + +You can select GraalVM as the **tooling toolchain**, the **runtime toolchain**, or **both**: + +#### Assigning GraalVM as the tooling toolchain + +Set **`tool_java_language_version`** to the version matching your GraalVM JDK declared in `graalvm_repository`. + +**In a `bazel.rc`:** +``` +build --tool_java_language_version=20 +build --extra_toolchains=@graalvm_toolchain_config_repo//:bootstrap_runtime_toolchain +``` + +#### Assigning GraalVM as the tooling toolchain + +Set **`java_runtime_version`** to the version matching your GraalVM JDK declared in `graalvm_repository`. + +**In a `bazel.rc`:** +``` +build --java_language_version=20 +build --java_runtime_version=graalvm_20 +``` diff --git a/example/BUILD b/example/BUILD deleted file mode 100644 index 453da6a5..00000000 --- a/example/BUILD +++ /dev/null @@ -1,24 +0,0 @@ -load("@rules_graal//graal:graal.bzl", "graal_binary") - -java_library( - name = "main", - #main_class = "Main", - srcs = glob(["Main.java"]), -) - -graal_binary( - name = "main-native", - deps = [":main"], - main_class = "Main", -) - - -graal_binary( - name = "main-native-reflectioncfg", - deps = [":main"], - initialize_at_build_time=["Main"], - reflection_configuration = "reflection.cfg", - main_class = "Main", -) - - diff --git a/example/BUILD.bazel b/example/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/example/native/BUILD.bazel b/example/native/BUILD.bazel new file mode 100644 index 00000000..e7c90d8a --- /dev/null +++ b/example/native/BUILD.bazel @@ -0,0 +1,34 @@ +load( + "@rules_java//java:defs.bzl", + "java_binary", + "java_library" +) + +load( + "@rules_graalvm//graalvm:defs.bzl", + "native_image" +) + +java_library( + name = "java", + srcs = ["Main.java"], +) + +java_binary( + name = "main", + main_class = "Main", + runtime_deps = [ + ":java", + ], +) + +native_image( + name = "main-native", + deps = [":java"], + main_class = "Main", +) + +alias( + name = "native", + actual = "main-native", +) diff --git a/example/Main.java b/example/native/Main.java similarity index 60% rename from example/Main.java rename to example/native/Main.java index dccb13bc..c9824efb 100644 --- a/example/Main.java +++ b/example/native/Main.java @@ -1,7 +1,5 @@ public class Main { - public static void main(String args[]) { - System.out.println("Hello, Stripe"); + System.out.println("Hello, GraalVM!"); } - } \ No newline at end of file diff --git a/example/reflection.cfg b/example/native/reflection.cfg similarity index 100% rename from example/reflection.cfg rename to example/native/reflection.cfg diff --git a/graal/graal_bindist.bzl b/graal/graal_bindist.bzl deleted file mode 100644 index 49f96acc..00000000 --- a/graal/graal_bindist.bzl +++ /dev/null @@ -1,269 +0,0 @@ -_graal_archive_internal_prefixs = { - "darwin-amd64": "graalvm-ce-java{java_version}-{version}/Contents/Home", - "darwin-aarch64": "graalvm-ce-java{java_version}-{version}/Contents/Home", - "linux-amd64": "graalvm-ce-java{java_version}-{version}", -} - -_graal_version_configs = { - "19.0.0": { - "urls": ["https://github.com/oracle/graal/releases/download/vm-{version}/graalvm-ce-{platform}-{version}.tar.gz"], - "sha": { - "8": { - "darwin-amd64": "fc652566e61b9b774c120da1aea0ae3e28f198d55a297524dcc97b9a83525a79", - "linux-amd64": "7ad124cdb19cbaa962f6d2f26d1e3eccfeb93afabbf8e81cb65976519f15730c", - }, - }, - }, - "19.3.1": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "8": { - "darwin-amd64": "eba3765174f0279ae2dc57c84fc0eb324da778dbfdcc03c6fa8381fe3728aef9", - "linux-amd64": "815385a1c35a1db54b9b9622059c9e8e5155460f65c3d713e55d3a84222c9194", - }, - "11": { - "darwin-amd64": "b3ea6cf6545332f667b2cc742bbff9949d47e49eecea06334d14f0b69aa1a3f3", - "linux-amd64": "691f0577c75c4ba0fb50916087925e6eb8a5a73de51994a37eee022d1e2c9e7d", - }, - }, - }, - "20.2.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "8": { - "darwin-amd64": "a1f524788354cfd2434566f0de972372f4a7743919bae49a9d508f2080385e7b", - "linux-amd64": "60951c774c708caeebd1fa3886c05aa1260d81c7595ede0c9c3e689be7fcc4e8", - }, - "11": { - "darwin-amd64": "e9df2caace6f90fcfbc623c184ef1bbb053de20eb4cf5b002d708c609340ba7a", - "linux-amd64": "5db74b5b8888712d2ac3cd7ae2a8361c2aa801bc94c801f5839351aba5064e29", - }, - }, - }, - "21.0.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "8": { - "darwin-amd64": "9192d8370b544c0efd36ef744f5933bd2d694d0cc9cb5e7f53d3b7e58f433b3e", - "linux-amd64": "326c5a9ba2f6a6b28023c1fef9c4c6fb6acf9cd87b0fcb6916e0527633bd01a3", - }, - "11": { - "darwin-amd64": "0e6b9af45d0ba40d8e61b16708361f794e17430f5098760bd03584ebcc950fa9", - "linux-amd64": "4cdb5b9d0142cdaf5565fd20c5cde176d9b7c9dfd278267cab318f64f2923dbc", - }, - }, - }, - "21.3.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "11": { - "darwin-amd64": "6c2bf7f6e5fab901e8a2284a0dbec6ce214bde65aa80cfeb90bfef8eabb5f862", - "linux-amd64": "3a1bc8eaf0518c128aaacb987ceb0b0e288776f48af630c11c01fd31122d93fa", - }, - "17": { - "darwin-amd64": "60236506920cc84a07ea7602f4514d05da2c07c7176e0634652f8a9c5ad677aa", - "linux-amd64": "11d8039e0a7a31b799a6f20a0e806e4128730e9a2595a7ffdec1443539d4c3f6", - }, - }, - }, - "22.0.0.2": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "11": { - "darwin-amd64": "8280159b8a66c51a839c8079d885928a7f759d5da0632f3af7300df2b63a6323", - "linux-aarch64": "1cc0263d95f642dada4e290dca7f49c0456cefa7b690b67e3e5c159b537b2c58", - "linux-amd64": "bc86083bb7e2778c7e4fe4f55d74790e42255b96f7806a7fefa51d06f3bc7103", - }, - "17": { - "darwin-amd64": "d54af9d1f4d0d351827395a714ed84d2489b023b74a9c13a431cc9d31d1e8f9a", - "linux-aarch64": "c7d78387d2a144944f26773697c1b61d3478a081a1c5e7fc20f47f1f5f3c82c7", - "linux-amd64": "4f743e0ed3d974b7d619ca2ed6014554e8c12e5ebbb38b9bc9e820b182169bd4", - }, - }, - }, - "22.1.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], - "sha": { - "11": { - "darwin-aarch64": "06bc19a0b1e93aa3df5e15c08e97f8cef624cb6070eeae40a69a51ec7fd41152", - "darwin-amd64": "c4c9df94ca47b83b582758b87d39042732ba0193fc63f1ab93f6818005a1fe6b", - "linux-aarch64": "050a4d471247d91935f7f485e92d678f0163e1d6209e26e8fe75d7c924f73e71", - "linux-amd64": "78c628707007bb97b09562932ee16f50beb1c3fa4a36e4311a0465a4a718e683", - }, - "17": { - "darwin-aarch64": "06075cd390bd261721392cd6fd967b1d28c0500d1b5625272ea906038e5cd533", - "darwin-amd64": "b9327fa73531a822d9a27d25980396353869eefbd73fdcef89b4fceb9f529c75", - "linux-aarch64": "05128e361ed44beebc89495faaa504b0b975bf93aa5e512e217b3cf5e42dfada", - "linux-amd64": "f11d46098efbf78465a875c502028767e3de410a31e45d92a9c5cf5046f42aa2", - }, - }, - }, -} - -_graal_native_image_version_configs = { - "19.0.0": { - "urls": ["https://github.com/oracle/graal/releases/download/vm-{version}/native-image-installable-svm-{platform}-{version}.jar"], - "sha": { - "8": { - "darwin-amd64": "4fa035b31cfd3d86d464e9a67b652c69a0cceb88c6b2f2ce629c55ca2113c786", - "linux-amd64": "1c794a3c038f4e6bb90542cf13ba3c6c793dcd193462bf56b8713fd24386e344", - }, - }, - }, - "19.3.1": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "8": { - "darwin-amd64": "266d295456dfc588fae52ef2c26cd7e745e6fa0681271e677cad2dd9a1b09461", - "linux-amd64": "3fd2e5b5299c8ce7c939235b4d01df990aeb236f127f98fbf19b588c521793fa", - }, - "11": { - "darwin-amd64": "6bd2bace9773a2ac7ff8182a36f84507678e71f94bf3f0c4646a091100644e13", - "linux-amd64": "fef2e2c71a5408855026e022ae15fda50cb52769aa7d0ec008837f49196ee16a", - }, - }, - }, - "20.2.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "8": { - "darwin-amd64": "4852abafe92e13cb6bf655bba4ba36721b93324ccc6777504f34c70094c583fb", - "linux-amd64": "6b5403e27282847acce180f0ae9637c3f26678f27047bbd5dfed92a5bef73ab2", - }, - "11": { - "darwin-amd64": "d60c321d6e680028f37954121eeebff0839a0a49a4436e5b41c636c3dd951de3", - "linux-amd64": "92b429939f12434575e4d586f79c5b686d322f29211d1608ed6055a97a35925c", - }, - }, - }, - "21.0.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "8": { - "darwin-amd64": "f006e001d195de80cd71b28518f230815b6c00e8d3762148f4b23c09097debc7", - "linux-amd64": "8f6976b2a9a40d35df50402a3e893af41a6a6bc01301851a91672106d313f842", - }, - "11": { - "darwin-amd64": "68d95999312e96c8cd070a8ba1d9724bc4d4fbe03e29da2c392e021a5f393fb5", - "linux-amd64": "c70b00b4eabcc0140505acab756c394a88be7980634706cce11f53e09658707c", - }, - }, - }, - "21.3.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "11": { - "darwin-amd64": "038ac1168b909cfb5e4d6437ee02a5aa8126cbb835aba7a3e6ab72042162e8d5", - "linux-amd64": "8958d4e0cad07340db0cf9e871776809e2f08fe0c93960f728fec75c4a96764f", - }, - "17": { - "darwin-amd64": "80ac09d45f8822413b9f16297da60da196013bbcfbc4bc7721f1257885ebe063", - "linux-amd64": "df488a04b5405c6443c90e94710cd3bd2be9adcb3768f91429aa494168d52440", - }, - }, - }, - "22.0.0.2": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "11": { - "darwin-amd64": "03c27de6cce61ee8073e89252212457f3fbac2c0bc9bfa4acbff12176476c176", - "linux-aarch64": "51d41e890a5aabf8e7b9d4f4e0f88206ee70a261f7dbb0315d51770ab8f3009e", - "linux-amd64": "8504a3441f5b28b8fd625f676674a9216f082ae63a4e30d43930c80f9672e71d", - }, - "17": { - "darwin-amd64": "007fa742cd139d447f83d776b6d78e717c9df11d56a61061a5937547c20028b7", - "linux-aarch64": "798947d0a93988929d2b8e3555f7c65225e789124cd99fbc0c3aae5f350175db", - "linux-amd64": "8c25f650d58c2649c97061cb806dfaec9e685d5d2b80afc7cf72fe61d6891831", - }, - }, - }, - "22.1.0": { - "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], - "sha": { - "11": { - "darwin-aarch64": "21f84ccf7b979dccc9091032fe76b5737b38e0092f282107cef75143dadb3bdb", - "darwin-amd64": "e0758687f4bd46f15fcee9b0a5bdd65d702ec81c41d465ee7229d3f4465bcf13", - "linux-aarch64": "12715793b223ce1db7ec7d0a339f0b578a0c9fb6dcc6607044e5af4fd33b25a7", - "linux-amd64": "36e4a2a9a73a19b03883f9e783bc8bde7c214bb0fa4b617379cb81798de425bf", - }, - "17": { - "darwin-aarch64": "beabecdd5b87e7536772d4dfe70abf4c5dd9847e87615464cf309138d21c39af", - "darwin-amd64": "e6bfe208bb28cd1d98da55e00fa705890a7f69286b919947b07d18cc9bb9c270", - "linux-aarch64": "6e10f6953ec8b9509c7a7d0194d57f265cf2a05dcb8f3272a6a8e847bda49cda", - "linux-amd64": "d81eecea15ebbf4f24850860c14104eaf6f8ae74574330e22afac533b8f96738", - }, - }, - }, -} - -def _get_platform(ctx): - res = ctx.execute(["uname", "-p"]) - arch = "amd64" - if res.return_code == 0: - uname = res.stdout.strip() - if uname == "arm": - arch = "arm64" - elif uname == "aarch64": - arch = "aarch64" - - if ctx.os.name == "linux": - return "linux-%s" % arch - elif ctx.os.name == "mac os x": - if arch == "arm64" or arch == "aarch64": - if ctx.attr.version != "22.1.0": - fail( - "GraalVM has `aarch64` distributions for macOS starting with v22.1.0. " + - "Please upgrade or use `amd64`." - ) - return "darwin-aarch64" - return "darwin-amd64" - else: - fail("Unsupported operating system: " + ctx.os.name) - -def _graal_bindist_repository_impl(ctx): - platform = _get_platform(ctx) - version = ctx.attr.version - java_version = ctx.attr.java_version - format_args = { - "version": version, - "platform": platform, - "java_version": java_version, - } - - #Download graal - config = _graal_version_configs[version] - sha = config["sha"][java_version][platform] - urls = [url.format(**format_args) for url in config["urls"]] - archive_internal_prefix = _graal_archive_internal_prefixs[platform].format(**format_args) - - ctx.download_and_extract( - url = urls, - sha256 = sha, - stripPrefix = archive_internal_prefix, - ) - - # download native image - native_image_config = _graal_native_image_version_configs[version] - native_image_sha = native_image_config["sha"][java_version][platform] - native_image_urls = [url.format(**format_args) for url in native_image_config["urls"]] - - ctx.download( - url = native_image_urls, - sha256 = native_image_sha, - output = "native-image-installer.jar", - ) - - exec_result = ctx.execute(["bin/gu", "install", "--local-file", "native-image-installer.jar"], quiet = False) - if exec_result.return_code != 0: - fail("Unable to install native image:\n{stdout}\n{stderr}".format(stdout = exec_result.stdout, stderr = exec_result.stderr)) - - ctx.file("BUILD", """exports_files(glob(["**/*"]))""") - ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = ctx.name)) - -graal_bindist_repository = repository_rule( - attrs = { - "version": attr.string(mandatory = True), - "java_version": attr.string(mandatory = True), - }, - implementation = _graal_bindist_repository_impl, -) diff --git a/graalvm/BUILD.bazel b/graalvm/BUILD.bazel new file mode 100644 index 00000000..9ee78be6 --- /dev/null +++ b/graalvm/BUILD.bazel @@ -0,0 +1,57 @@ +load( + "@bazel_skylib//:bzl_library.bzl", + "bzl_library", +) +load( + "@io_bazel_stardoc//stardoc:stardoc.bzl", + "stardoc", +) + +exports_files([ + "defs.bzl", + "repositories.bzl", +]) + +bzl_library( + name = "defs", + srcs = [ + "defs.bzl", + ], + deps = [ + "//internal:tooling", + "//graalvm/nativeimage:rules", + ], +) + +bzl_library( + name = "repositories", + srcs = [ + "repositories.bzl", + ], + deps = [ + "//internal:bindist", + "//internal:tooling", + ], +) + +stardoc( + name = "defs_doc", + input = "defs.bzl", + out = "defs.md", + visibility = ["//docs:__subpackages__"], + deps = [ + "//graalvm/nativeimage:rules", + "//internal:tooling", + ], +) + +stardoc( + name = "repositories_doc", + input = "repositories.bzl", + out = "repositories.md", + visibility = ["//docs:__subpackages__"], + deps = [ + "//internal:bindist", + "//internal:tooling", + ], +) diff --git a/graalvm/artifacts/BUILD.bazel b/graalvm/artifacts/BUILD.bazel new file mode 100644 index 00000000..9e69f75e --- /dev/null +++ b/graalvm/artifacts/BUILD.bazel @@ -0,0 +1 @@ +# Nothing at this time. \ No newline at end of file diff --git a/graalvm/defs.bzl b/graalvm/defs.bzl new file mode 100644 index 00000000..0bd2006a --- /dev/null +++ b/graalvm/defs.bzl @@ -0,0 +1,10 @@ +"Target rule definitions, intended for use by rule users." + +load( + "//graalvm/nativeimage:rules.bzl", + _native_image = "native_image", +) + + +## Exports +native_image = _native_image diff --git a/graalvm/nativeimage/BUILD.bazel b/graalvm/nativeimage/BUILD.bazel new file mode 100644 index 00000000..749d5a82 --- /dev/null +++ b/graalvm/nativeimage/BUILD.bazel @@ -0,0 +1,15 @@ +load( + "@bazel_skylib//:bzl_library.bzl", + "bzl_library", +) + +exports_files([ + "rules.bzl", +]) + +bzl_library( + name = "rules", + srcs = ["rules.bzl"], + visibility = ["//graalvm:__subpackages__"], + deps = ["//internal:tooling"], +) diff --git a/graal/graal.bzl b/graalvm/nativeimage/rules.bzl similarity index 89% rename from graal/graal.bzl rename to graalvm/nativeimage/rules.bzl index c795aa0f..5d2d3ddf 100644 --- a/graal/graal.bzl +++ b/graalvm/nativeimage/rules.bzl @@ -1,18 +1,19 @@ -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") +"Rules for building native binaries using the GraalVM `native-image` tool." + +load( + "@bazel_tools//tools/cpp:toolchain_utils.bzl", + "find_cpp_toolchain", +) load( "@bazel_tools//tools/build_defs/cc:action_names.bzl", - "ASSEMBLE_ACTION_NAME", - "CPP_COMPILE_ACTION_NAME", "CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME", "CPP_LINK_EXECUTABLE_ACTION_NAME", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME", "C_COMPILE_ACTION_NAME", - "OBJCPP_COMPILE_ACTION_NAME", - "OBJC_COMPILE_ACTION_NAME", ) def _graal_binary_implementation(ctx): - graal_attr = ctx.attr._graal + graal_attr = ctx.attr.graalvm graal_inputs, _, _ = ctx.resolve_command(tools = [graal_attr]) graal = graal_inputs[0] @@ -67,21 +68,20 @@ def _graal_binary_implementation(ctx): binary = ctx.actions.declare_file("%s-bin" % ctx.attr.name) args = ctx.actions.args() - args.add("--no-server") args.add("--no-fallback") args.add("-cp", ":".join([f.path for f in classpath_depset.to_list()])) args.add("-H:-CheckToolchain") args.add("-H:Class=%s" % ctx.attr.main_class) args.add("-H:Name=%s" % binary.path) args.add("-H:+ReportExceptionStackTraces") - for arg in ctx.attr.graal_extra_args: + for arg in ctx.attr.extra_args: args.add(arg) args.add_joined(ctx.attr.c_compiler_option, join_with = " ", format_joined="-H:CCompilerOption=%s") - if len(ctx.attr.native_image_features) > 0: - args.add("-H:Features={entries}".format(entries=",".join(ctx.attr.native_image_features))) + if len(ctx.attr.native_features) > 0: + args.add("-H:Features={entries}".format(entries=",".join(ctx.attr.native_features))) if len(ctx.attr.initialize_at_build_time) > 0: args.add("--initialize-at-build-time={entries}".format(entries=",".join(ctx.attr.initialize_at_build_time))) @@ -119,7 +119,7 @@ def _graal_binary_implementation(ctx): ), )] -graal_binary = rule( +native_image = rule( implementation = _graal_binary_implementation, attrs = { "deps": attr.label_list(providers = [[JavaInfo]]), @@ -129,10 +129,10 @@ graal_binary = rule( "include_resources": attr.string(), "initialize_at_build_time": attr.string_list(), "initialize_at_run_time": attr.string_list(), - "native_image_features": attr.string_list(), - "_graal": attr.label( - cfg = "host", - default = "@graal//:bin/native-image", + "native_features": attr.string_list(), + "graalvm": attr.label( + cfg = "exec", + default = "@graalvm//:bin/native-image", allow_files = True, executable = True, ), @@ -140,7 +140,7 @@ graal_binary = rule( default = Label("@bazel_tools//tools/cpp:current_cc_toolchain") ), "data": attr.label_list(allow_files = True), - "graal_extra_args": attr.string_list(), + "extra_args": attr.string_list(), "c_compiler_option": attr.string_list() }, executable = True, diff --git a/graalvm/repositories.bzl b/graalvm/repositories.bzl new file mode 100644 index 00000000..1c0eb54b --- /dev/null +++ b/graalvm/repositories.bzl @@ -0,0 +1,10 @@ +"Repository rule definitions, intended for use by rule users." + +load( + "//internal:graalvm_bindist.bzl", + _graalvm_repository = "graalvm_repository", +) + + +## Exports +graalvm_repository = _graalvm_repository diff --git a/graalvm/toolchain/BUILD.bazel b/graalvm/toolchain/BUILD.bazel new file mode 100644 index 00000000..f82bf11b --- /dev/null +++ b/graalvm/toolchain/BUILD.bazel @@ -0,0 +1,13 @@ +"Defines toolchain types for GraalVM." + +# Toolchain type: `graalvm` +# +# Describes a regular GraalVM toolchain; this type is satisfied by either GraalVM Community Edition +# or a distribution of Oracle GraalVM. +toolchain_type(name = "graalvm") + +# Toolchain type: `graalvm_native_image` +# +# Describes a `native-image` binary made available as part of a GraalVM installation of any type. +# This tool may be installed via the GraalVM Updater or provided otherwise. +toolchain_type(name = "graalvm_native_image") diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel new file mode 100644 index 00000000..40448783 --- /dev/null +++ b/internal/BUILD.bazel @@ -0,0 +1,50 @@ +load( + "@bazel_skylib//:bzl_library.bzl", + "bzl_library", +) + +exports_files([ + "config.bzl", + "graalvm_bindist.bzl", + "maven.bzl", +]) + +bzl_library( + name = "tooling", + visibility = ["//graalvm:__subpackages__"], + srcs = [ + "@bazel_tools//tools:bzl_srcs", + ], +) + +bzl_library( + name = "java_toolchains", + srcs = [ + "@rules_java//toolchains:bzl_srcs", + ], +) + +bzl_library( + name = "config", + srcs = ["config.bzl"], +) + +bzl_library( + name = "bindist", + srcs = ["graalvm_bindist.bzl"], + visibility = ["//graalvm:__subpackages__"], + deps = [ + ":tooling", + ":java_toolchains", + ], +) + +bzl_library( + name = "maven", + srcs = ["maven.bzl"], + visibility = ["//graalvm:__subpackages__"], + deps = [ + ":config", + ":tooling", + ], +) diff --git a/internal/config.bzl b/internal/config.bzl new file mode 100644 index 00000000..8e447d8a --- /dev/null +++ b/internal/config.bzl @@ -0,0 +1,32 @@ +"Defines configuration and pinned versions for the GraalVM Rules project." + +GRAALVM_VERSION = "20.0.1" + +GRAALVM_SDK_VERSION = "23.0.1" + +GRAALVM_DISTRIBUTION = "oracle" + +GRAALVM_JAVA_VERSION = "20" + +GRAALVM_SHA = None + +RULES_JVM_EXTERNAL_TAG = "5.3" + +RULES_JVM_EXTERNAL_SHA ="d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac" + +PROTOBUF_VERSION = "3.20.1" + +PROTOBUF_SHA = "8b28fdd45bab62d15db232ec404248901842e5340299a57765e48abe8a80d930" + +GO_VERSION = "1.20.5" + +MAVEN_ARTIFACTS = [ + "org.graalvm.nativeimage:svm:%s" % GRAALVM_SDK_VERSION, + "org.graalvm.sdk:graal-sdk:%s" % GRAALVM_SDK_VERSION, +] + +MAVEN_REPOSITORIES = [ + "https://maven.pkg.st", + "https://maven.google.com", + "https://repo1.maven.org/maven2", +] diff --git a/internal/graalvm_bindist.bzl b/internal/graalvm_bindist.bzl new file mode 100644 index 00000000..d11ce479 --- /dev/null +++ b/internal/graalvm_bindist.bzl @@ -0,0 +1,634 @@ +"Describes binary distribution coordinates for GraalVM releases." + +load( + "@rules_java//toolchains:jdk_build_file.bzl", + _JDK_BUILD_TEMPLATE = "JDK_BUILD_TEMPLATE", +) + +_graal_archive_internal_prefixes = { + "darwin-amd64": "graalvm-ce-java{java_version}-{version}/Contents/Home", + "linux-amd64": "graalvm-ce-java{java_version}-{version}", +} + +_graal_v2_archive_internal_prefixes = { + "macos": "Contents/Home", + "linux": "", + "windows": "" +} + +_graal_version_configs = { + "19.0.0": { + "urls": ["https://github.com/oracle/graal/releases/download/vm-{version}/graalvm-ce-{platform}-{version}.tar.gz"], + "sha256": { + "8": { + "darwin-amd64": "fc652566e61b9b774c120da1aea0ae3e28f198d55a297524dcc97b9a83525a79", + "linux-amd64": "7ad124cdb19cbaa962f6d2f26d1e3eccfeb93afabbf8e81cb65976519f15730c", + }, + }, + }, + "19.3.1": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha256": { + "8": { + "darwin-amd64": "eba3765174f0279ae2dc57c84fc0eb324da778dbfdcc03c6fa8381fe3728aef9", + "linux-amd64": "815385a1c35a1db54b9b9622059c9e8e5155460f65c3d713e55d3a84222c9194", + }, + "11": { + "darwin-amd64": "b3ea6cf6545332f667b2cc742bbff9949d47e49eecea06334d14f0b69aa1a3f3", + "linux-amd64": "691f0577c75c4ba0fb50916087925e6eb8a5a73de51994a37eee022d1e2c9e7d", + }, + }, + }, + "20.2.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha256": { + "8": { + "darwin-amd64": "a1f524788354cfd2434566f0de972372f4a7743919bae49a9d508f2080385e7b", + "linux-amd64": "60951c774c708caeebd1fa3886c05aa1260d81c7595ede0c9c3e689be7fcc4e8", + }, + "11": { + "darwin-amd64": "e9df2caace6f90fcfbc623c184ef1bbb053de20eb4cf5b002d708c609340ba7a", + "linux-amd64": "5db74b5b8888712d2ac3cd7ae2a8361c2aa801bc94c801f5839351aba5064e29", + }, + }, + }, + "21.0.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha256": { + "8": { + "darwin-amd64": "9192d8370b544c0efd36ef744f5933bd2d694d0cc9cb5e7f53d3b7e58f433b3e", + "linux-amd64": "326c5a9ba2f6a6b28023c1fef9c4c6fb6acf9cd87b0fcb6916e0527633bd01a3", + }, + "11": { + "darwin-amd64": "0e6b9af45d0ba40d8e61b16708361f794e17430f5098760bd03584ebcc950fa9", + "linux-amd64": "4cdb5b9d0142cdaf5565fd20c5cde176d9b7c9dfd278267cab318f64f2923dbc", + }, + }, + }, + "21.3.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha256": { + "11": { + "darwin-amd64": "6c2bf7f6e5fab901e8a2284a0dbec6ce214bde65aa80cfeb90bfef8eabb5f862", + "linux-amd64": "3a1bc8eaf0518c128aaacb987ceb0b0e288776f48af630c11c01fd31122d93fa", + }, + "17": { + "darwin-amd64": "60236506920cc84a07ea7602f4514d05da2c07c7176e0634652f8a9c5ad677aa", + "linux-amd64": "11d8039e0a7a31b799a6f20a0e806e4128730e9a2595a7ffdec1443539d4c3f6", + } + }, + }, + "22.0.0.2": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha": { + "11": { + "darwin-amd64": "8280159b8a66c51a839c8079d885928a7f759d5da0632f3af7300df2b63a6323", + "linux-aarch64": "1cc0263d95f642dada4e290dca7f49c0456cefa7b690b67e3e5c159b537b2c58", + "linux-amd64": "bc86083bb7e2778c7e4fe4f55d74790e42255b96f7806a7fefa51d06f3bc7103", + }, + "17": { + "darwin-amd64": "d54af9d1f4d0d351827395a714ed84d2489b023b74a9c13a431cc9d31d1e8f9a", + "linux-aarch64": "c7d78387d2a144944f26773697c1b61d3478a081a1c5e7fc20f47f1f5f3c82c7", + "linux-amd64": "4f743e0ed3d974b7d619ca2ed6014554e8c12e5ebbb38b9bc9e820b182169bd4", + }, + }, + }, + "22.1.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha": { + "11": { + "darwin-aarch64": "06bc19a0b1e93aa3df5e15c08e97f8cef624cb6070eeae40a69a51ec7fd41152", + "darwin-amd64": "c4c9df94ca47b83b582758b87d39042732ba0193fc63f1ab93f6818005a1fe6b", + "linux-aarch64": "050a4d471247d91935f7f485e92d678f0163e1d6209e26e8fe75d7c924f73e71", + "linux-amd64": "78c628707007bb97b09562932ee16f50beb1c3fa4a36e4311a0465a4a718e683", + }, + "17": { + "darwin-aarch64": "06075cd390bd261721392cd6fd967b1d28c0500d1b5625272ea906038e5cd533", + "darwin-amd64": "b9327fa73531a822d9a27d25980396353869eefbd73fdcef89b4fceb9f529c75", + "linux-aarch64": "05128e361ed44beebc89495faaa504b0b975bf93aa5e512e217b3cf5e42dfada", + "linux-amd64": "f11d46098efbf78465a875c502028767e3de410a31e45d92a9c5cf5046f42aa2", + }, + }, + }, + "ce-22.3.2": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"], + "sha256": { + "11": { + "macos-x64": "da3c52cc68ce0fb4dcc27dba3c59beadafb7588fec9e9d2812f5bc7c7d00ab63", + "linux-x64": "0e638d2b7406fabc15a1079fc65431a4f33f6f754da77e4073de8433b40e7c4a", + "linux-aarch64": "506c99fef656653ccbc57facb9f200303bfcc21ea29679e7391046d0990493da", + "windows-x64": "ce02ce51f3339895cfeef5afe5e6caf6a61a165534a4995981de837f4da2e3c6" + }, + "17": { + "macos-x64": "470d538e34dc168255ee8ceadca74aab4b028ec6c699c4bd8e0226b0a7d3f155", + "linux-x64": "e5a5868c9b498643fadebfba2040e4d9a19a13ea58ec77cec8d64ab6ee691d1e", + "windows-x64": "23fcc0ef9d245fc087d2bcefb321d2ef13a87dd10bfc04b2a98c55db7b401732" + } + }, + }, + "oracle-17.0.7": { + "urls": ["https://download.oracle.com/graalvm/{java_version}/archive/graalvm-jdk-{version}_{platform}_bin.tar.gz"], + "prefix": { + "macos": "graalvm-jdk-17.0.8+9.1", + "linux": "graalvm-jdk-17.0.8+9.1", + "windows": "graalvm-jdk-17.0.8+9.1" + }, + "sha256": { + "macos-x64": "325c1c5adce1e8b569e87f1e4dffe852f73e7c25e720ea15977f2ca1d7dba1bb", + "macos-aarch64": "c73d2917c1b681679d90a7e3851b553c328e4028137e19adb301040fe0d43cfd", + "linux-x64": "2d6696aa209daa098c51fefc51906aa7bf0dbe28dcc560ef738328352564181b", + "linux-aarch64": "10cb0b61571befb20bf7c11ac4e10ff4e4801065a64ae425b39f34d401e352b1", + "windows-x64": "ea90259f08c7e358bed62c2b48d68d295aa7be38ab3cb922d74bab284e717f64" + } + }, + "oracle-20.0.1": { + "urls": ["https://download.oracle.com/graalvm/{java_version}/archive/graalvm-jdk-{version}_{platform}_bin.tar.gz"], + "prefix": { + "macos": "graalvm-jdk-20.0.1+9.1", + "linux": "graalvm-jdk-20.0.1+9.1", + "windows": "graalvm-jdk-20.0.2+9.1" + }, + "sha256": { + "macos-x64": "72c74c3702437824cba3db3435897cce3643e9443acac59f6cfd43f9444b1004", + "macos-aarch64": "b94877df825ccefbe8b6751e087d54aa9b8129f9d2919d29ea18e00900392da1", + "linux-x64": "0aef42ae97bc98acbd11dce81018a7916250fced6ee9f95a934816813e48e4f4", + "linux-aarch64": "890596363a864bdbe55c6a9678a87384e62660056b6951c385cceaae4807fbb8", + "windows-x64": "3ec83085b54a8de7d0c0ca893d225718cf6ff514f406af6d31a615da63ae9019" + } + }, + "oracle-latest": { + "urls": ["https://download.oracle.com/graalvm/{java_version}/latest/graalvm-jdk-{java_version}_{platform}_bin.tar.gz"], + "prefix": { + "macos": "graalvm-jdk-{version}", + "linux": "graalvm-jdk-{version}", + "windows": "graalvm-jdk-{version}", + }, + "sha256": { + "macos-x64": None, + "macos-aarch64": None, + "linux-x64": None, + "linux-aarch64": None, + "windows-x64": None, + } + } +} + +_graal_native_image_version_configs = { + "19.0.0": { + "urls": ["https://github.com/oracle/graal/releases/download/vm-{version}/native-image-installable-svm-{platform}-{version}.jar"], + "sha256": { + "8": { + "darwin-amd64": "4fa035b31cfd3d86d464e9a67b652c69a0cceb88c6b2f2ce629c55ca2113c786", + "linux-amd64": "1c794a3c038f4e6bb90542cf13ba3c6c793dcd193462bf56b8713fd24386e344", + }, + }, + }, + "19.3.1": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha256": { + "8": { + "darwin-amd64": "266d295456dfc588fae52ef2c26cd7e745e6fa0681271e677cad2dd9a1b09461", + "linux-amd64": "3fd2e5b5299c8ce7c939235b4d01df990aeb236f127f98fbf19b588c521793fa", + }, + "11": { + "darwin-amd64": "6bd2bace9773a2ac7ff8182a36f84507678e71f94bf3f0c4646a091100644e13", + "linux-amd64": "fef2e2c71a5408855026e022ae15fda50cb52769aa7d0ec008837f49196ee16a", + }, + }, + }, + "20.2.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha256": { + "8": { + "darwin-amd64": "4852abafe92e13cb6bf655bba4ba36721b93324ccc6777504f34c70094c583fb", + "linux-amd64": "6b5403e27282847acce180f0ae9637c3f26678f27047bbd5dfed92a5bef73ab2", + }, + "11": { + "darwin-amd64": "d60c321d6e680028f37954121eeebff0839a0a49a4436e5b41c636c3dd951de3", + "linux-amd64": "92b429939f12434575e4d586f79c5b686d322f29211d1608ed6055a97a35925c", + }, + }, + }, + "21.0.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha256": { + "8": { + "darwin-amd64": "f006e001d195de80cd71b28518f230815b6c00e8d3762148f4b23c09097debc7", + "linux-amd64": "8f6976b2a9a40d35df50402a3e893af41a6a6bc01301851a91672106d313f842", + }, + "11": { + "darwin-amd64": "68d95999312e96c8cd070a8ba1d9724bc4d4fbe03e29da2c392e021a5f393fb5", + "linux-amd64": "c70b00b4eabcc0140505acab756c394a88be7980634706cce11f53e09658707c", + }, + }, + }, + "21.3.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha256": { + "11": { + "darwin-amd64": "038ac1168b909cfb5e4d6437ee02a5aa8126cbb835aba7a3e6ab72042162e8d5", + "linux-amd64": "8958d4e0cad07340db0cf9e871776809e2f08fe0c93960f728fec75c4a96764f", + }, + "17": { + "darwin-amd64": "80ac09d45f8822413b9f16297da60da196013bbcfbc4bc7721f1257885ebe063", + "linux-amd64": "df488a04b5405c6443c90e94710cd3bd2be9adcb3768f91429aa494168d52440", + } + }, + }, + "22.0.0.2": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha": { + "11": { + "darwin-amd64": "03c27de6cce61ee8073e89252212457f3fbac2c0bc9bfa4acbff12176476c176", + "linux-aarch64": "51d41e890a5aabf8e7b9d4f4e0f88206ee70a261f7dbb0315d51770ab8f3009e", + "linux-amd64": "8504a3441f5b28b8fd625f676674a9216f082ae63a4e30d43930c80f9672e71d", + }, + "17": { + "darwin-amd64": "007fa742cd139d447f83d776b6d78e717c9df11d56a61061a5937547c20028b7", + "linux-aarch64": "798947d0a93988929d2b8e3555f7c65225e789124cd99fbc0c3aae5f350175db", + "linux-amd64": "8c25f650d58c2649c97061cb806dfaec9e685d5d2b80afc7cf72fe61d6891831", + }, + }, + }, + "22.1.0": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha": { + "11": { + "darwin-aarch64": "21f84ccf7b979dccc9091032fe76b5737b38e0092f282107cef75143dadb3bdb", + "darwin-amd64": "e0758687f4bd46f15fcee9b0a5bdd65d702ec81c41d465ee7229d3f4465bcf13", + "linux-aarch64": "12715793b223ce1db7ec7d0a339f0b578a0c9fb6dcc6607044e5af4fd33b25a7", + "linux-amd64": "36e4a2a9a73a19b03883f9e783bc8bde7c214bb0fa4b617379cb81798de425bf", + }, + "17": { + "darwin-aarch64": "beabecdd5b87e7536772d4dfe70abf4c5dd9847e87615464cf309138d21c39af", + "darwin-amd64": "e6bfe208bb28cd1d98da55e00fa705890a7f69286b919947b07d18cc9bb9c270", + "linux-aarch64": "6e10f6953ec8b9509c7a7d0194d57f265cf2a05dcb8f3272a6a8e847bda49cda", + "linux-amd64": "d81eecea15ebbf4f24850860c14104eaf6f8ae74574330e22afac533b8f96738", + }, + }, + }, + "22.3.2": { + "urls": ["https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"], + "sha256": { + "11": { + "darwin-amd64": "ae542383b033576e26d0431b0b62b4f7c048fee3b209dad2a257c4ae6345f1fb", + "linux-amd64": "7093522c446e16e7d3db81fbec858ef487709d6f58fe1ee3b654676629d786aa", + "linux-aarch64": "6594b5b5558542cd3f30f235967209809924ea2d3fbb75e9a43db7035370416b", + "windows-amd64": "b6be28b7841a5e1e7221c4dd96e5cd6dfcf5d99152564e08e43f02b4b891982c" + }, + "17": { + "darwin-amd64": "f3325ba7fbbcb865c3cc38ee531398482344fae2dd364073391568b0e5b0a77a", + "linux-amd64": "c70dedcf87f4aad917a5e35a972e7b1bd33f91d4eec35c4dfa4cb4123ad06a2a", + "linux-aarch64": "20f69183baeabc3270d056f3caa57bdccb3b0ea130e8773725130f2e60184563", + "windows-amd64": "b6be28b7841a5e1e7221c4dd96e5cd6dfcf5d99152564e08e43f02b4b891982c" + } + }, + } +} + +def _get_platform(ctx, newdist): + arch_labels = { + "amd64": "x64", + "aarch64": "aarch64", + } + if not newdist: + if ctx.os.name == "linux": + return "linux-amd64" + elif ctx.os.name == "mac os x": + return "darwin-amd64" + else: + fail("Unsupported operating system: " + ctx.os.name) + else: + if ctx.os.name == "linux": + return ("linux-%s" % (arch_labels[ctx.os.arch] or ctx.os.arch), "linux") + elif ctx.os.name == "mac os x": + return ("macos-%s" % (arch_labels[ctx.os.arch] or ctx.os.arch), "macos") + elif ctx.os.name == "windows": + return ("windows-%s" % (arch_labels[ctx.os.arch] or ctx.os.arch), "windows") + else: + fail("Unsupported operating system: " + ctx.os.name) + +def _check_version(version, java_version, newdist): + java_version_numeric = int(java_version) + gvm_version_major = None + + if version != "latest": + gvm_version_major = int(version.split(".")[0]) + + if newdist: + # rule 1: java less than 17 is not supported in the new distribution + if java_version_numeric < 17: fail("Modern GraalVM distribution not available for Java version: '%s'" % java_version) + + else: + if gvm_version_major and gvm_version_major > 22: fail("Legacy GraalVM distributions not available at version '%s'" % version) + +def _toolchain_config_impl(ctx): + ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name)) + ctx.file("BUILD.bazel", ctx.attr.build_file) + +def _graal_postinstall_actions(ctx): + if ctx.attr.setup_actions and len(ctx.attr.setup_actions) > 0: + for action in ctx.attr.setup_actions: + if not action.startsWith("gu "): + fail("GraalVM setup action did not start with 'gu'. Please only run GraalVM updater commands.") + + action_cmd = action.replace("gu ", "").split(" ") + exec_result = ctx.execute(["bin/gu"] + action_cmd, quiet = False) + if exec_result.return_code != 0: + fail("Unable to run GraalVM setup action '{cmd}':\n{stdout}\n{stderr}".format( + cmd = action, + stdout = exec_result.stdout, + stderr = exec_result.stderr + )) + +def _graal_bindist_repository_impl(ctx): + if ctx.attr.distribution == None: + platform = _get_platform(ctx, False) + version = ctx.attr.version + java_version = ctx.attr.java_version + format_args = { + "version": version, + "platform": platform, + "java_version": java_version, + } + + _check_version(ctx.attr.version, ctx.attr.java_version, False) + + # download graal + config = _graal_version_configs[version] + sha = config["sha256"][java_version][platform] + urls = [url.format(**format_args) for url in config["urls"]] + archive_internal_prefix = _graal_archive_internal_prefixes[platform].format(**format_args) + + ctx.download_and_extract( + url = urls, + sha256 = sha, + stripPrefix = archive_internal_prefix, + ) + + # download native image + native_image_config = _graal_native_image_version_configs[version] + native_image_sha = native_image_config["sha256"][java_version][platform] + native_image_urls = [url.format(**format_args) for url in native_image_config["urls"]] + + ctx.download( + url = native_image_urls, + sha256 = native_image_sha, + output = "native-image-installer.jar", + ) + + exec_result = ctx.execute(["bin/gu", "install", "--local-file", "native-image-installer.jar"], quiet = False) + if exec_result.return_code != 0: + fail("Unable to install native image:\n{stdout}\n{stderr}".format(stdout = exec_result.stdout, stderr = exec_result.stderr)) + + ctx.file("BUILD", """exports_files(glob(["**/*"]))""") + ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = ctx.name)) + _graal_postinstall_actions(ctx) + + else: + platform, os = _get_platform(ctx, True) + version = ctx.attr.version + distribution = ctx.attr.distribution + java_version = ctx.attr.java_version + + # new gvm distribution check + _check_version(ctx.attr.version, ctx.attr.java_version, True) + ctx.report_progress("Downloading GraalVM") + + dist_names = { + "ce": "ce", + "community": "ce", + "oracle": "oracle", + "gvm": "oracle", + } + dist_name = dist_names[ctx.attr.distribution] + if not dist_name: + fail("Cannot find distribution name for GraalVM: " + ctx.attr.distribution) + + # resolve & download vm + dist_tag = "{dist}-{version}".format(dist = dist_name, version = ctx.attr.version) + version = ctx.attr.version + java_version = ctx.attr.java_version + format_args = { + "version": version, + "platform": platform, + "java_version": java_version, + } + + # download graal + config = _graal_version_configs[dist_tag] + if platform not in config["sha256"]: + fail("Platform %s not supported at GraalVM version '%s' (distribution '%s'). Available: %s." % ( + platform, version, distribution, ", ".join(config["sha256"].keys()) + )) + + sha = None + if platform in config["sha256"]: + sha = config["sha256"][platform] + elif ctx.attr.sha256: + sha = ctx.attr.sha256 + + urls = [url.format(**format_args) for url in config["urls"]] + prefix = config["prefix"][os] + archive_internal_prefix = _graal_v2_archive_internal_prefixes[os].format(**format_args) + effective_prefix = "%s/%s" % (prefix, archive_internal_prefix) + + ctx.download_and_extract( + url = urls, + sha256 = sha or ctx.attr.sha256, + stripPrefix = effective_prefix, + ) + + if ctx.attr.components and len(ctx.attr.components) > 0: + ctx.report_progress("Downloading GraalVM components") + exec_result = ctx.execute(["bin/gu", "install"] + ctx.attr.components, quiet = False) + if exec_result.return_code != 0: + fail("Unable to install GraalVM components:\n{stdout}\n{stderr}".format(stdout = exec_result.stdout, stderr = exec_result.stderr)) + + toolchain_aliases_template = """ +alias( + name = "toolchain", + actual = "@{repo}//:toolchain", + visibility = ["//visibility:public"], +) +alias( + name = "bootstrap_runtime_toolchain", + actual = "@{repo}//:bootstrap_runtime_toolchain", + visibility = ["//visibility:public"], +) +alias( + name = "toolchain_gvm", + actual = "@{repo}//:gvm", + visibility = ["//visibility:public"], +) +alias( + name = "toolchain_native_image", + actual = "@{repo}//:native_image", + visibility = ["//visibility:public"], +) + """.format( + repo = ctx.attr.toolchain_config + ) + + ctx.file("BUILD.bazel", """ +exports_files(glob(["**/*"])) + +%s +%s +""" % ( + ctx.attr.enable_toolchain and toolchain_aliases_template or "", + _JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = java_version)), + ) + + ctx.file("WORKSPACE.bazel", """ +workspace(name = \"{name}\") +""".format(name = ctx.name)) + + _graal_postinstall_actions(ctx) + # Done. + +_graalvm_bindist_repository = repository_rule( + attrs = { + "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), + "enable_toolchain": attr.bool(mandatory = False), + "toolchain_config": attr.string(mandatory = True), + "sha256": attr.string(mandatory = False), + }, + implementation = _graal_bindist_repository_impl, +) + +_toolchain_config = repository_rule( + local = True, + implementation = _toolchain_config_impl, + attrs = { + "build_file": attr.string(), + }, +) + +def graalvm_repository( + name, + java_version, + version = "latest", + distribution = "oracle", + toolchain = True, + toolchain_prefix = "graalvm", + target_compatible_with = [], + components = [], + setup_actions = [], + register_all = False, + **kwargs): + + """Declare a GraalVM distribution repository, and optionally a Java toolchain to match. + + To register and use the GraalVM distribution as a toolchain, follow the Toolchains guide in the docs + (`docs/toolchain.md`). + + If `distribution` is set to `oracle`, an Oracle GraalVM installation is downloaded. This variant of + GraalVM may be subject to different license obligations; please consult Oracle's docs for more info. + + Oracle GraalVM distributions are downloaded directly from Oracle, which provides a `latest` download + endpoint. Set `version` to `latest` (the default value) to download the latest available version of + GraalVM matching the provided `java_version`. + + When installing the `latest` version of GraalVM, it is probably ideal to provide your own `sha256`. + In this case, the `rules_graalvm` package does not provide an SHA256 hash otherwise. + + Args: + name: Name of the VM repository. + java_version: Java version to use/declare. + version: Version of the GraalVM release. + distribution: Which GVM distribution to download - `ce`, `community`, or `oracle`. + toolchain: Whether to create a Java toolchain from this GVM installation. + toolchain_prefix: Name prefix to use for the toolchain; defaults to `graalvm`. + target_compatible_with: Compatibility tags to apply. + components: Components to install in the target GVM installation. + setup_actions: GraalVM Updater commands that should be run; pass complete command strings that start with "gu". + register_all: Register all GraalVM repositories and use `target_compatible_with` (experimental). + **kwargs: Passed to the underlying bindist repository rule. + """ + + if toolchain: + _toolchain_config( + name = name + "_toolchain_config_repo", + build_file = """ +config_setting( + name = "prefix_version_setting", + values = {{"java_runtime_version": "{prefix}_{version}"}}, + visibility = ["//visibility:private"], +) +config_setting( + name = "version_setting", + values = {{"java_runtime_version": "{version}"}}, + visibility = ["//visibility:private"], +) +alias( + name = "version_or_prefix_version_setting", + actual = select({{ + ":version_setting": ":version_setting", + "//conditions:default": ":prefix_version_setting", + }}), + visibility = ["//visibility:private"], +) +toolchain( + name = "gvm", + target_compatible_with = {target_compatible_with}, + target_settings = [":version_or_prefix_version_setting"], + toolchain_type = "@rules_graalvm//graalvm/toolchain:graalvm", + toolchain = "{toolchain}", + visibility = ["//visibility:public"], +) +toolchain( + name = "native_image", + target_compatible_with = {target_compatible_with}, + target_settings = [":version_or_prefix_version_setting"], + toolchain_type = "@rules_graalvm//graalvm/toolchain:graalvm_native_image", + toolchain = "{toolchain}", + visibility = ["//visibility:public"], +) +toolchain( + name = "toolchain", + target_compatible_with = {target_compatible_with}, + target_settings = [":version_or_prefix_version_setting"], + toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type", + toolchain = "{toolchain}", + visibility = ["//visibility:public"], +) +toolchain( + name = "bootstrap_runtime_toolchain", + # These constraints are not required for correctness, but prevent fetches of remote JDK for + # different architectures. As every Java compilation toolchain depends on a bootstrap runtime in + # the same configuration, this constraint will not result in toolchain resolution failures. + exec_compatible_with = {target_compatible_with}, + target_settings = [":version_or_prefix_version_setting"], + toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type", + toolchain = "{toolchain}", + visibility = ["//visibility:public"], +) +""".format( + prefix = toolchain_prefix or "graalvm", + version = java_version, + target_compatible_with = target_compatible_with, + toolchain = "@{repo}//:jdk".format(repo = name), + ), + ) + + if not register_all: + # register a specific GraalVM version at the host OS/arch pair + _graalvm_bindist_repository( + name = name, + version = version, + java_version = java_version, + distribution = distribution, + components = components, + setup_actions = setup_actions, + enable_toolchain = toolchain, + toolchain_config = "%s_toolchain_config_repo" % name, + **kwargs + ) + else: + fail("GraalVM rules `register_all` is not supported yet.") diff --git a/internal/maven.bzl b/internal/maven.bzl new file mode 100644 index 00000000..58773ffc --- /dev/null +++ b/internal/maven.bzl @@ -0,0 +1,43 @@ +"Defines useful macros for use with GraalVM projects." + +load( + "//internal:config.bzl", + "GRAALVM_VERSION", +) + +def graalvm(artifact, repository = "@maven", version = None, group = None): + """Return an artifact coordinate for GraalVM Maven artifact. + + Args: + artifact: Group and name of the artifact, separated with `:`. + repository: Name of the Maven Bazel repository to pull from; defaults to + `@maven`. + version: Version to use for the artifact; if `None`, a version is selected + which matches the active GraalVM installation. + group: Artifact group to use; if not provided, expected to be provided as + part of the `artifact`. + + Returns: + Desired artifact label.""" + + if ":" in artifact and group: + fail("Please provide the `group` and `artifact` separately, or together as part of `artifact`, but not both.") + + group = (group or artifact.split(":")[0]).replace(".", "_") + name = (group and artifact or artifact.split(":")[1]).replace(".", "_") + resolved_version = version or GRAALVM_VERSION + + if resolved_version: + formatted_version = resolved_version.replace(".", "_") + return Label("%s//:%s_%s_%s" % ( + repository, + group, + name, + formatted_version, + )) + + return Label("%s//:%s_%s" % ( + repository, + group, + name, + )) diff --git a/internal/repositories.bzl b/internal/repositories.bzl new file mode 100644 index 00000000..8fa33a8d --- /dev/null +++ b/internal/repositories.bzl @@ -0,0 +1,109 @@ +"Local declarations for the GraalVM Rules project workspace." + +load( + "//internal:config.bzl", + "GO_VERSION", + "GRAALVM_VERSION", + "GRAALVM_DISTRIBUTION", + "GRAALVM_JAVA_VERSION", + "GRAALVM_SHA", + "MAVEN_ARTIFACTS", + "MAVEN_REPOSITORIES", +) + +load( + "@bazel_skylib//:workspace.bzl", + "bazel_skylib_workspace", +) + +load( + "@rules_java//java:repositories.bzl", + "rules_java_dependencies", + "rules_java_toolchains", +) + +load( + "@//graalvm:repositories.bzl", + "graalvm_repository", +) + +load( + "@aspect_bazel_lib//lib:repositories.bzl", + "aspect_bazel_lib_dependencies", +) + +load( + "@rules_jvm_external//:repositories.bzl", + "rules_jvm_external_deps", +) + +load( + "@io_bazel_stardoc//:setup.bzl", + "stardoc_repositories", +) + +load( + "@rules_jvm_external//:defs.bzl", + "maven_install", +) + +load( + "@io_bazel_rules_go//go:deps.bzl", + "go_register_toolchains", + "go_rules_dependencies", +) + +def _setup_rules_graalvm_repositories(maven = True): + + """Setup dependencies for the GraalVM Rules project.""" + + # Go + + go_rules_dependencies() + + go_register_toolchains(version = GO_VERSION) + + # Skylib + + bazel_skylib_workspace() + + # Java + + rules_java_dependencies() + + rules_java_toolchains() + + # GraalVM + + graalvm_repository( + name = "graalvm", + version = GRAALVM_VERSION, + distribution = GRAALVM_DISTRIBUTION, + java_version = GRAALVM_JAVA_VERSION, + sha256 = GRAALVM_SHA, + ) + + native.register_toolchains("@graalvm//:toolchain") + + # Aspect: Bazel Lib + + aspect_bazel_lib_dependencies() + + # Rules JVM External + + rules_jvm_external_deps() + + # Stardoc + + stardoc_repositories() + + if maven: + maven_install( + artifacts = MAVEN_ARTIFACTS, + repositories = MAVEN_REPOSITORIES, + maven_install_json = "//:maven_install.json", + generate_compat_repositories = True, + ) + + +rules_graalvm_repositories = _setup_rules_graalvm_repositories diff --git a/internal/setup.bzl b/internal/setup.bzl new file mode 100644 index 00000000..20cfaf33 --- /dev/null +++ b/internal/setup.bzl @@ -0,0 +1,30 @@ +"Second-stage setup code for the GraalVM Rules project." + +load( + "@rules_jvm_external//:setup.bzl", + "rules_jvm_external_setup", +) + +load( + "@maven//:defs.bzl", + "pinned_maven_install", +) + +# load( +# "@bazel_skylib_gazelle_plugin//:setup.bzl", +# "bazel_skylib_gazelle_plugin_setup", +# ) + +def _rules_graalvm_setup_workspace(maven = False): + + """Perform second-stage setup of the GraalVM Rules codebase.""" + + rules_jvm_external_setup() + + # bazel_skylib_gazelle_plugin_setup() + + if maven: + pinned_maven_install() + + +rules_graalvm_workspace = _rules_graalvm_setup_workspace diff --git a/maven_install.json b/maven_install.json new file mode 100644 index 00000000..ae28b7c4 --- /dev/null +++ b/maven_install.json @@ -0,0 +1,528 @@ +{ + "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", + "__INPUT_ARTIFACTS_HASH": -2120315242, + "__RESOLVED_ARTIFACTS_HASH": 473033470, + "artifacts": { + "org.graalvm.compiler:compiler": { + "shasums": { + "jar": "63a63a67e74541194e19e399166e274ec0f129c20f0b0ac1a6ae97e2f146041a" + }, + "version": "23.0.1" + }, + "org.graalvm.nativeimage:native-image-base": { + "shasums": { + "jar": "1662008ac00cb35deda97e5ade5c987ffadb6c5d219126dd303bf0a33f918832" + }, + "version": "23.0.1" + }, + "org.graalvm.nativeimage:objectfile": { + "shasums": { + "jar": "d454922b6c3a0161f67ac1167eeeda153f3294af32f00923d534d2fc984e703b" + }, + "version": "23.0.1" + }, + "org.graalvm.nativeimage:pointsto": { + "shasums": { + "jar": "4ef0cd65b65e9820937f402c36d31434c201c904c600cc0d8c98963974599caf" + }, + "version": "23.0.1" + }, + "org.graalvm.nativeimage:svm": { + "shasums": { + "jar": "cddc7b58ba558d1cc99fee13ca56970f9898c0a71f1ec19d1bf5618b4aeb2994" + }, + "version": "23.0.1" + }, + "org.graalvm.sdk:graal-sdk": { + "shasums": { + "jar": "39c46559ad641a5bd1d2b6ff5106aa391929a7dec21ebb215502f9f40e0cd9b0" + }, + "version": "23.0.1" + }, + "org.graalvm.truffle:truffle-api": { + "shasums": { + "jar": "9adb4df44be7cc4c1cc507cc59521fd69e0a963b02a4998ccb04e50300a0d6b4" + }, + "version": "23.0.1" + } + }, + "dependencies": { + "org.graalvm.compiler:compiler": [ + "org.graalvm.sdk:graal-sdk", + "org.graalvm.truffle:truffle-api" + ], + "org.graalvm.nativeimage:native-image-base": [ + "org.graalvm.compiler:compiler" + ], + "org.graalvm.nativeimage:objectfile": [ + "org.graalvm.compiler:compiler" + ], + "org.graalvm.nativeimage:pointsto": [ + "org.graalvm.compiler:compiler", + "org.graalvm.nativeimage:native-image-base" + ], + "org.graalvm.nativeimage:svm": [ + "org.graalvm.compiler:compiler", + "org.graalvm.nativeimage:native-image-base", + "org.graalvm.nativeimage:objectfile", + "org.graalvm.nativeimage:pointsto", + "org.graalvm.sdk:graal-sdk" + ], + "org.graalvm.truffle:truffle-api": [ + "org.graalvm.sdk:graal-sdk" + ] + }, + "packages": { + "org.graalvm.compiler:compiler": [ + "org.graalvm.compiler.api.directives", + "org.graalvm.compiler.api.replacements", + "org.graalvm.compiler.api.runtime", + "org.graalvm.compiler.asm", + "org.graalvm.compiler.asm.aarch64", + "org.graalvm.compiler.asm.amd64", + "org.graalvm.compiler.bytecode", + "org.graalvm.compiler.code", + "org.graalvm.compiler.core", + "org.graalvm.compiler.core.aarch64", + "org.graalvm.compiler.core.amd64", + "org.graalvm.compiler.core.common", + "org.graalvm.compiler.core.common.alloc", + "org.graalvm.compiler.core.common.calc", + "org.graalvm.compiler.core.common.cfg", + "org.graalvm.compiler.core.common.memory", + "org.graalvm.compiler.core.common.spi", + "org.graalvm.compiler.core.common.type", + "org.graalvm.compiler.core.common.util", + "org.graalvm.compiler.core.gen", + "org.graalvm.compiler.core.match", + "org.graalvm.compiler.core.phases", + "org.graalvm.compiler.core.phases.fuzzing", + "org.graalvm.compiler.core.riscv64", + "org.graalvm.compiler.core.target", + "org.graalvm.compiler.debug", + "org.graalvm.compiler.graph", + "org.graalvm.compiler.graph.iterators", + "org.graalvm.compiler.graph.spi", + "org.graalvm.compiler.hightiercodegen", + "org.graalvm.compiler.hightiercodegen.irwalk", + "org.graalvm.compiler.hightiercodegen.lowerer", + "org.graalvm.compiler.hightiercodegen.reconstruction", + "org.graalvm.compiler.hightiercodegen.reconstruction.stackifier", + "org.graalvm.compiler.hightiercodegen.reconstruction.stackifier.blocks", + "org.graalvm.compiler.hightiercodegen.reconstruction.stackifier.scopes", + "org.graalvm.compiler.hightiercodegen.variables", + "org.graalvm.compiler.hotspot", + "org.graalvm.compiler.hotspot.aarch64", + "org.graalvm.compiler.hotspot.amd64", + "org.graalvm.compiler.hotspot.debug", + "org.graalvm.compiler.hotspot.lir", + "org.graalvm.compiler.hotspot.meta", + "org.graalvm.compiler.hotspot.nodes", + "org.graalvm.compiler.hotspot.nodes.type", + "org.graalvm.compiler.hotspot.phases", + "org.graalvm.compiler.hotspot.replacements", + "org.graalvm.compiler.hotspot.replacements.arraycopy", + "org.graalvm.compiler.hotspot.riscv64", + "org.graalvm.compiler.hotspot.stubs", + "org.graalvm.compiler.hotspot.word", + "org.graalvm.compiler.java", + "org.graalvm.compiler.lir", + "org.graalvm.compiler.lir.aarch64", + "org.graalvm.compiler.lir.alloc", + "org.graalvm.compiler.lir.alloc.lsra", + "org.graalvm.compiler.lir.alloc.lsra.ssa", + "org.graalvm.compiler.lir.amd64", + "org.graalvm.compiler.lir.amd64.phases", + "org.graalvm.compiler.lir.amd64.vector", + "org.graalvm.compiler.lir.asm", + "org.graalvm.compiler.lir.constopt", + "org.graalvm.compiler.lir.debug", + "org.graalvm.compiler.lir.dfa", + "org.graalvm.compiler.lir.framemap", + "org.graalvm.compiler.lir.gen", + "org.graalvm.compiler.lir.hashing", + "org.graalvm.compiler.lir.phases", + "org.graalvm.compiler.lir.profiling", + "org.graalvm.compiler.lir.ssa", + "org.graalvm.compiler.lir.stackslotalloc", + "org.graalvm.compiler.lir.util", + "org.graalvm.compiler.loop.phases", + "org.graalvm.compiler.nodeinfo", + "org.graalvm.compiler.nodes", + "org.graalvm.compiler.nodes.calc", + "org.graalvm.compiler.nodes.cfg", + "org.graalvm.compiler.nodes.debug", + "org.graalvm.compiler.nodes.extended", + "org.graalvm.compiler.nodes.gc", + "org.graalvm.compiler.nodes.graphbuilderconf", + "org.graalvm.compiler.nodes.java", + "org.graalvm.compiler.nodes.loop", + "org.graalvm.compiler.nodes.memory", + "org.graalvm.compiler.nodes.memory.address", + "org.graalvm.compiler.nodes.spi", + "org.graalvm.compiler.nodes.type", + "org.graalvm.compiler.nodes.util", + "org.graalvm.compiler.nodes.virtual", + "org.graalvm.compiler.options", + "org.graalvm.compiler.phases", + "org.graalvm.compiler.phases.common", + "org.graalvm.compiler.phases.common.inlining", + "org.graalvm.compiler.phases.common.inlining.info", + "org.graalvm.compiler.phases.common.inlining.info.elem", + "org.graalvm.compiler.phases.common.inlining.policy", + "org.graalvm.compiler.phases.common.inlining.walker", + "org.graalvm.compiler.phases.common.util", + "org.graalvm.compiler.phases.contract", + "org.graalvm.compiler.phases.graph", + "org.graalvm.compiler.phases.schedule", + "org.graalvm.compiler.phases.tiers", + "org.graalvm.compiler.phases.util", + "org.graalvm.compiler.printer", + "org.graalvm.compiler.replacements", + "org.graalvm.compiler.replacements.aarch64", + "org.graalvm.compiler.replacements.amd64", + "org.graalvm.compiler.replacements.arraycopy", + "org.graalvm.compiler.replacements.classfile", + "org.graalvm.compiler.replacements.gc", + "org.graalvm.compiler.replacements.nodes", + "org.graalvm.compiler.replacements.nodes.arithmetic", + "org.graalvm.compiler.runtime", + "org.graalvm.compiler.serviceprovider", + "org.graalvm.compiler.truffle.common", + "org.graalvm.compiler.truffle.common.hotspot", + "org.graalvm.compiler.truffle.common.hotspot.libgraal", + "org.graalvm.compiler.truffle.compiler", + "org.graalvm.compiler.truffle.compiler.hotspot", + "org.graalvm.compiler.truffle.compiler.hotspot.aarch64", + "org.graalvm.compiler.truffle.compiler.hotspot.amd64", + "org.graalvm.compiler.truffle.compiler.nodes", + "org.graalvm.compiler.truffle.compiler.nodes.asserts", + "org.graalvm.compiler.truffle.compiler.nodes.frame", + "org.graalvm.compiler.truffle.compiler.phases", + "org.graalvm.compiler.truffle.compiler.phases.inlining", + "org.graalvm.compiler.truffle.compiler.substitutions", + "org.graalvm.compiler.truffle.jfr", + "org.graalvm.compiler.truffle.options", + "org.graalvm.compiler.truffle.runtime", + "org.graalvm.compiler.truffle.runtime.collection", + "org.graalvm.compiler.truffle.runtime.debug", + "org.graalvm.compiler.truffle.runtime.hotspot", + "org.graalvm.compiler.truffle.runtime.hotspot.java", + "org.graalvm.compiler.truffle.runtime.hotspot.libgraal", + "org.graalvm.compiler.truffle.runtime.serviceprovider", + "org.graalvm.compiler.virtual.phases.ea", + "org.graalvm.compiler.word", + "org.graalvm.graphio", + "org.graalvm.jniutils", + "org.graalvm.libgraal", + "org.graalvm.libgraal.jni", + "org.graalvm.libgraal.jni.annotation", + "org.graalvm.nativebridge", + "org.graalvm.util", + "org.graalvm.util.json" + ], + "org.graalvm.nativeimage:native-image-base": [ + "com.oracle.svm.common.meta", + "com.oracle.svm.common.option", + "com.oracle.svm.util" + ], + "org.graalvm.nativeimage:objectfile": [ + "com.oracle.objectfile", + "com.oracle.objectfile.debugentry", + "com.oracle.objectfile.debugentry.range", + "com.oracle.objectfile.debuginfo", + "com.oracle.objectfile.elf", + "com.oracle.objectfile.elf.dwarf", + "com.oracle.objectfile.io", + "com.oracle.objectfile.macho", + "com.oracle.objectfile.pecoff", + "com.oracle.objectfile.pecoff.cv" + ], + "org.graalvm.nativeimage:pointsto": [ + "com.oracle.graal.pointsto", + "com.oracle.graal.pointsto.api", + "com.oracle.graal.pointsto.constraints", + "com.oracle.graal.pointsto.flow", + "com.oracle.graal.pointsto.flow.builder", + "com.oracle.graal.pointsto.flow.context", + "com.oracle.graal.pointsto.flow.context.bytecode", + "com.oracle.graal.pointsto.flow.context.object", + "com.oracle.graal.pointsto.heap", + "com.oracle.graal.pointsto.heap.value", + "com.oracle.graal.pointsto.infrastructure", + "com.oracle.graal.pointsto.meta", + "com.oracle.graal.pointsto.nodes", + "com.oracle.graal.pointsto.phases", + "com.oracle.graal.pointsto.plugins", + "com.oracle.graal.pointsto.reports", + "com.oracle.graal.pointsto.results", + "com.oracle.graal.pointsto.typestate", + "com.oracle.graal.pointsto.typestore", + "com.oracle.graal.pointsto.util" + ], + "org.graalvm.nativeimage:svm": [ + "com.oracle.graal.reachability", + "com.oracle.svm.core", + "com.oracle.svm.core.aarch64", + "com.oracle.svm.core.allocationprofile", + "com.oracle.svm.core.amd64", + "com.oracle.svm.core.c", + "com.oracle.svm.core.c.enums", + "com.oracle.svm.core.c.function", + "com.oracle.svm.core.c.libc", + "com.oracle.svm.core.c.struct", + "com.oracle.svm.core.classinitialization", + "com.oracle.svm.core.code", + "com.oracle.svm.core.collections", + "com.oracle.svm.core.config", + "com.oracle.svm.core.configure", + "com.oracle.svm.core.containers", + "com.oracle.svm.core.containers.cgroupv1", + "com.oracle.svm.core.containers.cgroupv2", + "com.oracle.svm.core.cpufeature", + "com.oracle.svm.core.deopt", + "com.oracle.svm.core.feature", + "com.oracle.svm.core.fieldvaluetransformer", + "com.oracle.svm.core.genscavenge", + "com.oracle.svm.core.genscavenge.graal", + "com.oracle.svm.core.genscavenge.graal.nodes", + "com.oracle.svm.core.genscavenge.jvmstat", + "com.oracle.svm.core.genscavenge.remset", + "com.oracle.svm.core.graal", + "com.oracle.svm.core.graal.aarch64", + "com.oracle.svm.core.graal.amd64", + "com.oracle.svm.core.graal.code", + "com.oracle.svm.core.graal.jdk", + "com.oracle.svm.core.graal.lir", + "com.oracle.svm.core.graal.meta", + "com.oracle.svm.core.graal.nodes", + "com.oracle.svm.core.graal.nodes.aarch64", + "com.oracle.svm.core.graal.phases", + "com.oracle.svm.core.graal.replacements", + "com.oracle.svm.core.graal.riscv64", + "com.oracle.svm.core.graal.snippets", + "com.oracle.svm.core.graal.snippets.aarch64", + "com.oracle.svm.core.graal.snippets.amd64", + "com.oracle.svm.core.graal.snippets.riscv64", + "com.oracle.svm.core.graal.stackvalue", + "com.oracle.svm.core.graal.thread", + "com.oracle.svm.core.graal.word", + "com.oracle.svm.core.handles", + "com.oracle.svm.core.headers", + "com.oracle.svm.core.heap", + "com.oracle.svm.core.heap.dump", + "com.oracle.svm.core.heapdump", + "com.oracle.svm.core.hub", + "com.oracle.svm.core.identityhashcode", + "com.oracle.svm.core.image", + "com.oracle.svm.core.invoke", + "com.oracle.svm.core.jdk", + "com.oracle.svm.core.jdk.localization", + "com.oracle.svm.core.jdk.localization.bundles", + "com.oracle.svm.core.jdk.localization.compression", + "com.oracle.svm.core.jdk.localization.compression.utils", + "com.oracle.svm.core.jdk.localization.substitutions", + "com.oracle.svm.core.jdk.localization.substitutions.modes", + "com.oracle.svm.core.jdk.management", + "com.oracle.svm.core.jdk.proxy", + "com.oracle.svm.core.jdk.resources", + "com.oracle.svm.core.jdk17", + "com.oracle.svm.core.jfr", + "com.oracle.svm.core.jfr.events", + "com.oracle.svm.core.jfr.logging", + "com.oracle.svm.core.jfr.sampler", + "com.oracle.svm.core.jfr.traceid", + "com.oracle.svm.core.jfr.utils", + "com.oracle.svm.core.jni", + "com.oracle.svm.core.jni.access", + "com.oracle.svm.core.jni.functions", + "com.oracle.svm.core.jni.headers", + "com.oracle.svm.core.jvmstat", + "com.oracle.svm.core.locks", + "com.oracle.svm.core.log", + "com.oracle.svm.core.meta", + "com.oracle.svm.core.methodhandles", + "com.oracle.svm.core.monitor", + "com.oracle.svm.core.nodes", + "com.oracle.svm.core.option", + "com.oracle.svm.core.os", + "com.oracle.svm.core.posix", + "com.oracle.svm.core.posix.aarch64", + "com.oracle.svm.core.posix.amd64", + "com.oracle.svm.core.posix.darwin", + "com.oracle.svm.core.posix.headers", + "com.oracle.svm.core.posix.headers.darwin", + "com.oracle.svm.core.posix.headers.linux", + "com.oracle.svm.core.posix.heapdump", + "com.oracle.svm.core.posix.jvmstat", + "com.oracle.svm.core.posix.linux", + "com.oracle.svm.core.posix.pthread", + "com.oracle.svm.core.posix.riscv64", + "com.oracle.svm.core.posix.thread", + "com.oracle.svm.core.properties", + "com.oracle.svm.core.reflect", + "com.oracle.svm.core.reflect.proxy", + "com.oracle.svm.core.reflect.serialize", + "com.oracle.svm.core.reflect.target", + "com.oracle.svm.core.riscv64", + "com.oracle.svm.core.sampler", + "com.oracle.svm.core.snippets", + "com.oracle.svm.core.stack", + "com.oracle.svm.core.thread", + "com.oracle.svm.core.threadlocal", + "com.oracle.svm.core.util", + "com.oracle.svm.core.util.coder", + "com.oracle.svm.core.util.json", + "com.oracle.svm.core.windows", + "com.oracle.svm.core.windows.headers", + "com.oracle.svm.graal", + "com.oracle.svm.graal.aarch64", + "com.oracle.svm.graal.amd64", + "com.oracle.svm.graal.hosted", + "com.oracle.svm.graal.isolated", + "com.oracle.svm.graal.meta", + "com.oracle.svm.graal.meta.aarch64", + "com.oracle.svm.graal.meta.amd64", + "com.oracle.svm.graal.stubs", + "com.oracle.svm.hosted", + "com.oracle.svm.hosted.ameta", + "com.oracle.svm.hosted.analysis", + "com.oracle.svm.hosted.analysis.flow", + "com.oracle.svm.hosted.annotation", + "com.oracle.svm.hosted.c", + "com.oracle.svm.hosted.c.codegen", + "com.oracle.svm.hosted.c.function", + "com.oracle.svm.hosted.c.info", + "com.oracle.svm.hosted.c.libc", + "com.oracle.svm.hosted.c.query", + "com.oracle.svm.hosted.c.util", + "com.oracle.svm.hosted.cenum", + "com.oracle.svm.hosted.classinitialization", + "com.oracle.svm.hosted.code", + "com.oracle.svm.hosted.code.aarch64", + "com.oracle.svm.hosted.code.amd64", + "com.oracle.svm.hosted.config", + "com.oracle.svm.hosted.dashboard", + "com.oracle.svm.hosted.diagnostic", + "com.oracle.svm.hosted.fieldfolding", + "com.oracle.svm.hosted.heap", + "com.oracle.svm.hosted.image", + "com.oracle.svm.hosted.image.sources", + "com.oracle.svm.hosted.javafx", + "com.oracle.svm.hosted.jdk", + "com.oracle.svm.hosted.jdk.localization", + "com.oracle.svm.hosted.jdk17", + "com.oracle.svm.hosted.jfr", + "com.oracle.svm.hosted.jni", + "com.oracle.svm.hosted.lambda", + "com.oracle.svm.hosted.meta", + "com.oracle.svm.hosted.methodhandles", + "com.oracle.svm.hosted.nodes", + "com.oracle.svm.hosted.option", + "com.oracle.svm.hosted.phases", + "com.oracle.svm.hosted.reflect", + "com.oracle.svm.hosted.reflect.proxy", + "com.oracle.svm.hosted.reflect.serialize", + "com.oracle.svm.hosted.snippets", + "com.oracle.svm.hosted.substitute", + "com.oracle.svm.hosted.thread", + "com.oracle.svm.hosted.util", + "com.oracle.svm.hosted.xml", + "com.oracle.svm.truffle", + "com.oracle.svm.truffle.api", + "com.oracle.svm.truffle.isolated" + ], + "org.graalvm.sdk:graal-sdk": [ + "com.oracle.svm.core.annotate", + "org.graalvm.collections", + "org.graalvm.home", + "org.graalvm.home.impl", + "org.graalvm.nativeimage", + "org.graalvm.nativeimage.c", + "org.graalvm.nativeimage.c.constant", + "org.graalvm.nativeimage.c.function", + "org.graalvm.nativeimage.c.struct", + "org.graalvm.nativeimage.c.type", + "org.graalvm.nativeimage.hosted", + "org.graalvm.nativeimage.impl", + "org.graalvm.nativeimage.impl.clinit", + "org.graalvm.options", + "org.graalvm.polyglot", + "org.graalvm.polyglot.impl", + "org.graalvm.polyglot.io", + "org.graalvm.polyglot.management", + "org.graalvm.polyglot.proxy", + "org.graalvm.word", + "org.graalvm.word.impl" + ], + "org.graalvm.truffle:truffle-api": [ + "com.oracle.truffle.api", + "com.oracle.truffle.api.debug", + "com.oracle.truffle.api.debug.impl", + "com.oracle.truffle.api.dsl", + "com.oracle.truffle.api.exception", + "com.oracle.truffle.api.frame", + "com.oracle.truffle.api.impl", + "com.oracle.truffle.api.impl.asm", + "com.oracle.truffle.api.impl.asm.commons", + "com.oracle.truffle.api.impl.asm.signature", + "com.oracle.truffle.api.impl.asm.tree", + "com.oracle.truffle.api.instrumentation", + "com.oracle.truffle.api.interop", + "com.oracle.truffle.api.io", + "com.oracle.truffle.api.library", + "com.oracle.truffle.api.memory", + "com.oracle.truffle.api.nodes", + "com.oracle.truffle.api.object", + "com.oracle.truffle.api.profiles", + "com.oracle.truffle.api.source", + "com.oracle.truffle.api.staticobject", + "com.oracle.truffle.api.strings", + "com.oracle.truffle.api.utilities", + "com.oracle.truffle.host", + "com.oracle.truffle.host.adapters", + "com.oracle.truffle.object", + "com.oracle.truffle.object.basic", + "com.oracle.truffle.polyglot", + "org.graalvm.shadowed.org.jcodings", + "org.graalvm.shadowed.org.jcodings.ascii", + "org.graalvm.shadowed.org.jcodings.constants", + "org.graalvm.shadowed.org.jcodings.exception", + "org.graalvm.shadowed.org.jcodings.specific", + "org.graalvm.shadowed.org.jcodings.transcode", + "org.graalvm.shadowed.org.jcodings.transcode.specific", + "org.graalvm.shadowed.org.jcodings.unicode", + "org.graalvm.shadowed.org.jcodings.util" + ] + }, + "repositories": { + "https://maven.pkg.st/": [ + "org.graalvm.compiler:compiler", + "org.graalvm.nativeimage:native-image-base", + "org.graalvm.nativeimage:objectfile", + "org.graalvm.nativeimage:pointsto", + "org.graalvm.nativeimage:svm", + "org.graalvm.sdk:graal-sdk", + "org.graalvm.truffle:truffle-api" + ], + "https://maven.google.com/": [ + "org.graalvm.compiler:compiler", + "org.graalvm.nativeimage:native-image-base", + "org.graalvm.nativeimage:objectfile", + "org.graalvm.nativeimage:pointsto", + "org.graalvm.nativeimage:svm", + "org.graalvm.sdk:graal-sdk", + "org.graalvm.truffle:truffle-api" + ], + "https://repo1.maven.org/maven2/": [ + "org.graalvm.compiler:compiler", + "org.graalvm.nativeimage:native-image-base", + "org.graalvm.nativeimage:objectfile", + "org.graalvm.nativeimage:pointsto", + "org.graalvm.nativeimage:svm", + "org.graalvm.sdk:graal-sdk", + "org.graalvm.truffle:truffle-api" + ] + }, + "version": "2" +} diff --git a/tasks/BUILD b/tasks/BUILD deleted file mode 100644 index 412ad1d6..00000000 --- a/tasks/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -load("@rules_adroit//rules/shellcheck:shell.bzl", "shell_binary") - -shell_binary( - name = "ci", - srcs = ["src/ci.sh"], - tags = ["manual"], - deps = [ - "@bazel_tools//tools/bash/runfiles", - ], -) \ No newline at end of file diff --git a/tasks/src/ci.sh b/tasks/src/ci.sh deleted file mode 100755 index 2d3f4f11..00000000 --- a/tasks/src/ci.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# --- begin bash runfile prelude -- -if [[ -e "${TEST_SRCDIR:-}" ]]; then - function runfile() { - echo "$TEST_SRCDIR/$1" - } -elif [[ -f "$0.runfiles_manifest" ]]; then - __runfiles_manifest_file="$0.runfiles_manifest" - export __runfiles_manifest_file - function runfile() { - grep -m1 "^$1 " "$__runfiles_manifest_file" | cut -d ' ' -f 2- - } -else - echo "please run this script through bazel" - exit 1 -fi -export -f runfile -# --- end bash runfile prelude -- - -set -euox pipefail -cd "${BUILD_WORKSPACE_DIRECTORY:-$(dirname "$0")/..}" - -bazel=./tools/bazel -$bazel test //... -$bazel run //example:main-native | grep Hello \ No newline at end of file diff --git a/tools/bazel b/tools/bazel deleted file mode 100755 index e4bbe163..00000000 --- a/tools/bazel +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bash - -default_bazel_version='0.26.1' - -if [ -z "$OVERRIDE_BAZEL_VERSION" ]; then - bazel_version="$default_bazel_version" -else - bazel_version="$OVERRIDE_BAZEL_VERSION" -fi - -case "$bazel_version" in - 'host') - bazel_version=$("$BAZEL_REAL" version | awk '/Build label/ {print $3}' | cut -d '-' -f 1) - bazel="$BAZEL_REAL" - ;; - '0.24.1') - darwin_sha='5fe570423945424a8c44b35c6d171fdde92e9ed90c3c321b83f2e380bcc966b9' - linux_sha='cf8210e538c37f195298905301a1221ca5b6a5a6658ccd1c4369a867aa2339c3' - ;; - '0.26.1') - darwin_sha='d0ceb4845a72507438ff173b54850c344ae41be8b6da69d0e663e4680be68ede' - linux_sha='488d6b7223a1b3db965b8831c562aba61229a690aad38d75cd8f43012fc04fe4' - ;; - *) - echo "The requested Bazel version '$bazel_version' is not supported" - exit 1 - ;; -esac - -if [ -z "$bazel" ]; then - bazel_bin_loc=~/.bazel_binaries - mkdir -p $bazel_bin_loc - bazel=$bazel_bin_loc/$bazel_version/bin/bazel-real -fi - -if ! [ -f "$bazel" ]; then - case $(uname -s) in - Darwin) - platform='darwin' - sha=$darwin_sha - ;; - Linux) - platform='linux' - sha=$linux_sha - ;; - *) - echo 'Your OS is not supported.' - exit 1 - ;; - esac - remote_source=https://github.com/bazelbuild/bazel/releases/download - installer_name="bazel-$bazel_version-installer-$platform-x86_64.sh" - url="$remote_source/$bazel_version/$installer_name" - ( - tmp_dir=$(mktemp -d) - trap 'rm -rf $tmp_dir' EXIT - cd "$tmp_dir" - (>&2 echo "downloading installer from") - (>&2 echo "$url") - curl -o installer.sh -L "$url" - generated_sha=$(shasum -a 256 installer.sh | awk '{print $1}') - if [ "$generated_sha" != "$sha" ]; then - echo "Sha 256 does not match, expected: $sha" - echo "But found $generated_sha" - echo "Recommend you: update the sha to the expected" - echo "and then re-run this script" - exit 1 - fi - chmod +x installer.sh - ./installer.sh --base=$bazel_bin_loc/"$bazel_version" --bin=$bazel_bin_loc/"$bazel_version"/bin_t - ) -fi - -extra_command_args=() - -IFS=. read -r major minor _ < <(echo "$bazel_version") -extra_command_args+=("--config=v$major.$minor") - -for (( i=1; i<=$#; i++ )) -do - case "${!i}" in - -*) - ;; - *) - n=$((i + 1)) - set -- "${@:1:$i}" "${extra_command_args[@]}" "${@:$n}" - break - ;; - esac -done - -abs_path() { - perl -MCwd -le ' - for (@ARGV) { - if ($p = Cwd::abs_path $_) { - print $p; - } else { - warn "abs_path: $_: $!\n"; - $ret = 1; - } - } - exit $ret' "$@" -} -root_workspace=$(cd "$(dirname "$(abs_path "$0")")"/..; pwd) -workspace=$(cd "$(dirname "$0")"/..; pwd) - -if [ "$workspace" != "$root_workspace" ]; then - set -- --bazelrc="$root_workspace"/.bazelrc "$@" -fi - -disk_cache="$root_workspace"/.bazel_cache -disk_cache_rc="$disk_cache"/bazelrc -mkdir -p "$disk_cache" -cat > "$disk_cache_rc" <&2 echo :: exec "$bazel" "$@") -exec "$bazel" "$@" diff --git a/tools/bazel/bazel5.bazelrc b/tools/bazel/bazel5.bazelrc new file mode 100644 index 00000000..70b12324 --- /dev/null +++ b/tools/bazel/bazel5.bazelrc @@ -0,0 +1 @@ +build --experimental_remote_build_event_upload=minimal \ No newline at end of file diff --git a/tools/bazel/bazel6.bazelrc b/tools/bazel/bazel6.bazelrc new file mode 100644 index 00000000..2ab1c0b4 --- /dev/null +++ b/tools/bazel/bazel6.bazelrc @@ -0,0 +1 @@ +build --experimental_remote_build_event_upload=minimal diff --git a/tools/bazel/bazel7.bazelrc b/tools/bazel/bazel7.bazelrc new file mode 100644 index 00000000..705f8d6a --- /dev/null +++ b/tools/bazel/bazel7.bazelrc @@ -0,0 +1 @@ +build --remote_build_event_upload=minimal diff --git a/tools/bazel/buildbuddy.bazelrc b/tools/bazel/buildbuddy.bazelrc new file mode 100644 index 00000000..f7a29619 --- /dev/null +++ b/tools/bazel/buildbuddy.bazelrc @@ -0,0 +1,3 @@ +build:buildbuddy --bes_results_url=https://app.buildbuddy.io/invocation/ +build:buildbuddy --bes_backend=grpcs://remote.buildbuddy.io +build:buildbuddy --build_metadata=REPO_URL=https://github.com/sgammon/rules_graalvm diff --git a/tools/bazel/cache.bazelrc b/tools/bazel/cache.bazelrc new file mode 100644 index 00000000..3b73a33c --- /dev/null +++ b/tools/bazel/cache.bazelrc @@ -0,0 +1,15 @@ + +build --config=disk-cache + +build:disk-cache --disk_cache=~/.cache/bazel + +build:buildless --remote_cache=https://bazel.less.build/cache/generic + +build --modify_execution_info=PackageTar=+no-remote +build --remote_local_fallback +build --incompatible_remote_results_ignore_disk +build --noexperimental_check_output_files --noexperimental_check_external_repository_files +build --nolegacy_important_outputs +build --incompatible_default_to_explicit_init_py +build --experimental_remote_merkle_tree_cache +build --experimental_remote_cache_compression diff --git a/tools/bazel/ci.bazelrc b/tools/bazel/ci.bazelrc new file mode 100644 index 00000000..4f9e7f6a --- /dev/null +++ b/tools/bazel/ci.bazelrc @@ -0,0 +1,4 @@ +build:ci --stamp +build:ci --build_metadata=ROLE=CI +build:ci --build_metadata=VISIBILITY=PUBLIC +build:ci --workspace_status_command=$(pwd)/tools/scripts/workspace.sh diff --git a/tools/bazel/java.bazelrc b/tools/bazel/java.bazelrc new file mode 100644 index 00000000..d2a3fd90 --- /dev/null +++ b/tools/bazel/java.bazelrc @@ -0,0 +1,12 @@ +build --experimental_strict_java_deps=strict +build --explicit_java_test_deps + +test --verbose_failures +test --test_output=errors + +build --sandbox_tmpfs_path=/tmp + +build --java_language_version=20 +build --java_runtime_version=graalvm_20 +build --extra_toolchains=@graalvm//:toolchain +build --extra_toolchains=@graalvm//:bootstrap_runtime_toolchain diff --git a/tools/bazel/profiles.bazelrc b/tools/bazel/profiles.bazelrc new file mode 100644 index 00000000..95ed16e3 --- /dev/null +++ b/tools/bazel/profiles.bazelrc @@ -0,0 +1,13 @@ + +# Mode: Debug +build:debug --sandbox_debug +build:debug --verbose_failures +build:debug --compilation_mode=dbg + +# Mode: Release +build:release --stamp +build:release --strip=always +build:release --compilation_mode=opt + +# Mode: Fastbuild +build:fastbuild --compilation_mode=fastbuild diff --git a/tools/scripts/latest_version_tag.sh b/tools/scripts/latest_version_tag.sh new file mode 100755 index 00000000..b529e68b --- /dev/null +++ b/tools/scripts/latest_version_tag.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +# Prints the latest BuildBuddy version tag, like "v2.12.8" +git tag -l 'v*' --sort=creatordate | + perl -nle 'if (/^v\d+\.\d+\.\d+$/) { print $_ }' | + tail -n1 diff --git a/tools/scripts/workspace.sh b/tools/scripts/workspace.sh new file mode 100755 index 00000000..fdce8382 --- /dev/null +++ b/tools/scripts/workspace.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# This script will be run bazel when building process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +set -eo pipefail # exit immediately if any command fails. + +user=$(whoami); +echo "USER $user"; + +commit_sha=$(git rev-parse HEAD) +echo "COMMIT_SHA $commit_sha" + +git_branch=$(git rev-parse --abbrev-ref HEAD) +echo "GIT_BRANCH $git_branch" + +git_tree_status=$(git diff-index --quiet HEAD -- && echo 'Clean' || echo 'Modified') +echo "GIT_TREE_STATUS $git_tree_status" + +# Note: the "STABLE_" suffix causes these to be part of the "stable" workspace +# status, which may trigger rebuilds of certain targets if these values change +# and you're building with the "--stamp" flag. +latest_version_tag=$(./tools/scripts/latest_version_tag.sh) +echo "STABLE_VERSION_TAG $latest_version_tag" +echo "STABLE_COMMIT_SHA $commit_sha"