Documentation for pkg_tar ?

1,183 views
Skip to first unread message

Jan Pfeifer

unread,
Apr 1, 2023, 4:50:57 AM4/1/23
to bazel-discuss
Apologies for the noob question but I'm not finding the information.

I'm trying to upgrade an external dependency and I was forced to upgrade from Bazel 5 to Bazel 6.1.1

Now a `pkg_tar` rule that usually worked, Bazel is complaining:

```
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
...
pkg_tar(
name = "gomlx_xla",
srcs = [
":gomlx_headers_include",
":gomlx_xla_lib",
],
extension = "tar.gz",
mode = "0644",
package_dir = "",
)
```

When I do a `blaze ... build ... (many flags and options)`, I get:

```
ERROR: /mnt/BUILD:37:8: //:gomlx_xla: no such attribute 'extension' in '_real_pkg_tar' rule
ERROR: /mnt/BUILD:37:8: //:gomlx_xla: no such attribute 'mode' in '_real_pkg_tar' rule
```

So I'm assuming the syntax (or source) of the rule changed. But I wonder if it's something else.

Any pointers ?

thanks in advance for any help! 

Jan Pfeifer

unread,
Apr 1, 2023, 6:31:13 AM4/1/23
to bazel-discuss
Apparently it is deprectated, and the new version is:


But this new version doesn't seem to work directories. I have a rule like:

```
genrule(
name = "my_headers_include",
srcs = ["//foo:bar"],
out = "include",
cmd = """
set -x
mkdir -p "$@"
mkdir -p "$@/foo"
echo "out=$@"
for f in $(locations //foo:bar); do
echo "$${f}"
cp "$${f}" "$@/$${f}"
done
""",
)

...
pkg_tar(
name = "my_pkg",
srcs = [
":my_headers_include",
# ... more stuff commented out ...
],
extension = "tar.gz",
mode = "0644",
package_dir = "",
)
```

But when I `blaze build :my_pkg`, I get:

```
IsADirectoryError: [Errno 21] Is a directory: 'bazel-out/k8-opt/bin/include'
```

Searching a bit,  I found that someone had the same issue with `pkg_zip` in https://github.com/bazelbuild/rules_pkg/issues/517.

Any suggestions on work arounds ?

thx

Jan Pfeifer

unread,
Apr 1, 2023, 6:55:39 AM4/1/23
to bazel-discuss
A quick fix, after giving up on `pkg_tar`, for others searching:

genrule(
name = "my_pkg",
outs = ["my_pkg.tar.gz"],

srcs = [
":my_headers_include",
# ...
],
cmd_bash = """
tar czf "$@" $(SRCS)
"""
)

Xudong Yang

unread,
Apr 3, 2023, 7:57:17 AM4/3/23
to Jan Pfeifer, ai...@google.com, bazel-discuss

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/ed39d6c8-bd5b-4160-9813-c59240a2100cn%40googlegroups.com.

James Sharpe

unread,
Apr 3, 2023, 8:01:34 AM4/3/23
to Xudong Yang, Jan Pfeifer, ai...@google.com, bazel-discuss
Jan,

Be aware that your 'quick' fix won't be reproducible as tar will embed timestamps and file order and usernames into it. See https://reproducible-builds.org/docs/archives/ for information on how to make your tar command more reproducible.

James Sharpe | Software Architecture & Security | Zenotech
Papercut
Email:
james....@zenotech.com
Zenotech LTD - Simulation Unlimited
Web:
www.zenotech.com


Papercut
linkedin:Twitter:Location:

Company Registration No : 07926926 | VAT No : 128198591

Registered Office : 1 Larkfield Grove, Chepstow, Monmouthshire, NP16 5UF, UK

Address : Bristol & Bath Science Park, Dirac Cres, Emersons Green, Bristol BS16 7FR



Reply all
Reply to author
Forward
0 new messages