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.
This commit is contained in:
Ayke van Laethem
2025-03-19 08:58:10 +01:00
committed by Ron Evans
parent 8486e07377
commit 4c54aa20da
3 changed files with 13 additions and 24 deletions
+1
View File
@@ -49,6 +49,7 @@ var BoehmGC = Library{
"-I" + libdir + "/include",
}
},
needsLibc: true,
sourceDir: func() string {
return filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc")
},
+7 -12
View File
@@ -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
}
+5 -12
View File
@@ -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)
}