diff --git a/cgo/cgo.go b/cgo/cgo.go index efaa949c..15b38869 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 b46c36dd..cbb0f589 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 diff --git a/loader/loader.go b/loader/loader.go index b8db2587..e9de2ec2 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -418,10 +418,7 @@ func (p *Package) parseFiles() ([]*ast.File, error) { var initialCFlags []string initialCFlags = append(initialCFlags, p.program.config.CFlags()...) initialCFlags = append(initialCFlags, "-I"+p.Dir) - if p.program.clangHeaders != "" { - initialCFlags = append(initialCFlags, "-isystem", p.program.clangHeaders) - } - generated, headerCode, cflags, ldflags, accessedFiles, errs := cgo.Process(files, p.program.workingDir, p.program.fset, initialCFlags) + generated, headerCode, cflags, ldflags, accessedFiles, errs := cgo.Process(files, p.program.workingDir, p.program.fset, initialCFlags, p.program.clangHeaders) p.CFlags = append(initialCFlags, cflags...) p.CGoHeaders = headerCode for path, hash := range accessedFiles {