From 4c54aa20da2943d9a2d0bcbb46ecd51f062609a7 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 19 Mar 2025 08:58:10 +0100 Subject: [PATCH] builder: simplify bdwgc libc dependency Header files are built immediately, not in a separate job, so no dependency is needed here. All we need is a flag whether to add flags for that given libc. --- builder/bdwgc.go | 1 + builder/build.go | 19 +++++++------------ builder/library.go | 17 +++++------------ 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/builder/bdwgc.go b/builder/bdwgc.go index 88e7a2673..8341005d2 100644 --- a/builder/bdwgc.go +++ b/builder/bdwgc.go @@ -49,6 +49,7 @@ var BoehmGC = Library{ "-I" + libdir + "/include", } }, + needsLibc: true, sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc") }, diff --git a/builder/build.go b/builder/build.go index 46f4dcbdf..d921f95a0 100644 --- a/builder/build.go +++ b/builder/build.go @@ -147,14 +147,13 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe // the libc needs them. root := goenv.Get("TINYGOROOT") var libcDependencies []*compileJob - var libcJob *compileJob switch config.Target.Libc { case "darwin-libSystem": - libcJob = makeDarwinLibSystemJob(config, tmpdir) + libcJob := makeDarwinLibSystemJob(config, tmpdir) libcDependencies = append(libcDependencies, libcJob) case "musl": var unlock func() - libcJob, unlock, err = libMusl.load(config, tmpdir, nil) + libcJob, unlock, err := libMusl.load(config, tmpdir) if err != nil { return BuildResult{}, err } @@ -162,7 +161,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(libcJob.result), "crt1.o"))) libcDependencies = append(libcDependencies, libcJob) case "picolibc": - libcJob, unlock, err := libPicolibc.load(config, tmpdir, nil) + libcJob, unlock, err := libPicolibc.load(config, tmpdir) if err != nil { return BuildResult{}, err } @@ -175,15 +174,14 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe } libcDependencies = append(libcDependencies, dummyCompileJob(path)) case "wasmbuiltins": - libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir, nil) + libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir) if err != nil { return BuildResult{}, err } defer unlock() libcDependencies = append(libcDependencies, libcJob) case "mingw-w64": - var unlock func() - libcJob, unlock, err = libMinGW.load(config, tmpdir, nil) + libcJob, unlock, err := libMinGW.load(config, tmpdir) if err != nil { return BuildResult{}, err } @@ -704,7 +702,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe // Add compiler-rt dependency if needed. Usually this is a simple load from // a cache. if config.Target.RTLib == "compiler-rt" { - job, unlock, err := libCompilerRT.load(config, tmpdir, nil) + job, unlock, err := libCompilerRT.load(config, tmpdir) if err != nil { return result, err } @@ -714,10 +712,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe // The Boehm collector is stored in a separate C library. if config.GC() == "boehm" { - if libcJob == nil { - return BuildResult{}, fmt.Errorf("boehm GC isn't supported with libc %s", config.Target.Libc) - } - job, unlock, err := BoehmGC.load(config, tmpdir, libcJob) + job, unlock, err := BoehmGC.load(config, tmpdir) if err != nil { return BuildResult{}, err } diff --git a/builder/library.go b/builder/library.go index 09bd53fc8..0c73a515a 100644 --- a/builder/library.go +++ b/builder/library.go @@ -25,6 +25,9 @@ type Library struct { // cflags returns the C flags specific to this library cflags func(target, headerPath string) []string + // needsLibc is set to true if this library needs libc headers. + needsLibc bool + // The source directory. sourceDir func() string @@ -43,11 +46,7 @@ type Library struct { // output archive file, it is expected to be removed after use. // As a side effect, this call creates the library header files if they didn't // exist yet. -// The provided libc job (if not null) will cause this libc to be added as a -// dependency for all C compiler jobs, and adds libc headers for the given -// target config. In other words, pass this libc if the library needs a libc to -// compile. -func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJob) (job *compileJob, abortLock func(), err error) { +func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJob, abortLock func(), err error) { outdir := config.LibcPath(l.name) archiveFilePath := filepath.Join(outdir, "lib.a") @@ -180,7 +179,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ args = append(args, "-mfpu=vfpv2") } } - if libc != nil { + if l.needsLibc { args = append(args, config.LibcCFlags()...) } @@ -251,9 +250,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ return nil }, } - if libc != nil { - objfile.dependencies = append(objfile.dependencies, libc) - } job.dependencies = append(job.dependencies, objfile) } @@ -284,9 +280,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ return os.Rename(tmpfile.Name(), filepath.Join(outdir, "crt1.o")) }, } - if libc != nil { - crt1Job.dependencies = append(crt1Job.dependencies, libc) - } job.dependencies = append(job.dependencies, crt1Job) }