Skip to content

Commit f3d78bf

Browse files
authored
Upgrade all dependencies (#239)
* Upgrade all dependencies We now no longer need a nightly version of the Rust toolchain to build jrsonnet. The latest stable version works perfectly fine. However, we do still need a nightly version of the host tools to make bindeps work. Because we now also set the host tools repo name properly, we no longer need to juggle with Rust in examples/MODULE.bazel. Fixes: #224 #225 #226 #228 #229 #230 #234 #235 #236 #237 #238 * Add a workaround for aspect_bazel_lib not wrapping platform labels * Make import paths in jsonnet_to_json_test() work with modern Bazel Modern Bazel no longer includes files in the runfiles directory using the long path layout. We now only need to use short paths. Unfortunately, Bazel lacks some proper APIs for generating those in pieces, so we need to do some string substitution.
1 parent 44e0de1 commit f3d78bf

File tree

6 files changed

+69
-36
lines changed

6 files changed

+69
-36
lines changed

MODULE.bazel

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module(
33
version = "0.6.0",
44
)
55

6-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
7-
bazel_dep(name = "jsonnet", version = "0.20.0")
8-
bazel_dep(name = "jsonnet_go", version = "0.20.0")
9-
bazel_dep(name = "rules_python", version = "1.2.0")
10-
bazel_dep(name = "rules_rust", version = "0.54.1")
6+
bazel_dep(name = "bazel_skylib", version = "1.8.0")
7+
bazel_dep(name = "jsonnet", version = "0.21.0")
8+
bazel_dep(name = "jsonnet_go", version = "0.21.0")
9+
bazel_dep(name = "rules_python", version = "1.5.0")
10+
bazel_dep(name = "rules_rust", version = "0.62.0")
1111

1212
jsonnet = use_extension("//jsonnet:extensions.bzl", "jsonnet")
1313
use_repo(jsonnet, "rules_jsonnet_toolchain")
@@ -16,23 +16,22 @@ register_toolchains("@rules_jsonnet_toolchain//:toolchain")
1616

1717
rust_host = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")
1818
rust_host.host_tools(
19-
version = "nightly/2024-05-02",
19+
name = "rust_host_tools_jsonnet",
20+
sha256s = {
21+
"2025-07-01/rustc-nightly-aarch64-apple-darwin.tar.xz": "b5fb4b5272fea4d4ef6e3896e484e9748fda4f29be428ae3a55c22f70566b54c",
22+
"2025-07-01/clippy-nightly-aarch64-apple-darwin.tar.xz": "a0715713220f6cb56031a86c91de7a26d1f89d149afc2e01af625a89ca63f673",
23+
"2025-07-01/cargo-nightly-aarch64-apple-darwin.tar.xz": "4eb240f69df9f9159c6fef128c3b7c24e5e1ae8aaf1357de4924fd518bd54941",
24+
"2025-07-01/llvm-tools-nightly-aarch64-apple-darwin.tar.xz": "ab8d9977ba3187819008b70dab317654bb290fc220cfea35b4f2ea165ce32e70",
25+
"2025-07-01/rust-std-nightly-aarch64-apple-darwin.tar.xz": "da6c8e6f256bb6512485db068d35109a3c77ccac678bc28134665cd1b547863b",
26+
},
27+
version = "nightly/2025-07-01",
2028
)
29+
use_repo(rust_host, "rust_host_tools_jsonnet")
2130

2231
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
2332
rust.toolchain(
2433
edition = "2021",
25-
sha256s = {
26-
"2024-05-01/rustc-nightly-aarch64-apple-darwin.tar.xz": "3c3d4693b8e846c9c250bb14a97654657ca62a5eb20617a875c34462582daf83",
27-
"2024-05-01/clippy-nightly-aarch64-apple-darwin.tar.xz": "379e22e343a7b1c2e39b030810ff633d800d0daae0f8fd6bf00181402c42be4e",
28-
"2024-05-01/cargo-nightly-aarch64-apple-darwin.tar.xz": "899aec41e675146359d30a296db488f114cd280aef9dea566e178a8bb6f33774",
29-
"2024-05-01/llvm-tools-nightly-aarch64-apple-darwin.tar.xz": "4b04ceaf724bea888fb1e5e6bd9a9a963196f585d4f73036e783a2c51d4e907e",
30-
"2024-05-01/rust-std-nightly-aarch64-apple-darwin.tar.xz": "bf52ea3e1ac669455694079fb83b6bd0d446e759b9ab3502f75615d538e646a0",
31-
},
32-
# Nightly version is required to be able to depend on a binary dependency
33-
# with Cargo.
34-
# See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies.
35-
versions = ["nightly/2024-05-01"],
34+
versions = ["1.88.0"],
3635
)
3736
use_repo(rust, "rust_toolchains")
3837

@@ -52,5 +51,7 @@ crate.annotation(
5251
crate = "jrsonnet",
5352
gen_binaries = ["jrsonnet"],
5453
)
55-
crate.from_specs()
54+
crate.from_specs(
55+
host_tools = "@rust_host_tools_jsonnet",
56+
)
5657
use_repo(crate, "crates")

docs/MODULE.bazel

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ module(
33
version = "0.0.0",
44
)
55

6-
bazel_dep(name = "aspect_bazel_lib", version = "2.9.4")
7-
bazel_dep(name = "stardoc", version = "0.7.2")
8-
6+
bazel_dep(name = "aspect_bazel_lib", version = "2.19.4")
7+
bazel_dep(name = "stardoc", version = "0.8.0")
98
bazel_dep(name = "rules_jsonnet", version = "0.0.0")
109
local_path_override(
1110
module_name = "rules_jsonnet",
1211
path = "..",
1312
)
13+
14+
single_version_override(
15+
module_name = "aspect_bazel_lib",
16+
patches = ["//:aspect_bazel_lib-label.diff"],
17+
)

docs/aspect_bazel_lib-label.diff

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git lib/private/docs.bzl lib/private/docs.bzl
2+
index feeb852..0395e3d 100644
3+
--- lib/private/docs.bzl
4+
+++ lib/private/docs.bzl
5+
@@ -20,7 +20,7 @@ def stardoc_with_diff_test(
6+
target_compatible_with = kwargs.pop("target_compatible_with", select({
7+
# stardoc produces different line endings on Windows
8+
# which makes the diff_test fail
9+
- "@platforms//os:windows": ["@platforms//:incompatible"],
10+
+ Label("@platforms//os:windows"): ["@platforms//:incompatible"],
11+
"//conditions:default": [],
12+
}))
13+

docs/jsonnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Example:
191191
| <a id="jsonnet_to_json-deps"></a>deps | List of targets that are required by the `srcs` Jsonnet files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
192192
| <a id="jsonnet_to_json-src"></a>src | The `.jsonnet` file to convert to JSON. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
193193
| <a id="jsonnet_to_json-data"></a>data | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
194-
| <a id="jsonnet_to_json-outs"></a>outs | Names of the output `.json` files to be generated by this rule.<br><br>If you are generating only a single JSON file and are not using jsonnet multiple output files, then this attribute should only contain the file name of the JSON file you are generating.<br><br>If you are generating multiple JSON files using jsonnet multiple file output (`jsonnet -m`), then list the file names of all the JSON files to be generated. The file names specified here must match the file names specified in your `src` Jsonnet file.<br><br>For the case where multiple file output is used but only for generating one output file, set the `multiple_outputs` attribute to 1 to explicitly enable the `-m` flag for multiple file output.<br><br>This attribute is incompatible with `out_dir`. | List of labels | optional | `[]` |
194+
| <a id="jsonnet_to_json-outs"></a>outs | Names of the output `.json` files to be generated by this rule.<br><br>If you are generating only a single JSON file and are not using jsonnet multiple output files, then this attribute should only contain the file name of the JSON file you are generating.<br><br>If you are generating multiple JSON files using jsonnet multiple file output (`jsonnet -m`), then list the file names of all the JSON files to be generated. The file names specified here must match the file names specified in your `src` Jsonnet file.<br><br>For the case where multiple file output is used but only for generating one output file, set the `multiple_outputs` attribute to 1 to explicitly enable the `-m` flag for multiple file output.<br><br>This attribute is incompatible with `out_dir`. | List of labels; <a href="https://bazel.build/reference/be/common-definitions#configurable-attributes">nonconfigurable</a> | optional | `[]` |
195195
| <a id="jsonnet_to_json-code_vars"></a>code_vars | Deprecated (use 'ext_code'). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
196196
| <a id="jsonnet_to_json-ext_code"></a>ext_code | - | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
197197
| <a id="jsonnet_to_json-ext_code_envs"></a>ext_code_envs | - | List of strings | optional | `[]` |

examples/MODULE.bazel

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,3 @@ local_path_override(
2323
module_name = "other_toolchain_module",
2424
path = "other_toolchain_module",
2525
)
26-
27-
bazel_dep(name = "rules_rust", version = "0.45.1")
28-
29-
rust_host = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")
30-
rust_host.host_tools(
31-
version = "nightly/2024-05-02",
32-
)

jsonnet/jsonnet.bzl

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,25 @@ _JSONNET_FILETYPE = [
2020
".json",
2121
]
2222

23-
def _get_import_paths(label, files, imports):
23+
def _get_import_paths(label, files, imports, short_path):
24+
# TODO: Is there a cleaner way to compute the short paths here?
2425
return [
2526
# Implicitly add the workspace root as an import path.
26-
paths.join(".", file.root.path, label.workspace_root)
27+
paths.join(
28+
".",
29+
"" if short_path else file.root.path,
30+
label.workspace_root.replace("external/", "../") if short_path else label.workspace_root,
31+
)
2732
for file in files
2833
] + [
2934
# Explicitly provided import paths.
30-
paths.join(".", file.root.path, label.workspace_root, label.package, im)
35+
paths.join(
36+
".",
37+
"" if short_path else file.root.path,
38+
label.workspace_root.replace("external/", "../") if short_path else label.workspace_root,
39+
label.package,
40+
im,
41+
)
3142
for file in files
3243
for im in imports
3344
]
@@ -44,15 +55,21 @@ def _setup_deps(deps):
4455
dependencies
4556
imports: List of Strings containing import flags set by transitive
4657
dependency targets.
58+
short_imports: List of Strings containing import flags set by
59+
transitive dependency targets, when invoking Jsonnet as part
60+
of a test where dependencies are stored in runfiles.
4761
"""
4862
transitive_sources = []
4963
imports = []
64+
short_imports = []
5065
for dep in deps:
5166
transitive_sources.append(dep[JsonnetLibraryInfo].transitive_jsonnet_files)
5267
imports.append(dep[JsonnetLibraryInfo].imports)
68+
short_imports.append(dep[JsonnetLibraryInfo].short_imports)
5369

5470
return struct(
5571
imports = depset(transitive = imports),
72+
short_imports = depset(transitive = short_imports),
5673
transitive_sources = depset(transitive = transitive_sources, order = "postorder"),
5774
)
5875

@@ -63,9 +80,13 @@ def _jsonnet_library_impl(ctx):
6380
depinfo = _setup_deps(ctx.attr.deps)
6481
sources = depset(ctx.files.srcs, transitive = [depinfo.transitive_sources])
6582
imports = depset(
66-
_get_import_paths(ctx.label, ctx.files.srcs, ctx.attr.imports),
83+
_get_import_paths(ctx.label, ctx.files.srcs, ctx.attr.imports, False),
6784
transitive = [depinfo.imports],
6885
)
86+
short_imports = depset(
87+
_get_import_paths(ctx.label, ctx.files.srcs, ctx.attr.imports, True),
88+
transitive = [depinfo.short_imports],
89+
)
6990

7091
return [
7192
DefaultInfo(
@@ -80,6 +101,7 @@ def _jsonnet_library_impl(ctx):
80101
),
81102
JsonnetLibraryInfo(
82103
imports = imports,
104+
short_imports = short_imports,
83105
transitive_jsonnet_files = sources,
84106
),
85107
]
@@ -173,7 +195,7 @@ def _jsonnet_to_json_impl(ctx):
173195
"set -e;",
174196
ctx.toolchains["//jsonnet:toolchain_type"].jsonnetinfo.compiler.path,
175197
] +
176-
["-J " + shell.quote(im) for im in _get_import_paths(ctx.label, [ctx.file.src], ctx.attr.imports)] +
198+
["-J " + shell.quote(im) for im in _get_import_paths(ctx.label, [ctx.file.src], ctx.attr.imports, False)] +
177199
["-J " + shell.quote(im) for im in depinfo.imports.to_list()] +
178200
other_args +
179201
["--ext-str %s=%s" %
@@ -388,8 +410,8 @@ def _jsonnet_to_json_test_impl(ctx):
388410
other_args = ctx.attr.extra_args + (["-y"] if ctx.attr.yaml_stream else [])
389411
jsonnet_command = " ".join(
390412
["OUTPUT=$(%s" % ctx.toolchains["//jsonnet:toolchain_type"].jsonnetinfo.compiler.short_path] +
391-
["-J " + shell.quote(im) for im in _get_import_paths(ctx.label, [ctx.file.src], ctx.attr.imports)] +
392-
["-J " + shell.quote(im) for im in depinfo.imports.to_list()] +
413+
["-J " + shell.quote(im) for im in _get_import_paths(ctx.label, [ctx.file.src], ctx.attr.imports, True)] +
414+
["-J " + shell.quote(im) for im in depinfo.short_imports.to_list()] +
393415
other_args +
394416
["--ext-str %s=%s" %
395417
(_quote(key), _quote(val)) for key, val in jsonnet_ext_strs.items()] +

0 commit comments

Comments
 (0)