Skip to content

Commit

Permalink
feat: add a tar toolchain (#468)
Browse files Browse the repository at this point in the history
* feat: add a BSD tar toolchain

@thesayyn discovered that it has a feature which should make it a drop-in replacement for pkg_tar
including fine-grained file permissions and symlinks:
https://man.freebsd.org/cgi/man.cgi?mtree(8)

* show example of mtree usage

* feat: introduce tar rule

* cleanup and get test passing

* more cleanup

* chore: add support for compress flags

* chore: add docs

* chore: add docs

* feat: implement linux bsdtar toolchain (#566)

* chore: improve target naming

* WIP: args

* feat: generate mtree spec

Also allow arbitrary args

* refactor: mtree is required

* refactor: style nits

* fix: support mix of source and generated artifacts

* feat: demonstrate strip_prefix

* chore: regen docs

* fix: make host toolchain a fallback toolchain

* fix: include libarchive13.so when installing BSD tar

* chore: buildifier

* fix: aarch64 cpu constraint

* fix(ci): include libarchive13.so when running tar

* chore: add libnettle

* refactor: inputs mutated less

* refactor: remove unneeded substitution arg

* refactor: don't advertise unsupported modes

* fix: hack enough to make it run on my machine

* chore: dynamic libraries included in sh_binary under toolchain

* make sh_binary work

* refactor: drop arm64 for now

* fix toolchain

* fix test

* chore: improve test naming scheme

---------

Co-authored-by: Sahin Yort <thesayyn@gmail.com>
  • Loading branch information
2 people authored and gregmagolan committed Mar 23, 2024
1 parent c215c62 commit a393109
Show file tree
Hide file tree
Showing 14 changed files with 859 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ stardoc_with_diff_test(
bzl_library_target = "//lib:lists",
)

stardoc_with_diff_test(
name = "tar",
bzl_library_target = "//lib:tar",
)

stardoc_with_diff_test(
name = "utils",
bzl_library_target = "//lib:utils",
Expand Down
19 changes: 19 additions & 0 deletions docs/repositories.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions docs/tar.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Users should *not* need to install these. If users see a load()
statement from these, that's a bug in our distribution.
"""

load("//lib:repositories.bzl", "register_coreutils_toolchains", "register_jq_toolchains", "register_yq_toolchains")
load("//lib:repositories.bzl", "register_coreutils_toolchains", "register_jq_toolchains", "register_tar_toolchains", "register_yq_toolchains")
load("//lib:utils.bzl", http_archive = "maybe_http_archive")

# buildifier: disable=unnamed-macro
Expand Down Expand Up @@ -73,3 +73,4 @@ def bazel_lib_internal_deps():
register_jq_toolchains()
register_yq_toolchains()
register_coreutils_toolchains()
register_tar_toolchains()
15 changes: 15 additions & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ toolchain_type(
name = "expand_template_toolchain_type",
)

toolchain_type(
name = "tar_toolchain_type",
)

bzl_library(
name = "docs",
srcs = ["docs.bzl"],
Expand Down Expand Up @@ -125,6 +129,16 @@ bzl_library(
deps = ["//lib/private/docs:utils"],
)

bzl_library(
name = "tar",
srcs = ["tar.bzl"],
deps = [
"//lib/private/docs:tar",
"@bazel_skylib//lib:types",
"@bazel_skylib//rules:write_file",
],
)

bzl_library(
name = "jq",
srcs = ["jq.bzl"],
Expand Down Expand Up @@ -260,6 +274,7 @@ bzl_library(
"//lib/private/docs:jq_toolchain",
"//lib/private/docs:local_config_platform",
"//lib/private/docs:source_toolchains_repo",
"//lib/private/docs:tar_toolchain",
"//lib/private/docs:yq_toolchain",
],
)
Expand Down
13 changes: 13 additions & 0 deletions lib/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ load(
"DEFAULT_EXPAND_TEMPLATE_REPOSITORY",
"DEFAULT_JQ_REPOSITORY",
"DEFAULT_JQ_VERSION",
"DEFAULT_TAR_REPOSITORY",
"DEFAULT_YQ_REPOSITORY",
"DEFAULT_YQ_VERSION",
"register_copy_directory_toolchains",
"register_copy_to_directory_toolchains",
"register_coreutils_toolchains",
"register_expand_template_toolchains",
"register_jq_toolchains",
"register_tar_toolchains",
"register_yq_toolchains",
)
load("//lib/private:extension_utils.bzl", "extension_utils")
Expand All @@ -27,6 +29,7 @@ def _toolchain_extension(mctx):
register_jq_toolchains(register = False)
register_yq_toolchains(register = False)
register_coreutils_toolchains(register = False)
register_tar_toolchains(register = False)
register_expand_template_toolchains(register = False)

create_host_repo = False
Expand Down Expand Up @@ -101,6 +104,15 @@ def _toolchains_extension_impl(mctx):
toolchain_repos_fn = lambda name, version: register_coreutils_toolchains(name = name, version = version, register = False),
)

extension_utils.toolchain_repos_bfs(
mctx = mctx,
get_tag_fn = lambda tags: tags.tar,
toolchain_name = "tar",
default_repository = DEFAULT_TAR_REPOSITORY,
toolchain_repos_fn = lambda name, version: register_tar_toolchains(name = name, register = False),
get_version_fn = lambda attr: None,
)

extension_utils.toolchain_repos_bfs(
mctx = mctx,
get_tag_fn = lambda tags: tags.expand_template,
Expand All @@ -117,6 +129,7 @@ toolchains = module_extension(
"jq": tag_class(attrs = {"name": attr.string(default = DEFAULT_JQ_REPOSITORY), "version": attr.string(default = DEFAULT_JQ_VERSION)}),
"yq": tag_class(attrs = {"name": attr.string(default = DEFAULT_YQ_REPOSITORY), "version": attr.string(default = DEFAULT_YQ_VERSION)}),
"coreutils": tag_class(attrs = {"name": attr.string(default = DEFAULT_COREUTILS_REPOSITORY), "version": attr.string(default = DEFAULT_COREUTILS_VERSION)}),
"tar": tag_class(attrs = {"name": attr.string(default = DEFAULT_TAR_REPOSITORY)}),
"expand_template": tag_class(attrs = {"name": attr.string(default = DEFAULT_EXPAND_TEMPLATE_REPOSITORY)}),
},
)
13 changes: 13 additions & 0 deletions lib/private/docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ bzl_library(
],
)

bzl_library(
name = "tar",
srcs = [
"//lib/private:tar.bzl",
],
)

bzl_library(
name = "utils",
srcs = [
Expand Down Expand Up @@ -211,6 +218,12 @@ bzl_library(
deps = [":repo_utils"],
)

bzl_library(
name = "tar_toolchain",
srcs = ["//lib/private:tar_toolchain.bzl"],
deps = [":repo_utils"],
)

bzl_library(
name = "repo_utils",
srcs = ["//lib/private:repo_utils.bzl"],
Expand Down
Loading

0 comments on commit a393109

Please sign in to comment.