Skip to content

Commit 4c54aa2

Browse files
aykevldeadprogram
authored andcommitted
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 8486e07 commit 4c54aa2

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

builder/bdwgc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var BoehmGC = Library{
4949
"-I" + libdir + "/include",
5050
}
5151
},
52+
needsLibc: true,
5253
sourceDir: func() string {
5354
return filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc")
5455
},

builder/build.go

Lines changed: 7 additions & 12 deletions
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":
153-
libcJob = makeDarwinLibSystemJob(config, tmpdir)
152+
libcJob := makeDarwinLibSystemJob(config, tmpdir)
154153
libcDependencies = append(libcDependencies, libcJob)
155154
case "musl":
156155
var unlock func()
157-
libcJob, unlock, err = libMusl.load(config, tmpdir, nil)
156+
libcJob, unlock, err := libMusl.load(config, tmpdir)
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)
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)
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)
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)
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)
721716
if err != nil {
722717
return BuildResult{}, err
723718
}

builder/library.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type Library struct {
2525
// cflags returns the C flags specific to this library
2626
cflags func(target, headerPath string) []string
2727

28+
// needsLibc is set to true if this library needs libc headers.
29+
needsLibc bool
30+
2831
// The source directory.
2932
sourceDir func() string
3033

@@ -43,11 +46,7 @@ type Library struct {
4346
// output archive file, it is expected to be removed after use.
4447
// As a side effect, this call creates the library header files if they didn't
4548
// exist yet.
46-
// The provided libc job (if not null) will cause this libc to be added as a
47-
// dependency for all C compiler jobs, and adds libc headers for the given
48-
// target config. In other words, pass this libc if the library needs a libc to
49-
// compile.
50-
func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJob) (job *compileJob, abortLock func(), err error) {
49+
func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJob, abortLock func(), err error) {
5150
outdir := config.LibcPath(l.name)
5251
archiveFilePath := filepath.Join(outdir, "lib.a")
5352

@@ -180,7 +179,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
180179
args = append(args, "-mfpu=vfpv2")
181180
}
182181
}
183-
if libc != nil {
182+
if l.needsLibc {
184183
args = append(args, config.LibcCFlags()...)
185184
}
186185

@@ -251,9 +250,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
251250
return nil
252251
},
253252
}
254-
if libc != nil {
255-
objfile.dependencies = append(objfile.dependencies, libc)
256-
}
257253
job.dependencies = append(job.dependencies, objfile)
258254
}
259255

@@ -284,9 +280,6 @@ func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJ
284280
return os.Rename(tmpfile.Name(), filepath.Join(outdir, "crt1.o"))
285281
},
286282
}
287-
if libc != nil {
288-
crt1Job.dependencies = append(crt1Job.dependencies, libc)
289-
}
290283
job.dependencies = append(job.dependencies, crt1Job)
291284
}
292285

0 commit comments

Comments
 (0)