Skip to content

Commit 25aebcc

Browse files
committed
builder: key library caches by inputs
Compute target library cache directories from a content-derived description of each build. Use that same description to drive compilation. The key covers selected sources, every regular file in library input trees, generated headers, external include and resource directories, per-file flags, compiler arguments and identity, target options, and the archive format. This avoids stale libraries without per-library version bumps.
1 parent 206d9ae commit 25aebcc

6 files changed

Lines changed: 627 additions & 150 deletions

File tree

builder/build.go

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -146,53 +146,33 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
146146
// As a side effect, this also creates the headers for the given libc, if
147147
// the libc needs them.
148148
root := goenv.Get("TINYGOROOT")
149+
libraries, err := configuredLibraries(config)
150+
if err != nil {
151+
return BuildResult{}, err
152+
}
153+
libraryInputs, libraryKeys, err := makeLibraryCacheInputs(config, libraries)
154+
if err != nil {
155+
return BuildResult{}, err
156+
}
157+
config.LibraryKeys = libraryKeys
149158
var libcDependencies []*compileJob
150-
switch config.Target.Libc {
151-
case "darwin-libSystem":
159+
if config.Target.Libc == "darwin-libSystem" {
152160
libcJob := makeDarwinLibSystemJob(config, tmpdir)
153161
libcDependencies = append(libcDependencies, libcJob)
154-
case "musl":
155-
var unlock func()
156-
libcJob, unlock, err := libMusl.load(config, tmpdir)
157-
if err != nil {
158-
return BuildResult{}, err
159-
}
160-
defer unlock()
161-
libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(libcJob.result), "crt1.o")))
162-
libcDependencies = append(libcDependencies, libcJob)
163-
case "picolibc":
164-
libcJob, unlock, err := libPicolibc.load(config, tmpdir)
165-
if err != nil {
166-
return BuildResult{}, err
167-
}
168-
defer unlock()
169-
libcDependencies = append(libcDependencies, libcJob)
170-
case "wasi-libc":
171-
libcJob, unlock, err := libWasiLibc.load(config, tmpdir)
172-
if err != nil {
173-
return BuildResult{}, err
174-
}
175-
defer unlock()
176-
libcDependencies = append(libcDependencies, libcJob)
177-
case "wasmbuiltins":
178-
libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir)
162+
}
163+
if libraries.libc != nil {
164+
libcJob, unlock, err := libraries.libc.load(config, tmpdir, libraryInputs[libraries.libc.name])
179165
if err != nil {
180166
return BuildResult{}, err
181167
}
182168
defer unlock()
183-
libcDependencies = append(libcDependencies, libcJob)
184-
case "mingw-w64":
185-
libcJob, unlock, err := libMinGW.load(config, tmpdir)
186-
if err != nil {
187-
return BuildResult{}, err
169+
if libraries.libc.crt1Source != "" {
170+
libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(libcJob.result), "crt1.o")))
188171
}
189-
defer unlock()
190172
libcDependencies = append(libcDependencies, libcJob)
173+
}
174+
if config.Target.Libc == "mingw-w64" {
191175
libcDependencies = append(libcDependencies, makeMinGWExtraLibs(tmpdir, config.GOARCH())...)
192-
case "":
193-
// no library specified, so nothing to do
194-
default:
195-
return BuildResult{}, fmt.Errorf("unknown libc: %s", config.Target.Libc)
196176
}
197177

198178
optLevel, speedLevel, sizeLevel := config.OptLevel()
@@ -739,27 +719,16 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
739719
}
740720
}
741721

742-
// Add compiler-rt dependency if needed. Usually this is a simple load from
743-
// a cache.
744-
if config.Target.RTLib == "compiler-rt" {
745-
job, unlock, err := libCompilerRT.load(config, tmpdir)
722+
// Add library dependencies needed by the linker, usually from the cache.
723+
for _, library := range libraries.linker {
724+
job, unlock, err := library.load(config, tmpdir, libraryInputs[library.name])
746725
if err != nil {
747726
return result, err
748727
}
749728
defer unlock()
750729
linkerDependencies = append(linkerDependencies, job)
751730
}
752731

753-
// The Boehm collector is stored in a separate C library.
754-
if config.GC() == "boehm" {
755-
job, unlock, err := BoehmGC.load(config, tmpdir)
756-
if err != nil {
757-
return BuildResult{}, err
758-
}
759-
defer unlock()
760-
linkerDependencies = append(linkerDependencies, job)
761-
}
762-
763732
// Add jobs to compile extra files. These files are in C or assembly and
764733
// contain things like the interrupt vector table and low level operations
765734
// such as stack switching.

0 commit comments

Comments
 (0)