aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'compileopts/config.go')
-rw-r--r--compileopts/config.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index 9664d2770..bdbdd0d20 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -198,6 +198,16 @@ func (c *Config) RP2040BootPatch() bool {
return false
}
+// MuslArchitecture returns the architecture name as used in musl libc. It is
+// usually the same as the first part of the LLVM triple, but not always.
+func MuslArchitecture(triple string) string {
+ arch := strings.Split(triple, "-")[0]
+ if strings.HasPrefix(arch, "arm") || strings.HasPrefix(arch, "thumb") {
+ arch = "arm"
+ }
+ return arch
+}
+
// LibcPath returns the path to the libc directory. The libc path will be either
// a precompiled libc shipped with a TinyGo build, or a libc path in the cache
// directory (which might not yet be built).
@@ -238,6 +248,15 @@ func (c *Config) CFlags() []string {
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "include"),
"-Xclang", "-internal-isystem", "-Xclang", filepath.Join(picolibcDir, "tinystdio"),
)
+ case "musl":
+ root := goenv.Get("TINYGOROOT")
+ path, _ := c.LibcPath("musl")
+ arch := MuslArchitecture(c.Triple())
+ cflags = append(cflags,
+ "--sysroot="+path,
+ "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "arch", arch),
+ "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "musl", "include"),
+ )
case "wasi-libc":
root := goenv.Get("TINYGOROOT")
cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot")