Skip to content

Commit 8192e41

Browse files
authored
Merge pull request #94 from tweag/cb/upgrade-bazel
Upgrade Bazel versions, remove Bazel 5
2 parents 9d16f12 + 97d4ce7 commit 8192e41

File tree

8 files changed

+54
-53
lines changed

8 files changed

+54
-53
lines changed

.bazeliskrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
USE_BAZEL_VERSION=7.0.0
1+
USE_BAZEL_VERSION=7.4.1

.bazelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Compatibility options (per bazel version)
2-
common:bazel8 --noincompatible_disallow_ctx_resolve_tools
2+
common:bazel8 --config=common
33

44
common:bazel7 --config=common
55

66
common:bazel6 --config=common
77

8-
common:bazel5 --config=common
9-
108
common:common --noverbose_failures
119

1210
# Remote Cache Configuration

.github/workflows/workflow.yaml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,7 @@ jobs:
2020
matrix:
2121
os: [ubuntu-latest, macos-latest, windows-latest]
2222
bazel_mode: [workspace, module]
23-
version: ["5.4.1", "6.4.0", "7.0.0", "8.0.0"]
24-
include:
25-
# Bazel 5.4.1 does not find Visual Studio on windows-2022. So, we
26-
# test it on windows-2019.
27-
- version: 5.4.1
28-
bazel_mode: workspace
29-
os: windows-2019
30-
exclude:
31-
- version: 5.4.1
32-
bazel_mode: module
33-
# Bazel 5.4.1 does not find Visual Studio on windows-2022.
34-
- version: 5.4.1
35-
os: windows-latest
23+
version: ["6.5.0", "7.4.1", "8.0.0"]
3624
defaults:
3725
run:
3826
shell: bash
@@ -62,7 +50,7 @@ jobs:
6250
uses: tweag/write-bazelrc@v0
6351
if: ${{ matrix.bazel_mode == 'module' }}
6452
with:
65-
content: build --experimental_enable_bzlmod
53+
content: build --enable_bzlmod
6654
- name: Configure the Bazel version
6755
run: |
6856
echo "USE_BAZEL_VERSION=${{ matrix.version }}" > .bazeliskrc

