builder: add -trimpath support - #5711
Draft
jakebailey wants to merge 1 commit into
Draft
jakebailey wants to merge 1 commit into
jakebailey wants to merge 1 commit into
Conversation
Rewrite Go, CGo, embedded file, and runtime library source paths to stable package paths. Normalize cache inputs so identical source trees produce identical binaries. Fixes 5275
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
CGo headers outside the package directory can still expose local paths and prevent reproducible cache keys.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds -trimpath support to remove local paths and improve binary reproducibility.
Changes:
- Adds and propagates the
-trimpathoption. - Rewrites Go, CGo, library, and embedded-file paths.
- Adds path-removal and reproducibility tests.
| File | Description |
|---|---|
main.go |
Adds the CLI flag. |
main_test.go |
Tests the flag and output reproducibility. |
compileopts/options.go |
Stores the option. |
compileopts/config.go |
Configures path mapping and cache isolation. |
compiler/compiler.go |
Records mapped debug paths. |
loader/loader.go |
Maps package paths and flags. |
loader/loader_test.go |
Tests module path mapping. |
cgo/cgo.go |
Maps CGo source locations. |
cgo/cgo_test.go |
Updates the CGo call signature. |
builder/build.go |
Applies mapping during builds. |
builder/library.go |
Applies mapping to C libraries. |
testdata/trimpath/main.go |
Adds the integration test program. |
testdata/trimpath/main.c |
Adds test C code. |
testdata/trimpath/go.mod |
Defines the test module. |
testdata/trimpath/dependency/go.mod |
Defines the test dependency. |
testdata/trimpath/dependency/dependency.go |
Adds dependency code. |
testdata/trimpath/data.txt |
Adds embedded test data. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // DebugPrefixMap returns the Clang flag that maps this package to its recorded | ||
| // source directory. | ||
| func (p *Package) DebugPrefixMap() string { | ||
| return "-ffile-prefix-map=" + p.OriginalDir() + "=" + p.RecordedDir() |
jakebailey
marked this pull request as draft
September 19, 2026 17:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #5275
With
-no-debug, this doesn't really matter, but otherwise it does make binaries smaller and more reproducible.