Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel toolchain support #192

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

Kevintjeb
Copy link
Contributor

@Kevintjeb Kevintjeb commented Apr 11, 2024

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:

  • Jsonnet (cpp) does not support the -c flag to create nested output directories.

  • Jrsonnet (Rust) does not support manifest files containing the files that were generated by the Jsonnet program. It's currently only able to write those outputs to stdout.

  • Jrsonnet text output (e.g. errors) is different compared to the cpp and Go implementations.

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

Copy link

google-cla bot commented Apr 11, 2024

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.

@Kevintjeb Kevintjeb force-pushed the KB/toolchain-bzlmod-ci branch 3 times, most recently from c381585 to 4dabbb7 Compare April 13, 2024 18:57
@Kevintjeb Kevintjeb force-pushed the KB/toolchain-bzlmod-ci branch 3 times, most recently from 8ef87bf to c44c85f Compare June 6, 2024 14:07
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:

- Jsonnet (cpp) does not support the -c flag to create nested output
directories.

- Jrsonnet (Rust) does not support manifest files containing the
files that were generated by the Jsonnet program. It's currently only
able to write those outputs to stdout.

- Jrsonnet text output (e.g. errors) is different compared to the cpp and
Go implementations.

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.
@Kevintjeb Kevintjeb force-pushed the KB/toolchain-bzlmod-ci branch from c44c85f to bba21cd Compare July 16, 2024 09:46
@EdSchouten EdSchouten merged commit 04221a6 into bazel-contrib:master Jul 16, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compatibility with jrsonnet
2 participants