sh/experimental/posix_hermetic.bzl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,10 @@ def _custom_rule_impl(ctx):
164164
"RUNFILES_DIR": toolchain.tool[DefaultInfo].files_to_run.runfiles_manifest.dirname,
165165
"RUNFILES_MANIFEST_FILE": toolchain.tool[DefaultInfo].files_to_run.runfiles_manifest.path,
166166
}
167-
(tools_inputs, tools_manifest) = ctx.resolve_tools(tools = [toolchain.tool])
168167
169168
ctx.actions.run(
170-
executable = sh_binaries_info.executables["grep"],
169+
executable = sh_binaries_info.files_to_run["grep"],
171170
env = tools_env, # Pass the environment into the action.
172-
inputs = tools_inputs,
173-
input_manifests = tools_manifest,
174171
...
175172
)
176173
```

sh/sh.bzl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ShBinariesInfo = provider(
1111
doc = "The description of a sh_binaries target.",
1212
fields = {
1313
"executables": "dict of File, The executables included in the bundle by name.",
14+
"files_to_run": "dict of FilesToRunProvider, to be passed to ctx.action.run / ctx.action.run_shell.",
1415
"paths": "depset of string, The directories under which the binaries can be found.",
1516
},
1617
)
@@ -21,13 +22,15 @@ def _sh_binaries_from_srcs(ctx, srcs, is_windows):
2122
executable_files = []
2223
runfiles = ctx.runfiles()
2324
executables_dict = dict()
25+
files_to_run_dict = dict()
2426
executable_paths = []
2527

2628
for src in srcs:
2729
if src[DefaultInfo].files_to_run == None or src[DefaultInfo].files_to_run.executable == None:
2830
fail("srcs must be executable, but '{}' is not.".format(src.label))
2931

30-
executable = src[DefaultInfo].files_to_run.executable
32+
files_to_run = src[DefaultInfo].files_to_run
33+
executable = files_to_run.executable
3134
name = executable.basename
3235
if is_windows:
3336
(noext, ext) = paths.split_extension(executable.basename)
@@ -44,18 +47,21 @@ def _sh_binaries_from_srcs(ctx, srcs, is_windows):
4447
executable_files.append(executable)
4548
runfiles = runfiles.merge(src[DefaultInfo].default_runfiles)
4649
executables_dict[name] = executable
50+
files_to_run_dict[name] = files_to_run
4751
executable_paths.append(executable.dirname)
4852

4953
return struct(
5054
executable_files = executable_files,
5155
runfiles = runfiles,
5256
executables_dict = executables_dict,
5357
executable_paths = executable_paths,
58+
files_to_run_dict = files_to_run_dict,
5459
)
5560

5661
def _sh_binaries_from_deps(ctx, deps):
5762
executable_files = []
5863
runfiles = ctx.runfiles()
64+
files_to_run_dict = dict()
5965
executables_dict = dict()
6066
executable_paths = []
6167

@@ -66,13 +72,15 @@ def _sh_binaries_from_deps(ctx, deps):
6672
executable_files.append(dep[DefaultInfo].files)
6773
runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)
6874
executables_dict.update(dep[ShBinariesInfo].executables)
75+
files_to_run_dict.update(dep[ShBinariesInfo].files_to_run)
6976
executable_paths.append(dep[ShBinariesInfo].paths)
7077

7178
return struct(
7279
executable_files = executable_files,
7380
runfiles = runfiles,
7481
executables_dict = executables_dict,
7582
executable_paths = executable_paths,
83+
files_to_run_dict = files_to_run_dict,
7684
)
7785

7886
def _runfiles_from_data(ctx, data):
@@ -91,6 +99,11 @@ def _mk_sh_binaries_info(direct, transitive):
9199
transitive.executables_dict,
92100
direct.executables_dict,
93101
),
102+
files_to_run = dicts.add(
103+
# The order is important so that srcs take precedence over deps on collision.
104+
transitive.files_to_run_dict,
105+
direct.files_to_run_dict,
106+
),
94107
paths = depset(
95108
direct = direct.executable_paths,
96109
# Reverse the order so that later deps take precedence.
@@ -244,13 +257,10 @@ load("@rules_sh//sh:sh.bzl", "ShBinariesInfo")
244257
245258
def _custom_rule_impl(ctx):
246259
tools = ctx.attr.tools[ShBinariesInfo]
247-
(tools_inputs, tools_manifest) = ctx.resolve_tools(tools = [ctx.attr.tools])
248260
249261
# Use binary-a in a `run` action.
250262
ctx.actions.run(
251-
executable = tools.executables["binary-a"], # Invoke binary-a
252-
inputs = tools_inputs,
253-
input_manifests = tools_manifest,
263+
executable = tools.files_to_run["binary-a"], # Invoke binary-a
254264
...
255265
)
256266
@@ -261,11 +271,9 @@ def _custom_rule_impl(ctx):
261271
binary_b = tools.executables["binary-b"].path, # Path to binary-b
262272
]),
263273
tools = [
264-
tools.executables["binary-a"],
265-
tools.executables["binary-b"],
274+
tools.files_to_run["binary-a"],
275+
tools.files_to_run["binary-b"],
266276
],
267-
inputs = tools_inputs,
268-
input_manifests = tools_manifest,
269277
...
270278
)
271279
@@ -275,11 +283,9 @@ def _custom_rule_impl(ctx):
275283
path = ":".join(tools.paths.to_list()),
276284
),
277285
tools = [
278-
tools.executables["binary-a"],
279-
tools.executables["binary-b"],
286+
tools.files_to_run["binary-a"],
287+
tools.files_to_run["binary-b"],
280288
],
281-
inputs = tools_inputs,
282-
input_manifests = tools_manifest,
283289
...
284290
)
285291
```
@@ -318,7 +324,6 @@ And in a custom rule as follows:
318324
```bzl
319325
def _custom_rule_impl(ctx):
320326
tools = ctx.attr.tools[ShBinariesInfo]
321-
(tools_inputs, tools_manifest) = ctx.resolve_tools(tools = [ctx.attr.tools])
322327
# The explicit RUNFILES_DIR/RUNFILES_MANIFEST_FILE is a workaround for
323328
# https://github.com/bazelbuild/bazel/issues/15486
324329
tools_env = {
@@ -327,10 +332,8 @@ def _custom_rule_impl(ctx):
327332
}
328333
329334
ctx.actions.run(
330-
executable = tools.executables["binary-a"],
335+
executable = tools.files_to_run["binary-a"],
331336
env = tools_env, # Pass the environment into the action.
332-
inputs = tools_inputs,
333-
input_manifests = tools_manifest,
334337
...
335338
)
336339
```

tests/.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
try-import %workspace%/../.bazelrc
1+
import %workspace%/../.bazelrc
22
try-import %workspace%/../.bazelrc.local

tests/posix_hermetic/posix_hermetic_test.bzl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ def _test_runfiles_toolchain():
608608
def _runfiles_custom_rule_impl(ctx):
609609
toolchain = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
610610

