Skip to content

Add source files in name order (reproducible builds) - #21

Closed
eseiker wants to merge 1 commit into
mlua-rs:mainfrom
eseiker:sort-sources
Closed

eseiker wants to merge 1 commit into
mlua-rs:mainfrom
eseiker:sort-sources

Conversation

@eseiker

@eseiker eseiker commented Nov 19, 2026

Copy link
Copy Markdown

add_files_by_ext passes Lua's .c files to cc in fs::read_dir order. That order depends on the file system: on ext4 with dir_index it follows a per-volume filename hash, so two machines (or two CI runners) build the same objects in a different order. The archive's member order changes, and so does the layout of any binary that links it (section offsets, jump tables, the order of dynamic imports). Byte-for-byte reproducible builds of crates using lua-src then fail.

This sorts the files by path before adding them. Flags and defines are unchanged, so the compiled code is the same, only in a fixed order.

Found while making a downstream project's Linux release builds reproducible: two rebuilds of the same commit differed only in where Lua's objects landed. With the files sorted, ar t liblua5.4.a lists lapi.o … lzio.o on every machine.

Tested: testcrate with each of lua51, lua52, lua53, lua54, lua55.

fs::read_dir returns entries in an order that depends on the file
system (on ext4 with dir_index, a per-volume filename hash), so the
objects in the built archive, and the layout of binaries linking it,
differ from one machine to another. Sorting the files makes the build
reproducible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GkmLQ5nvNrfRpnUjryR3hR
@khvzak

khvzak commented Nov 22, 2026

Copy link
Copy Markdown
Member

Thanks for the PR, but I don't accept commits authored by LLM.

@khvzak khvzak closed this Nov 22, 2026
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