Skip to content

Commit dc24f0a

Browse files
committed
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.
1 parent 263ffe4 commit dc24f0a

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

builder/build.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,21 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
147147
// the libc needs them.
148148
root := goenv.Get("TINYGOROOT")
149149
var libcDependencies []*compileJob
150-
var libcJob *compileJob
151150
switch config.Target.Libc {
152151
case "darwin-libSystem":
153152
job := makeDarwinLibSystemJob(config, tmpdir)
154153
libcDependencies = append(libcDependencies, job)
155154
case "musl":
156155
var unlock func()
157-
libcJob, unlock, err = libMusl.load(config, tmpdir, nil)
156+
libcJob, unlock, err := libMusl.load(config, tmpdir, false)
158157
if err != nil {
159158
return BuildResult{}, err
160159
}
161160
defer unlock()
162161
libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(libcJob.result), "crt1.o")))
163162
libcDependencies = append(libcDependencies, libcJob)
164163
case "picolibc":
165-
libcJob, unlock, err := libPicolibc.load(config, tmpdir, nil)
164+
libcJob, unlock, err := libPicolibc.load(config, tmpdir, false)
166165
if err != nil {
167166
return BuildResult{}, err
168167
}
@@ -175,15 +174,14 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
175174
}
176175
libcDependencies = append(libcDependencies, dummyCompileJob(path))
177176
case "wasmbuiltins":
178-
libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir, nil)
177+
libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir, false)
179178
if err != nil {
180179
return BuildResult{}, err
181180
}
182181
defer unlock()
183182
libcDependencies = append(libcDependencies, libcJob)
184183
case "mingw-w64":
185-
var unlock func()
186-
libcJob, unlock, err = libMinGW.load(config, tmpdir, nil)
184+
libcJob, unlock, err := libMinGW.load(config, tmpdir, false)
187185
if err != nil {
188186
return BuildResult{}, err
189187
}
@@ -704,7 +702,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
704702
// Add compiler-rt dependency if needed. Usually this is a simple load from
705703
// a cache.
706704
if config.Target.RTLib == "compiler-rt" {
707-
job, unlock, err := libCompilerRT.load(config, tmpdir, nil)
705+
job, unlock, err := libCompilerRT.load(config, tmpdir, false)
708706
if err != nil {
709707
return result, err
710708
}
@@ -714,10 +712,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
714712

715713
// The Boehm collector is stored in a separate C library.
716714
if config.GC() == "boehm" {
717-
if libcJob == nil {
718-
return BuildResult{}, fmt.Errorf("boehm GC isn't supported with libc %s", config.Target.Libc)
719-
}
720-
job, unlock, err := BoehmGC.load(config, tmpdir, libcJob)
715+
job, unlock, err := BoehmGC.load(config, tmpdir, true)
721716
if err != nil {
722717
return BuildResult{}, err
723718
}

builder/library.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Library struct {
4747
// dependency for all C compiler jobs, and adds libc headers for the given
4848
// target config. In other words, pass this libc if the library needs a libc to
4949
// compile.
50-
func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJob) (job *compileJob, abortLock func(), err error) {
50+
func (l *Library) load(config *compileopts.Config, tmpdir string, needLibc bool) (job *compileJob, abortLock func(), err error) {
5151
outdir := config.LibcPath(l.name)
5252
archiveFilePath := filepath.Join(outdir, "lib.a")
5353

@@ -180,7 +180,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
180180
args = append(args, "-mfpu=vfpv2")
181181
}
182182
}
183-
if libc != nil {
183+
if needLibc {
184184
args = append(args, config.LibcCFlags()...)
185185
}
186186

@@ -251,9 +251,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
251251
return nil
252252
},
253253
}
254-
if libc != nil {
255-
objfile.dependencies = append(objfile.dependencies, libc)
256-
}
257254
job.dependencies = append(job.dependencies, objfile)
258255
}
259256

@@ -284,9 +281,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
284281
return os.Rename(tmpfile.Name(), filepath.Join(outdir, "crt1.o"))
285282
},
286283
}
287-
if libc != nil {
288-
crt1Job.dependencies = append(crt1Job.dependencies, libc)
289-
}
290284
job.dependencies = append(job.dependencies, crt1Job)
291285
}
292286

0 commit comments

Comments
 (0)