611-
(tools_inputs, tools_manifest) = ctx.resolve_tools(tools = [toolchain.tool])
612-
613611
# Override the argv[0] relative runfiles tree or manifest by the bundle's.
614612
# This is a workaround for https://github.com/bazelbuild/bazel/issues/15486
615613
tools_env = {
@@ -620,11 +618,9 @@ def _runfiles_custom_rule_impl(ctx):
620618
output = ctx.actions.declare_file("{}.txt".format(ctx.label.name))
621619
ctx.actions.run_shell(
622620
outputs = [output],
623-
inputs = tools_inputs,
624-
input_manifests = tools_manifest,
625621
env = tools_env,
626622
tools = [
627-
toolchain.sh_binaries_info.executables["echo"],
623+
toolchain.sh_binaries_info.files_to_run["echo"],
628624
],
629625
arguments = [
630626
toolchain.sh_binaries_info.executables["echo"].path,

tests/sh_binaries/sh_binaries_test.bzl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def _bundle_two_binaries_test_impl(ctx):
256256
bundle_binaries_info.executables["hello_world"],
257257
)
258258

259+
asserts.equals(
260+
env,
261+
bundle_binaries_info.executables["hello_world"],
262+
bundle_binaries_info.files_to_run["hello_world"].executable,
263+
)
264+
259265
asserts.true(
260266
env,
261267
"hello_data" in bundle_binaries_info.executables,
@@ -268,6 +274,12 @@ def _bundle_two_binaries_test_impl(ctx):
268274
bundle_binaries_info.executables["hello_data"],
269275
)
270276

277+
asserts.equals(
278+
env,
279+
bundle_binaries_info.executables["hello_data"],
280+
bundle_binaries_info.files_to_run["hello_data"].executable,
281+
)
282+
271283
asserts.equals(
272284
env,
273285
1,
@@ -380,6 +392,12 @@ def _merge_bundles_test_impl(ctx):
380392
bundle_binaries_info.executables["hello_world"],
381393
)
382394

395+
asserts.equals(
396+
env,
397+
bundle_binaries_info.executables["hello_world"],
398+
bundle_binaries_info.files_to_run["hello_world"].executable,
399+
)
400+
383401
asserts.true(
384402
env,
385403
"hello_data" in bundle_binaries_info.executables,
@@ -392,6 +410,12 @@ def _merge_bundles_test_impl(ctx):
392410
bundle_binaries_info.executables["hello_data"],
393411
)
394412

413+
asserts.equals(
414+
env,
415+
bundle_binaries_info.executables["hello_data"],
416+
bundle_binaries_info.files_to_run["hello_data"].executable,
417+
)
418+
395419
asserts.equals(
396420
env,
397421
1,
@@ -472,7 +496,6 @@ def _test_merge_bundles():
472496

473497
def _custom_rule_impl(ctx):
474498
tools = ctx.attr.tools[ShBinariesInfo]
475-
(tools_inputs, tools_manifest) = ctx.resolve_tools(tools = [ctx.attr.tools])
476499

477500
# Override the argv[0] relative runfiles tree or manifest by the bundle's.
478501
# This is a workaround for https://github.com/bazelbuild/bazel/issues/15486
@@ -484,22 +507,19 @@ def _custom_rule_impl(ctx):
484507
output_run = ctx.actions.declare_file("custom_rule_run_output")
485508
ctx.actions.run(
486509
outputs = [output_run],
487-
inputs = tools_inputs,
488-
executable = tools.executables["hello_data"],
510+
executable = tools.files_to_run["hello_data"],
489511
arguments = [output_run.path],
490512
mnemonic = "RunExecutableWithBundle",
491513
progress_message = "Running hello_data",
492514
env = tools_env,
493-
input_manifests = tools_manifest,
494515
)
495516

496517
output_run_shell = ctx.actions.declare_file("custom_rule_run_shell_output")
497518
ctx.actions.run_shell(
498519
outputs = [output_run_shell],
499-
inputs = tools_inputs,
500520
tools = [
501-
tools.executables["hello_world"],
502-
tools.executables["hello_data"],
521+
tools.files_to_run["hello_world"],
522+
tools.files_to_run["hello_data"],
503523
],
504524
arguments = [
505525
tools.executables["hello_world"].path,
@@ -510,7 +530,6 @@ def _custom_rule_impl(ctx):
510530
command = "$1 > $3 && $2 >> $3",
511531
progress_message = "Running hello_world and hello_data",
512532
env = tools_env,
513-
input_manifests = tools_manifest,
514533
)
515534

516535
default_info = DefaultInfo(

0 commit comments

Comments
 (0)