Description
Over in rules_python, declare_symlink() is used to create symlinks for efficiency and correctness reasons. Such artifacts are "raw" symlinks, that is, Bazel will keep them exactly as-is and not try to transform them, as happens when using declare_file().
Unfortunately, pkg_tar gives an error when it sees these artifacts. What happens is it thinks the file is a regular file, so tries to read it. Since its a relative symlink, it either is dangling (in the context of pkg_tar), or will read the actual file (instead of creating a symlink), neither of which is desirable behavior.
Thankfully, starting in Bazel 8, File.is_symlink can be used to detect these artifacts. This allows the manifest that pkg_tar generates, and the build_tar program that uses it, to handle them correctly.
The two basic changes are:
- When File.is_symlink is true, write a manifest entry with entry_type=raw_symlink (pkg_files.bzl)
- Modify build_tar.py to handle entry_type=raw_symlink: read os.readlink() from the src file. Then store it as a symlink. This preserves the original symlink.
I prototyped this a bit and it seems to work. I'd reference my branch, but its in a very hacky and broken state right now. The above gets the gist though