Skip to content

Commit 07e93d1

Browse files
fix: Use target tar toolchain for cross-platform execution (#844)
Hi @thesayyn, @alexeagle. I'd like to help solve the cross-platform remote execution issue described in [#769](#769), which significantly affects us. I see this is connected to the fundamental Bazel limitation described in [bazelbuild/bazel#19645](bazelbuild/bazel#19645). I've noticed that a similar issue was addressed for crane and yq toolchains in [#590](#590), but the same transition-based solution for tar toolchain ([#762](#762)) got stuck because it doesn't work well in other cases. ## Proposal I'm suggesting to use target_toolchain which was [recently implemented](bazel-contrib/tar.bzl#65) instead of toolchain to determine it correctly. As a prerequisite we need to migrate to tar.bzl. ## Changes summary 1. tar.bzl was used instead of `aspect_bazel_lib/tar.bzl` 2. target toolchain was used instead of toolchainl.
1 parent 95d7802 commit 07e93d1

File tree

19 files changed

+43
-27
lines changed

19 files changed

+43
-27
lines changed

MODULE.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bazel_dep(name = "aspect_bazel_lib", version = "2.7.2")
99
bazel_dep(name = "bazel_features", version = "1.10.0")
1010
bazel_dep(name = "bazel_skylib", version = "1.8.2")
1111
bazel_dep(name = "platforms", version = "1.0.0")
12+
bazel_dep(name = "tar.bzl", version = "0.7.0")
1213

1314
oci = use_extension("//oci:extensions.bzl", "oci")
1415
oci.toolchains()
@@ -25,8 +26,12 @@ register_toolchains("@zstd_toolchains//:all")
2526

2627
bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
2728
bazel_lib.jq()
28-
bazel_lib.tar()
29-
use_repo(bazel_lib, "bsd_tar_toolchains", "jq_toolchains")
29+
use_repo(bazel_lib, "jq_toolchains")
30+
31+
tar = use_extension("@tar.bzl//tar:extensions.bzl", "toolchains")
32+
use_repo(tar, "bsd_tar_toolchains")
33+
34+
register_toolchains("@bsd_tar_toolchains//:all")
3035

3136
# Dev dependencies
3237

docs/compare_dockerfile.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ oci_pull(
6565
2. Replace `COPY` with `tar`.
6666

6767
```starlark
68-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
68+
load("@tar.bzl", "tar")
6969

7070
tar(
7171
name = "web_assets",
@@ -77,7 +77,7 @@ tar(
7777
3. The resulting `BUILD` file would look like:
7878

7979
```starlark
80-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
80+
load("@tar.bzl", "tar")
8181

8282
tar(
8383
name = "web_assets",

docs/cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use_repo(oci, "docker_lib_ubuntu")
7676
```
7777

7878
```python
79-
bazel_dep(name = "tar.bzl", version = "0.3.0")
79+
bazel_dep(name = "tar.bzl", version = "0.7.0")
8080
```
8181

8282
To load the image, execute:

docs/scala.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ scala_binary(
133133
After that, we can package that binary into a layer using `tar`
134134

135135
```python
136-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
136+
load("@tar.bzl", "tar")
137137

138138
tar(
139139
name = "layer",
@@ -181,7 +181,7 @@ Complete `BUILD.bazel` file
181181

182182
```python
183183
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary")
184-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
184+
load("@tar.bzl", "tar")
185185
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
186186

187187
scala_binary(

e2e/wasm/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
21
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
32
load("@bazel_skylib//rules:build_test.bzl", "build_test")
43
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
54
load("@rules_rust//rust:defs.bzl", "rust_binary")
5+
load("@tar.bzl", "tar")
66

77
package(default_visibility = ["//visibility:public"])
88

e2e/wasm/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ bazel_dep(name = "rules_oci", version = "0.0.0")
22
bazel_dep(name = "aspect_bazel_lib", version = "2.7.2")
33
bazel_dep(name = "bazel_skylib", version = "1.8.2")
44
bazel_dep(name = "platforms", version = "1.0.0")
5+
bazel_dep(name = "tar.bzl", version = "0.7.0")
56
bazel_dep(name = "rules_rust", version = "0.45.1")
67
bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.0")
78

examples/assertion/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
21
load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")
32
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
43
load("@bazel_skylib//rules:build_test.bzl", "build_test")
54
load("@bazel_skylib//rules:write_file.bzl", "write_file")
65
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
6+
load("@tar.bzl", "tar")
77
load("//examples:assert.bzl", "assert_oci_config")
88

99
# Case 1: image name containing a capital case.

examples/assertion/big_image/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
1+
load("@tar.bzl", "tar")
22
load("//oci:defs.bzl", "oci_image", "oci_load")
33

44
# These numbers were gathered on a `Apple M2 Pro`

examples/cmd_location_expansion/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
21
load("@rules_oci//oci:defs.bzl", "oci_image")
2+
load("@tar.bzl", "tar")
33
load("//examples:assert.bzl", "assert_oci_config", "assert_oci_image_command")
44

55
tar(
@@ -40,8 +40,8 @@ assert_oci_image_command(
4040
"y",
4141
"l1\nl2",
4242
],
43-
image = ":image",
4443
exit_code_eq = 0,
44+
image = ":image",
4545
output_eq = """\
4646
hello world!
4747
arg 0:x

examples/env/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
2-
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
32
load("@rules_oci//oci:defs.bzl", "oci_image")
3+
load("@tar.bzl", "tar")
44
load("//examples:assert.bzl", "assert_oci_image_command")
55

66
tar(
@@ -27,7 +27,7 @@ oci_image(
2727

2828
assert_oci_image_command(
2929
name = "assert_version_is_correct",
30+
exit_code_eq = 0,
3031
image = ":image",
3132
output_eq = "version: 1.2.3",
32-
exit_code_eq = 0
3333
)

0 commit comments

Comments
 (0)