cgo: support builtin #include headers

Add support for header files bundled with the compiler by copying them
into the release tarball.
This commit is contained in:
Ayke van Laethem
2019-04-20 15:14:48 +02:00
committed by Ron Evans
parent d396abb690
commit 2f2d62cc0c
10 changed files with 49 additions and 18 deletions
+12 -1
View File
@@ -22,6 +22,7 @@ type Program struct {
fset *token.FileSet
TypeChecker types.Config
Dir string // current working directory (for error reporting)
TinyGoRoot string // root of the TinyGo installation or root of the source code
CFlags []string
}
@@ -292,6 +293,16 @@ func (p *Package) parseFiles() ([]*ast.File, error) {
}
files = append(files, f)
}
clangIncludes := ""
if len(p.CgoFiles) != 0 {
if _, err := os.Stat(filepath.Join(p.TinyGoRoot, "llvm", "tools", "clang", "lib", "Headers")); !os.IsNotExist(err) {
// Running from the source directory.
clangIncludes = filepath.Join(p.TinyGoRoot, "llvm", "tools", "clang", "lib", "Headers")
} else {
// Running from the installation directory.
clangIncludes = filepath.Join(p.TinyGoRoot, "lib", "clang", "include")
}
}
for _, file := range p.CgoFiles {
path := filepath.Join(p.Package.Dir, file)
f, err := p.parseFile(path, parser.ParseComments)
@@ -299,7 +310,7 @@ func (p *Package) parseFiles() ([]*ast.File, error) {
fileErrs = append(fileErrs, err)
continue
}
errs := p.processCgo(path, f, append(p.CFlags, "-I"+p.Package.Dir))
errs := p.processCgo(path, f, append(p.CFlags, "-I"+p.Package.Dir, "-I"+clangIncludes))
if errs != nil {
fileErrs = append(fileErrs, errs...)
continue