aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-10-13 16:12:34 +0200
committerRon Evans <[email protected]>2023-10-14 11:35:26 +0200
commitd801d0cd539447322228e9f1daa860774584b4d3 (patch)
treea1a608bd558051b19f05cb2114585489f4cefae9 /compileopts
parentc2f1965e0358d3f044bd8f8282ce3942d669ff89 (diff)
downloadtinygo-d801d0cd539447322228e9f1daa860774584b4d3.tar.gz
tinygo-d801d0cd539447322228e9f1daa860774584b4d3.zip
builder: refactor clang include headers
Set -resource-dir in a central place instead of passing the header path around everywhere and adding it using the `-I` flag. I believe this is closer to how Clang is intended to be used. This change was inspired by my attempt to add a Nix flake file to TinyGo.
Diffstat (limited to 'compileopts')
-rw-r--r--compileopts/config.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index 5ad45c607..578534a15 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -19,7 +19,6 @@ type Config struct {
Options *Options
Target *TargetSpec
GoMinorVersion int
- ClangHeaders string // Clang built-in header include path
TestConfig TestConfig
}
@@ -259,11 +258,19 @@ func (c *Config) DefaultBinaryExtension() string {
// CFlags returns the flags to pass to the C compiler. This is necessary for CGo
// preprocessing.
-func (c *Config) CFlags() []string {
+func (c *Config) CFlags(libclang bool) []string {
var cflags []string
for _, flag := range c.Target.CFlags {
cflags = append(cflags, strings.ReplaceAll(flag, "{root}", goenv.Get("TINYGOROOT")))
}
+ resourceDir := goenv.ClangResourceDir(libclang)
+ if resourceDir != "" {
+ // The resoure directory contains the built-in clang headers like
+ // stdbool.h, stdint.h, float.h, etc.
+ // It is left empty if we're using an external compiler (that already
+ // knows these headers).
+ cflags = append(cflags, "-resource-dir="+resourceDir)
+ }
switch c.Target.Libc {
case "darwin-libSystem":
root := goenv.Get("TINYGOROOT")
@@ -275,8 +282,8 @@ func (c *Config) CFlags() []string {
picolibcDir := filepath.Join(root, "lib", "picolibc", "newlib", "libc")
path, _ := c.LibcPath("picolibc")
cflags = append(cflags,
- "--sysroot="+path,
- "-isystem", filepath.Join(path, "include"), // necessary for Xtensa
+ "-nostdlibinc",
+ "-isystem", filepath.Join(path, "include"),
"-isystem", filepath.Join(picolibcDir, "include"),
"-isystem", filepath.Join(picolibcDir, "tinystdio"),
)