diff options
author | Ayke van Laethem <[email protected]> | 2022-02-03 10:55:35 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-02-12 15:33:06 +0100 |
commit | 850a5fdbfb00f1bdfe930bd41013d0404f75e248 (patch) | |
tree | 83bccc93292ce60d6245f2c39f5c2e25ef9f8868 /cgo | |
parent | 4b2edc9a26a84b4870d61ddf09f70369ab9f6f1e (diff) | |
download | tinygo-850a5fdbfb00f1bdfe930bd41013d0404f75e248.tar.gz tinygo-850a5fdbfb00f1bdfe930bd41013d0404f75e248.zip |
loader: only add Clang header path for CGo
It should only be added at the point that it is needed, for example when
using libclang or using the built-in Clang. It isn't needed when running
an external tool.
Diffstat (limited to 'cgo')
-rw-r--r-- | cgo/cgo.go | 5 | ||||
-rw-r--r-- | cgo/cgo_test.go | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/cgo/cgo.go b/cgo/cgo.go index efaa949cc..15b388694 100644 --- a/cgo/cgo.go +++ b/cgo/cgo.go @@ -197,7 +197,7 @@ func GoBytes(ptr unsafe.Pointer, length C.int) []byte { // functions), the CFLAGS and LDFLAGS found in #cgo lines, and a map of file // hashes of the accessed C header files. If there is one or more error, it // returns these in the []error slice but still modifies the AST. -func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string) (*ast.File, []string, []string, []string, map[string][]byte, []error) { +func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string, clangHeaders string) (*ast.File, []string, []string, []string, map[string][]byte, []error) { p := &cgoPackage{ currentDir: dir, fset: fset, @@ -333,6 +333,9 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string // have better alternatives anyway. cflagsForCGo := append([]string{"-D_FORTIFY_SOURCE=0"}, cflags...) cflagsForCGo = append(cflagsForCGo, p.cflags...) + if clangHeaders != "" { + cflagsForCGo = append(cflagsForCGo, "-isystem", clangHeaders) + } // Process CGo imports for each file. for i, f := range files { diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go index b46c36dd6..cbb0f5897 100644 --- a/cgo/cgo_test.go +++ b/cgo/cgo_test.go @@ -63,7 +63,7 @@ func TestCGo(t *testing.T) { } // Process the AST with CGo. - cgoAST, _, _, _, _, cgoErrors := Process([]*ast.File{f}, "testdata", fset, cflags) + cgoAST, _, _, _, _, cgoErrors := Process([]*ast.File{f}, "testdata", fset, cflags, "") // Check the AST for type errors. var typecheckErrors []error |