bazel-contrib / rules_jsonnet

Jsonnet rules for Bazel
https://bazelbuild.github.io/rules_jsonnet/
Apache License 2.0
68 stars 73 forks source link

Bazel toolchain support #192

Closed Kevintjeb closed 3 months ago

Kevintjeb commented 7 months ago

This adds the Bazel toolchain support to change the effective Jsonnet compiler. Go-Jsonnet, Jsonnet (cpp) and Jrsonnet (Rust) are implemented.

There are some incompatibilities:

Due to these incompatibilities there are two addditional attributes on the toolchain: the flags to pass during directory creation and if manifest files are supported.

When adding rules_jsonnet as a bzlmod module, a user can now select the preferred compiler by using:

jsonnet = use_extension("@rules_jsonnet//jsonnet:extensions.bzl", "jsonnet")
jsonnet.compiler(name = "rust")

Currently there are three options: cpp, go and rust.

Additionally, this fixes CI:

The current .bazelci expects a variable ${{ jsonnet_port }} to be defined. However, that isn't the case with the current setup. The current behaviour is an empty ${{ jsonnet_port }} which causes the implementation to fall back to the default (Go), effectively disabling the cpp tests.

The CI runs:

bazel test //... --extra_toolchains=@rules_jsonnet//jsonnet:go_jsonnet_toolchain
bazel test //... --extra_toolchains=@rules_jsonnet//jsonnet:rust_jsonnet_toolchain
bazel test //... --extra_toolchains=@rules_jsonnet//jsonnet:cpp_jsonnet_toolchain

Lastly, fix docs:

The current docs setup only supports a single source file for docs generation (jsonnet.bzl). Now that toolchains.bzl is also a file that must be included in the docs generation, we use a helper file docs.bzl to aggregate what needs to be documented.

Note:

To use the Rust Jsonnet compiler a Nightly Rust version for the host tools is required because -Z bindeps is needed to compile the Jrsonnet binary.

Add the following snippet to the Module.bazel file:

bazel_dep(name = "rules_rust", version = "0.45.1")

rust_host = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")
rust_host.host_tools(
    version = "nightly/2024-05-02",
)

Fixes #150

google-cla[bot] commented 7 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.