diff --git a/Makefile b/Makefile index 4345290b..7d5fad9e 100644 --- a/Makefile +++ b/Makefile @@ -786,6 +786,7 @@ endif @cp -rp lib/musl/src/exit build/release/tinygo/lib/musl/src @cp -rp lib/musl/src/include build/release/tinygo/lib/musl/src @cp -rp lib/musl/src/internal build/release/tinygo/lib/musl/src + @cp -rp lib/musl/src/legacy build/release/tinygo/lib/musl/src @cp -rp lib/musl/src/malloc build/release/tinygo/lib/musl/src @cp -rp lib/musl/src/mman build/release/tinygo/lib/musl/src @cp -rp lib/musl/src/math build/release/tinygo/lib/musl/src diff --git a/builder/builtins.go b/builder/builtins.go index 121398fa..f3581614 100644 --- a/builder/builtins.go +++ b/builder/builtins.go @@ -181,11 +181,11 @@ var CompilerRT = Library{ // Development build. return filepath.Join(goenv.Get("TINYGOROOT"), "lib/compiler-rt-builtins") }, - librarySources: func(target string) []string { + librarySources: func(target string) ([]string, error) { builtins := append([]string{}, genericBuiltins...) // copy genericBuiltins if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { builtins = append(builtins, aeabiBuiltins...) } - return builtins + return builtins, nil }, } diff --git a/builder/library.go b/builder/library.go index 385f1610..06b57632 100644 --- a/builder/library.go +++ b/builder/library.go @@ -29,7 +29,7 @@ type Library struct { sourceDir func() string // The source files, relative to sourceDir. - librarySources func(target string) []string + librarySources func(target string) ([]string, error) // The source code for the crt1.o file, relative to sourceDir. crt1Source string @@ -219,7 +219,11 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ // Create jobs to compile all sources. These jobs are depended upon by the // archive job above, so must be run first. - for _, path := range l.librarySources(target) { + paths, err := l.librarySources(target) + if err != nil { + return nil, nil, err + } + for _, path := range paths { // Strip leading "../" parts off the path. cleanpath := path for strings.HasPrefix(cleanpath, "../") { diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go index 27fefee0..db8b43c3 100644 --- a/builder/mingw-w64.go +++ b/builder/mingw-w64.go @@ -31,9 +31,9 @@ var MinGW = Library{ // No flags necessary because there are no files to compile. return nil }, - librarySources: func(target string) []string { + librarySources: func(target string) ([]string, error) { // We only use the UCRT DLL file. No source files necessary. - return nil + return nil, nil }, } diff --git a/builder/musl.go b/builder/musl.go index 8d577f66..bdfdc4a8 100644 --- a/builder/musl.go +++ b/builder/musl.go @@ -106,7 +106,7 @@ var Musl = Library{ } }, sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl/src") }, - librarySources: func(target string) []string { + librarySources: func(target string) ([]string, error) { arch := compileopts.MuslArchitecture(target) globs := []string{ "env/*.c", @@ -125,11 +125,14 @@ var Musl = Library{ "stdio/*.c", "string/*.c", "thread/" + arch + "/*.s", - "thread/" + arch + "/*.c", "thread/*.c", "time/*.c", "unistd/*.c", } + if arch == "arm" { + // These files need to be added to the start for some reason. + globs = append([]string{"thread/arm/*.c"}, globs...) + } var sources []string seenSources := map[string]struct{}{} @@ -143,13 +146,16 @@ var Musl = Library{ // > ErrBadPattern, when pattern is malformed. // So the only possible error is when the (statically defined) // pattern is wrong. In other words, a programming bug. - panic("could not glob source dirs: " + err.Error()) + return nil, fmt.Errorf("musl: could not glob source dirs: %w", err) + } + if len(matches) == 0 { + return nil, fmt.Errorf("musl: did not find any files for pattern %#v", pattern) } for _, match := range matches { relpath, err := filepath.Rel(basepath, match) if err != nil { // Not sure if this is even possible. - panic(err) + return nil, err } // Make sure architecture specific files override generic files. id := strings.ReplaceAll(relpath, "/"+arch+"/", "/") @@ -161,7 +167,7 @@ var Musl = Library{ sources = append(sources, relpath) } } - return sources + return sources, nil }, crt1Source: "../crt/crt1.c", // lib/musl/crt/crt1.c } diff --git a/builder/picolibc.go b/builder/picolibc.go index d0786ee3..1251f5ef 100644 --- a/builder/picolibc.go +++ b/builder/picolibc.go @@ -38,8 +38,8 @@ var Picolibc = Library{ } }, sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib") }, - librarySources: func(target string) []string { - return picolibcSources + librarySources: func(target string) ([]string, error) { + return picolibcSources, nil }, }