1
1
"Provide access to a BSD tar"
2
2
3
- load (":repo_utils.bzl" , "repo_utils" )
4
-
5
3
BSDTAR_PLATFORMS = {
4
+ "darwin_amd64" : struct (
5
+ compatible_with = [
6
+ "@platforms//os:osx" ,
7
+ "@platforms//cpu:x86_64" ,
8
+ ],
9
+ ),
10
+ "darwin_arm64" : struct (
11
+ compatible_with = [
12
+ "@platforms//os:osx" ,
13
+ "@platforms//cpu:aarch64" ,
14
+ ],
15
+ ),
6
16
"linux_amd64" : struct (
7
17
compatible_with = [
8
18
"@platforms//os:linux" ,
@@ -22,145 +32,58 @@ BSDTAR_PLATFORMS = {
22
32
"@platforms//cpu:x86_64" ,
23
33
],
24
34
),
25
- # WARNING: host toolchain should always come last to make it a fallback toolchain.
26
- "host" : struct (
27
- # loaded by the macro
28
- compatible_with = "HOST_CONSTRAINTS" ,
29
- ),
30
35
}
31
36
32
- WINDOWS_DEPS = (
33
- "e06f10043b1b148eb38ad06cff678af05beade0bdd2edd8735a198c521fa3993" ,
34
- "https://github.com/libarchive/libarchive/releases/download/v3.7.2/libarchive-v3.7.2-amd64.zip" ,
35
- )
36
-
37
- # note, using Ubuntu Focal packages as they link with older glibc versions.
38
- # Ubuntu Jammy packages will fail on ubuntu 20.02 with
39
- # bsdtar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found
40
- # bsdtar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
41
- #
42
- # TODO: this is only a partial listing of the transitive deps of libarchive-tools
43
- # so we expect a bunch of compress modes are broken, for example.
44
-
45
- LINUX_LIB_DEPS = {
46
- "linux_arm64" : [
47
- (
48
- "6d18525e248e84b8a4ee39a226fd1195ca9b9d0d5a1c7909ae4f997d46378848" ,
49
- "http://ports.ubuntu.com/pool/main/n/nettle/libnettle7_3.5.1+really3.5.1-2ubuntu0.2_arm64.deb" ,
50
- ),
51
- (
52
- "aa5e31d05a9d6bde8093137bd1c82b5a20a5f470bd5109642014f895c20f323a" ,
53
- "http://ports.ubuntu.com/pool/main/liba/libarchive/libarchive13_3.4.0-2ubuntu1_arm64.deb" ,
54
- ),
55
- (
56
- "6d089f878507b536d8ca51b1ad80a80706a1dd7dbbcce7600800d3f9f98be2ab" ,
57
- "http://ports.ubuntu.com/pool/main/liba/libarchive/libarchive-tools_3.2.1-2~ubuntu16.04.1_arm64.deb" ,
58
- ),
59
- (
60
- "6242892cb032859044ddfcfbe61bac5678a95c585d8fff4525acaf45512e3d39" ,
61
- "http://ports.ubuntu.com/pool/main/libx/libxml2/libxml2_2.9.10+dfsg-5_arm64.deb" ,
62
- ),
63
- (
64
- "6302e309ab002af30ddfa0d68de26c68f7c034ed2f45b1d97a712bff1a03999a" ,
65
- "http://ports.ubuntu.com/pool/main/i/icu/libicu66_66.1-2ubuntu2_arm64.deb" ,
66
- ),
67
- ],
68
- "linux_amd64" : [
69
- # https://packages.ubuntu.com/focal/amd64/libarchive-tools/download
70
- (
71
- "12a19878d34b407e6f4893d3b26b7758a26c5534a066d76184c8b764b2df1652" ,
72
- "http://security.ubuntu.com/ubuntu/pool/universe/liba/libarchive/libarchive-tools_3.4.0-2ubuntu1.2_amd64.deb" ,
73
- ),
74
- # https://packages.ubuntu.com/focal/amd64/libarchive13/download
75
- (
76
- "8ba7507f61bb3ea8da488702ec0badcbfb726d36ea6886e3421ac59082aaf2d1" ,
77
- "http://security.ubuntu.com/ubuntu/pool/main/liba/libarchive/libarchive13_3.4.0-2ubuntu1.2_amd64.deb" ,
78
- ),
79
- # https://packages.ubuntu.com/focal/amd64/libnettle7/download
80
- (
81
- "3496aed83407fde71e0dc5988b28e8fd7f07a2f27fcf3e0f214c7cd86667eecd" ,
82
- "http://security.ubuntu.com/ubuntu/pool/main/n/nettle/libnettle7_3.5.1+really3.5.1-2ubuntu0.2_amd64.deb" ,
83
- ),
84
- # https://packages.ubuntu.com/focal/amd64/libxml2/download
85
- (
86
- "cef3871873e5e7e7f1d01afec4d35f15504a9d8a0afbe56f57037e92f7f8e850" ,
87
- "http://security.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2_2.9.10+dfsg-5ubuntu0.20.04.7_amd64.deb" ,
88
- ),
89
- # https://packages.ubuntu.com/focal/amd64/libicu66/download
90
- (
91
- "00d0de456134668f41bd9ea308a076bc0a6a805180445af8a37209d433f41efe" ,
92
- "http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu66_66.1-2ubuntu2.1_amd64.deb" ,
93
- ),
94
- ],
37
+ BSDTAR_PREBUILT = {
38
+ "darwin_amd64" : (
39
+ "https://github.com/aspect-build/bsdtar-prebuilt/releases/download/v3.7.2/tar_darwin_amd64" ,
40
+ "a3bd0e7be92bcddcb70341f1efc48c29ef99b3ad57349b433e9a3182b68cb0c1" ,
41
+ ),
42
+ "darwin_arm64" : (
43
+ "https://github.com/aspect-build/bsdtar-prebuilt/releases/download/v3.7.2/tar_darwin_arm64" ,
44
+ "63ee769e2d870d1ed3542e292c919dc8a3934544d17b2de34213c18c41c5437f" ,
45
+ ),
46
+ "linux_amd64" : (
47
+ "https://github.com/aspect-build/bsdtar-prebuilt/releases/download/v3.7.2/tar_linux_amd64" ,
48
+ "d40582e64aace892e2f9588045edc5e67023ca3371cd575e7043b0c2a08205b4" ,
49
+ ),
50
+ "linux_arm64" : (
51
+ "https://github.com/aspect-build/bsdtar-prebuilt/releases/download/v3.7.2/tar_linux_arm64" ,
52
+ "e2527be38499e94e021c7c02476b4cff8083313d38c85bdf46fc5751d31d32aa" ,
53
+ ),
54
+ "windows_amd64" : (
55
+ "https://github.com/libarchive/libarchive/releases/download/v3.7.2/libarchive-v3.7.2-amd64.zip" ,
56
+ "e06f10043b1b148eb38ad06cff678af05beade0bdd2edd8735a198c521fa3993" ,
57
+ ),
95
58
}
96
59
97
- def _find_usable_system_tar (rctx , tar_name ):
98
- tar = rctx .which (tar_name )
99
- if not tar :
100
- fail ("tar not found on PATH, and we don't handle this case yet" )
101
-
102
- # Run tar --version and see if we are satisfied to use it
103
- tar_version = rctx .execute ([tar , "--version" ]).stdout .strip ()
104
-
105
- # TODO: also check if it's really ancient or compiled without gzip support or something?
106
- # TODO: document how users could fetch the source and compile it themselves
107
- if tar_version .find ("bsdtar" ) >= 0 :
108
- return tar
109
-
110
- fail ("tar isn't a BSD tar" )
111
-
112
60
def _bsdtar_binary_repo (rctx ):
113
- tar_name = "tar.exe" if repo_utils .is_windows (rctx ) else "tar"
114
- build_header = """\
115
- # @generated by @aspect_bazel_lib//lib/private:tar_toolchain.bzl
116
-
117
- load("@aspect_bazel_lib//lib/private:tar_toolchain.bzl", "tar_toolchain")
118
-
119
- package(default_visibility = ["//visibility:public"])
120
-
121
- """
122
-
123
- # On MacOS, the system `tar` binary on the PATH should already work
124
- if rctx .attr .platform == "host" :
125
- tar = _find_usable_system_tar (rctx , tar_name )
126
- output = rctx .path (tar_name )
127
- rctx .symlink (tar , output )
128
- rctx .file ("BUILD.bazel" , build_header + """tar_toolchain(name = "bsdtar_toolchain", binary = "tar")""" )
129
- return
130
-
131
- if repo_utils .is_windows (rctx ):
61
+ (url , sha256 ) = BSDTAR_PREBUILT [rctx .attr .platform ]
62
+ if rctx .attr .platform .startswith ("windows" ):
132
63
rctx .download_and_extract (
133
- url = WINDOWS_DEPS [ 1 ] ,
64
+ url = url ,
134
65
type = "zip" ,
135
- sha256 = WINDOWS_DEPS [0 ],
66
+ sha256 = sha256 ,
67
+ )
68
+ binary = "libarchive/bin/bsdtar.exe"
69
+ else :
70
+ rctx .download (
71
+ url = url ,
72
+ output = "tar" ,
73
+ executable = True ,
74
+ sha256 = sha256 ,
136
75
)
137
- rctx .file ("BUILD.bazel" , build_header + """tar_toolchain(name = "bsdtar_toolchain", binary = "libarchive/bin/bsdtar.exe")""" )
138
- return
76
+ binary = "tar"
139
77
140
- # Other platforms, we have more work to do.
141
- libs_dir = "usr/lib/x86_64-linux-gnu" if rctx . attr . platform . endswith ( "amd64" ) else "usr/ lib/aarch64-linux-gnu"
78
+ rctx . file ( "BUILD.bazel" , """ \
79
+ # @generated by @aspect_bazel_lib// lib/private:tar_toolchain.bzl
142
80
143
- for lib in LINUX_LIB_DEPS [rctx .attr .platform ]:
144
- rctx .download_and_extract (
145
- url = lib [1 ],
146
- type = "deb" ,
147
- sha256 = lib [0 ],
148
- )
149
- rctx .extract ("data.tar.xz" )
81
+ load("@aspect_bazel_lib//lib/private:tar_toolchain.bzl", "tar_toolchain")
150
82
151
- rctx .file ("bsdtar.sh" , """#!/usr/bin/env bash
152
- readonly wksp="$(dirname "${{BASH_SOURCE[0]}}")"
153
- LD_LIBRARY_PATH=$wksp/{libs_dir} exec $wksp/usr/bin/bsdtar $@
154
- """ .format (name = rctx .name , libs_dir = libs_dir ))
83
+ package(default_visibility = ["//visibility:public"])
155
84
156
- rctx .file ("BUILD.bazel" , build_header + """\
157
- tar_toolchain(
158
- name = "bsdtar_toolchain",
159
- files = glob(["{libs}/*.so.*"]) + ["usr/bin/bsdtar"],
160
- binary = "bsdtar.sh",
161
- visibility = ["//visibility:public"],
162
- )
163
- """ .format (libs = libs_dir , name = rctx .name ))
85
+ tar_toolchain(name = "bsdtar_toolchain", binary = "{}")
86
+ """ .format (binary ))
164
87
165
88
bsdtar_binary_repo = repository_rule (
166
89
implementation = _bsdtar_binary_repo ,
0 commit comments