diff options
author | Ayke van Laethem <[email protected]> | 2019-06-13 13:52:45 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-06-13 15:21:04 +0200 |
commit | a3d1f1a514aaaad6c2bfe6024ee48211cf6b7575 (patch) | |
tree | d8d2d70fb565d8c037b92fb2a01c6bc22a281724 /loader | |
parent | 3e1c0d90c5de927d5ff5f334379b3734d3912021 (diff) | |
download | tinygo-a3d1f1a514aaaad6c2bfe6024ee48211cf6b7575.tar.gz tinygo-a3d1f1a514aaaad6c2bfe6024ee48211cf6b7575.zip |
all: try more locations to find Clang built-in headers
This commit fixes the case where TinyGo was built with `go build` and
LLVM sources were never downloaded into the TinyGo source directory.
Diffstat (limited to 'loader')
-rw-r--r-- | loader/loader.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/loader/loader.go b/loader/loader.go index 7b20a925a..cfa81e99f 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -26,6 +26,7 @@ type Program struct { Dir string // current working directory (for error reporting) TINYGOROOT string // root of the TinyGo installation or root of the source code CFlags []string + ClangHeaders string } // Package holds a loaded package, its imports, and its parsed files. @@ -306,15 +307,11 @@ func (p *Package) parseFiles() ([]*ast.File, error) { files = append(files, f) } if len(p.CgoFiles) != 0 { - clangIncludes := "" - 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") + cflags := append(p.CFlags, "-I"+p.Package.Dir) + if p.ClangHeaders != "" { + cflags = append(cflags, "-I"+p.ClangHeaders) } - generated, errs := cgo.Process(files, p.Program.Dir, p.fset, append(p.CFlags, "-I"+p.Package.Dir, "-I"+clangIncludes)) + generated, errs := cgo.Process(files, p.Program.Dir, p.fset, cflags) if errs != nil { fileErrs = append(fileErrs, errs...) } |