Skip to content

builder: add -trimpath support - #5711

Draft
jakebailey wants to merge 1 commit into
tinygo-org:devfrom
jakebailey:trimpath
Draft

jakebailey wants to merge 1 commit into
tinygo-org:devfrom
jakebailey:trimpath

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Fixes #5275

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

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 Medium severity

Open (1)
What changed in this PR

Adds -trimpath support to remove local paths and improve binary reproducibility.

Changes:

  • Adds and propagates the -trimpath option.
  • 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.

Comment thread loader/loader.go
// 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
jakebailey marked this pull request as draft September 19, 2026 17:52
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.

-trimpath build flag not working

2 participants