Skip to content

fix(zipapp): store _solib shared libraries as files, not absolute symlinks - #4211

Merged
rickeylev merged 1 commit into
bazel-contrib:mainfrom
gfrankliu:fix/zipapp-absolute-source-symlink
Oct 5, 2026
Merged

rickeylev merged 1 commit into
bazel-contrib:mainfrom
gfrankliu:fix/zipapp-absolute-source-symlink

Conversation

@gfrankliu

Copy link
Copy Markdown
Contributor

Since #4165, the zipper keeps a symlink for an input whose original source is a
symlink, looking through the absolute symlink the Bazel sandbox exposes the
input as. For the _solib entries Bazel creates for shared libraries, the
original source is itself an absolute symlink into the build machine's output
base, so the zipapp stored entries like

runfiles/_main/_solib_x86_64/libST-..._Slibgrpc.so
  -> /home/<user>/.cache/bazel/<hash>/execroot/_main/bazel-out/.../libgrpc.so

which dangle on any other machine. Any zipapp whose Python code loads a shared
library from _solib (a C extension that links a cc_library dynamically, or
libpython for an extension that links it) fails to load it outside the
machine that built it. Before #4165 these files were copied.

To fix, only keep the looked-through target when it is relative, e.g.
libpython3.10.so -> libpython3.10.so.1.0 inside the runtime, which is what
the size optimization in #4165 is for. Otherwise the file is stored.

  • Adds a zipper test with the _solib shape: a sandbox symlink to an absolute
    symlink to the library. It fails without the fix ("should NOT be a symlink
    but is").

…links

Since bazel-contrib#4165, the zipper keeps a symlink for an input whose original source is a
symlink, looking through the absolute symlink the Bazel sandbox exposes the
input as. For the `_solib` entries Bazel creates for shared libraries, the
original source is itself an absolute symlink into the build machine's output
base, so the zipapp stored entries like

    runfiles/_main/_solib_x86_64/libST-..._Slibgrpc.so
      -> /home/<user>/.cache/bazel/<hash>/execroot/_main/bazel-out/.../libgrpc.so

which dangle on any other machine. Any zipapp whose Python code loads a shared
library from `_solib` (a C extension that links a `cc_library` dynamically, or
`libpython` for an extension that links it) fails to load it outside the
machine that built it. Before bazel-contrib#4165 these files were copied.

To fix, only keep the looked-through target when it is relative, e.g.
`libpython3.10.so -> libpython3.10.so.1.0` inside the runtime, which is what
the size optimization in bazel-contrib#4165 is for. Otherwise the file is stored.

* Adds a zipper test with the `_solib` shape: a sandbox symlink to an absolute
  symlink to the library. It fails without the fix ("should NOT be a symlink
  but is").
Copilot AI balanced review requested due to automatic review settings October 4, 2026 05:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation correctly addresses the portability bug and includes appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes non-portable zipapps by copying absolute _solib symlink targets instead of preserving machine-local links—a decidedly less silly walk.

Changes:

  • Preserves only relative source symlinks.
  • Adds regression coverage for sandboxed _solib links.
  • Documents the user-visible fix.
File Description
tools/​zipapp/​zipper.py Copies targets of absolute source symlinks.
tests/​tools/​zipapp/​zipper_test.py Tests the _solib sandbox shape.
news/​zipapp-absolute-source-symlinks.fixed.md Adds the release note.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@rickeylev
rickeylev added this pull request to the merge queue Oct 5, 2026
Merged via the queue into bazel-contrib:main with commit 381762a Oct 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants