bazel-contrib/bazel-lib

[Bug]: bsdtar toolchain fails on macOS if host tar is gnutar

Strum355 opened this issue · 2 comments

What happened?

bazel-lib doesnt provide any non-host bsdtar toolchains on macOS. This causes a hard-fail when the host tar binary is a gnutar implementation instead of bsdtar, as is the case when e.g. running inside a Nix shell.
It may be expected that in this case, one should provide their own bsdtar toolchain, in which case this is working-as-intended. It would definitely be more convenient though for bazel-lib to also provide that : )

Version

Development (host) and target OS/architectures: macOS arm64

Output of bazel --version: aspect 5.8.19

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 2.5.3

Language(s) and/or frameworks involved: Nix

How to reproduce

No response

Any other information?

No response

pcj commented

Also hit this (in nix):

$ which tar
/nix/store/j02fnkid82a80vr8hgh9mq169gcvcb87-gnutar-1.34/bin/tar
INFO: Repository bsd_tar_host instantiated at:
  /Users/pcj/go/src/github.com/Omnistac/unity/WORKSPACE:161:37: in <toplevel>
  /private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/repositories.bzl:326:28: in aspect_bazel_lib_register_toolchains
  /private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/repositories.bzl:95:27: in register_tar_toolchains
Repository rule bsdtar_binary_repo defined at:
  /private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/private/tar_toolchain.bzl:165:37: in <toplevel>
ERROR: An error occurred during the fetch of repository 'bsd_tar_host':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/private/tar_toolchain.bzl", line 125, column 38, in _bsdtar_binary_repo
		tar = _find_usable_system_tar(rctx, tar_name)
	File "/private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/private/tar_toolchain.bzl", line 110, column 9, in _find_usable_system_tar
		fail("tar isn't a BSD tar")
Error in fail: tar isn't a BSD tar
ERROR: /Users/pcj/go/src/github.com/Omnistac/unity/WORKSPACE:161:37: fetching bsdtar_binary_repo rule //external:bsd_tar_host: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/private/tar_toolchain.bzl", line 125, column 38, in _bsdtar_binary_repo
		tar = _find_usable_system_tar(rctx, tar_name)
	File "/private/var/tmp/_bazel_pcj/d7e82b68b84ece06dc82c3639a1eabcf/external/aspect_bazel_lib/lib/private/tar_toolchain.bzl", line 110, column 9, in _find_usable_system_tar
		fail("tar isn't a BSD tar")
Error in fail: tar isn't a BSD tar

We'll use https://github.com/dzbarsky/bsdtar/releases/tag/v3.7.2 which includes darwin binaries to fix this.