Skip to content

fix(elixir_bytecode): store relative source paths in beam files - #6

Open
TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:fix/relative-beam-paths
Open

TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:fix/relative-beam-paths

Conversation

@TrapsterDK

Copy link
Copy Markdown

Problem
elixirc expands every source to an absolute path, and that path is stored in the debug info (Dbgi) and docs (Docs) chunks of each .beam. The path contains the sandbox directory, so the same sources give different beam files in different sandboxes or checkouts. Builds are not reproducible and remote cache entries are not shared across machines. The compile info (CInf) chunk also records the source path and compile options.

Repro: build any elixir_app, then read the Dbgi chunk of a beam (:beam_lib.chunks(beam, [:debug_info])). file is an absolute path inside the sandbox.

Change

  • Compile with ERL_COMPILER_OPTIONS=deterministic, which keeps the source path and options out of CInf. It is exported before env, so a target can still override it.
  • After elixirc finishes, rewrite Dbgi file and Docs source_path of every beam in the output directory to be relative to the execroot.
  • Add a Fixed entry to CHANGELOG.md.

Issues are disabled on this repository, so there is no linked issue.

Test
test/beam_paths_test.sh (//:beam_paths_test) reads the chunks of the compiled Basic module and fails if Dbgi or Docs holds an absolute path or CInf has a source entry. It runs with bazel test //... in test/, like escript_test.

I could not run Bazel or Elixir on the machine used to prepare this, so the change and test are not run locally. CI is the first run.

Assisted by Claude.

elixirc expands every source to an absolute path, and the path lands in the
Dbgi and Docs chunks of each module. The path holds the sandbox directory, so
the same sources produce different beam files in different sandboxes or
checkouts, which breaks reproducible builds and remote cache sharing.

Rewrite both paths relative to the execroot after elixirc runs, and compile
with ERL_COMPILER_OPTIONS=deterministic to keep the source path and compile
options out of the CInf chunk. Add beam_paths_test, which reads the chunks of a
compiled module.

Signed-off-by: Martin Kuntz Jacobsen <martin.kuntz.jacobsen@gmail.com>
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.

1 participant