builder: hard code Clang compiler
At the moment, all targets use the Clang compiler to compile C and assembly files. There is no good reason to make this configurable anymore and in fact it will make future changes more complicated (and thus more likely to have bugs). Therefore, I've removed support for setting the compiler. Note that the same is not true for the linker. While it makes sense to standardize on the Clang compiler (because if Clang doesn't support a target, TinyGo is unlikely to support it either), linkers will remain configurable for the foreseeable future. One example is Xtensa, which is supported by the Xtensa LLVM fork but doesn't have support in ld.lld yet. I've also fixed a bug in compileAndCacheCFile: it wasn't using the right CFlags for caching purposes. This could lead to using stale caches. This commit fixes that too.
Этот коммит содержится в:
родитель
6152a661e8
коммит
f706219996
13 изменённых файлов: 12 добавлений и 34 удалений
|
@ -494,7 +494,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||||
job := &compileJob{
|
job := &compileJob{
|
||||||
description: "compile extra file " + path,
|
description: "compile extra file " + path,
|
||||||
run: func(job *compileJob) error {
|
run: func(job *compileJob) error {
|
||||||
result, err := compileAndCacheCFile(abspath, dir, config.CFlags(), config)
|
result, err := compileAndCacheCFile(abspath, dir, config.CFlags(), config.Options.PrintCommands)
|
||||||
job.result = result
|
job.result = result
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
@ -513,7 +513,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||||
job := &compileJob{
|
job := &compileJob{
|
||||||
description: "compile CGo file " + abspath,
|
description: "compile CGo file " + abspath,
|
||||||
run: func(job *compileJob) error {
|
run: func(job *compileJob) error {
|
||||||
result, err := compileAndCacheCFile(abspath, dir, pkg.CFlags, config)
|
result, err := compileAndCacheCFile(abspath, dir, pkg.CFlags, config.Options.PrintCommands)
|
||||||
job.result = result
|
job.result = result
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/tinygo-org/tinygo/compileopts"
|
|
||||||
"github.com/tinygo-org/tinygo/goenv"
|
"github.com/tinygo-org/tinygo/goenv"
|
||||||
"tinygo.org/x/go-llvm"
|
"tinygo.org/x/go-llvm"
|
||||||
)
|
)
|
||||||
|
@ -57,7 +56,7 @@ import (
|
||||||
// depfile but without invalidating its name. For this reason, the depfile is
|
// depfile but without invalidating its name. For this reason, the depfile is
|
||||||
// written on each new compilation (even when it seems unnecessary). However, it
|
// written on each new compilation (even when it seems unnecessary). However, it
|
||||||
// could in rare cases lead to a stale file fetched from the cache.
|
// could in rare cases lead to a stale file fetched from the cache.
|
||||||
func compileAndCacheCFile(abspath, tmpdir string, cflags []string, config *compileopts.Config) (string, error) {
|
func compileAndCacheCFile(abspath, tmpdir string, cflags []string, printCommands bool) (string, error) {
|
||||||
// Hash input file.
|
// Hash input file.
|
||||||
fileHash, err := hashFile(abspath)
|
fileHash, err := hashFile(abspath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -68,14 +67,12 @@ func compileAndCacheCFile(abspath, tmpdir string, cflags []string, config *compi
|
||||||
buf, err := json.Marshal(struct {
|
buf, err := json.Marshal(struct {
|
||||||
Path string
|
Path string
|
||||||
Hash string
|
Hash string
|
||||||
Compiler string
|
|
||||||
Flags []string
|
Flags []string
|
||||||
LLVMVersion string
|
LLVMVersion string
|
||||||
}{
|
}{
|
||||||
Path: abspath,
|
Path: abspath,
|
||||||
Hash: fileHash,
|
Hash: fileHash,
|
||||||
Compiler: config.Target.Compiler,
|
Flags: cflags,
|
||||||
Flags: config.CFlags(),
|
|
||||||
LLVMVersion: llvm.Version,
|
LLVMVersion: llvm.Version,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -131,10 +128,10 @@ func compileAndCacheCFile(abspath, tmpdir string, cflags []string, config *compi
|
||||||
// flags (for the assembler) is a compiler error.
|
// flags (for the assembler) is a compiler error.
|
||||||
flags = append(flags, "-Qunused-arguments")
|
flags = append(flags, "-Qunused-arguments")
|
||||||
}
|
}
|
||||||
if config.Options.PrintCommands {
|
if printCommands {
|
||||||
fmt.Printf("%s %s\n", config.Target.Compiler, strings.Join(flags, " "))
|
fmt.Printf("clang %s\n", strings.Join(flags, " "))
|
||||||
}
|
}
|
||||||
err = runCCompiler(config.Target.Compiler, flags...)
|
err = runCCompiler(flags...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", &commandError{"failed to build", abspath, err}
|
return "", &commandError{"failed to build", abspath, err}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (l *Library) load(target, cpu, tmpdir string) (job *compileJob, err error)
|
||||||
var compileArgs []string
|
var compileArgs []string
|
||||||
compileArgs = append(compileArgs, args...)
|
compileArgs = append(compileArgs, args...)
|
||||||
compileArgs = append(compileArgs, "-o", objpath, srcpath)
|
compileArgs = append(compileArgs, "-o", objpath, srcpath)
|
||||||
err := runCCompiler("clang", compileArgs...)
|
err := runCCompiler(compileArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &commandError{"failed to build", srcpath, err}
|
return &commandError{"failed to build", srcpath, err}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// runCCompiler invokes a C compiler with the given arguments.
|
// runCCompiler invokes a C compiler with the given arguments.
|
||||||
func runCCompiler(command string, flags ...string) error {
|
func runCCompiler(flags ...string) error {
|
||||||
if hasBuiltinTools && command == "clang" {
|
if hasBuiltinTools {
|
||||||
// Compile this with the internal Clang compiler.
|
// Compile this with the internal Clang compiler.
|
||||||
headerPath := getClangHeaderPath(goenv.Get("TINYGOROOT"))
|
headerPath := getClangHeaderPath(goenv.Get("TINYGOROOT"))
|
||||||
if headerPath == "" {
|
if headerPath == "" {
|
||||||
|
@ -23,17 +23,8 @@ func runCCompiler(command string, flags ...string) error {
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Running some other compiler. Maybe it has been defined in the
|
// Compile this with an external invocation of the Clang compiler.
|
||||||
// commands map (unlikely).
|
return execCommand(commands["clang"], flags...)
|
||||||
if cmdNames, ok := commands[command]; ok {
|
|
||||||
return execCommand(cmdNames, flags...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alternatively, run the compiler directly.
|
|
||||||
cmd := exec.Command(command, flags...)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// link invokes a linker with the given name and flags.
|
// link invokes a linker with the given name and flags.
|
||||||
|
|
|
@ -31,7 +31,6 @@ type TargetSpec struct {
|
||||||
BuildTags []string `json:"build-tags"`
|
BuildTags []string `json:"build-tags"`
|
||||||
GC string `json:"gc"`
|
GC string `json:"gc"`
|
||||||
Scheduler string `json:"scheduler"`
|
Scheduler string `json:"scheduler"`
|
||||||
Compiler string `json:"compiler"`
|
|
||||||
Linker string `json:"linker"`
|
Linker string `json:"linker"`
|
||||||
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
||||||
Libc string `json:"libc"`
|
Libc string `json:"libc"`
|
||||||
|
@ -244,7 +243,6 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
GOOS: goos,
|
GOOS: goos,
|
||||||
GOARCH: goarch,
|
GOARCH: goarch,
|
||||||
BuildTags: []string{goos, goarch},
|
BuildTags: []string{goos, goarch},
|
||||||
Compiler: "clang",
|
|
||||||
Linker: "cc",
|
Linker: "cc",
|
||||||
CFlags: []string{"--target=" + triple},
|
CFlags: []string{"--target=" + triple},
|
||||||
GDB: []string{"gdb"},
|
GDB: []string{"gdb"},
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"build-tags": ["avr", "baremetal", "linux", "arm"],
|
"build-tags": ["avr", "baremetal", "linux", "arm"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"compiler": "clang",
|
|
||||||
"gc": "conservative",
|
"gc": "conservative",
|
||||||
"linker": "avr-gcc",
|
"linker": "avr-gcc",
|
||||||
"scheduler": "none",
|
"scheduler": "none",
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
"build-tags": ["cortexm", "baremetal", "linux", "arm"],
|
"build-tags": ["cortexm", "baremetal", "linux", "arm"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"compiler": "clang",
|
|
||||||
"gc": "conservative",
|
"gc": "conservative",
|
||||||
"scheduler": "tasks",
|
"scheduler": "tasks",
|
||||||
"linker": "ld.lld",
|
"linker": "ld.lld",
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"],
|
"build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"compiler": "clang",
|
|
||||||
"linker": "ld.lld",
|
"linker": "ld.lld",
|
||||||
"rtlib": "compiler-rt",
|
"rtlib": "compiler-rt",
|
||||||
"libc": "picolibc",
|
"libc": "picolibc",
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"build-tags": ["nintendoswitch", "arm64"],
|
"build-tags": ["nintendoswitch", "arm64"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm64",
|
"goarch": "arm64",
|
||||||
"compiler": "clang",
|
|
||||||
"linker": "ld.lld",
|
"linker": "ld.lld",
|
||||||
"rtlib": "compiler-rt",
|
"rtlib": "compiler-rt",
|
||||||
"libc": "picolibc",
|
"libc": "picolibc",
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"build-tags": ["tinygo.riscv", "baremetal", "linux", "arm"],
|
"build-tags": ["tinygo.riscv", "baremetal", "linux", "arm"],
|
||||||
"gc": "conservative",
|
"gc": "conservative",
|
||||||
"compiler": "clang",
|
|
||||||
"linker": "ld.lld",
|
"linker": "ld.lld",
|
||||||
"rtlib": "compiler-rt",
|
"rtlib": "compiler-rt",
|
||||||
"libc": "picolibc",
|
"libc": "picolibc",
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"build-tags": ["wasm", "wasi"],
|
"build-tags": ["wasm", "wasi"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"compiler": "clang",
|
|
||||||
"linker": "wasm-ld",
|
"linker": "wasm-ld",
|
||||||
"libc": "wasi-libc",
|
"libc": "wasi-libc",
|
||||||
"cflags": [
|
"cflags": [
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"build-tags": ["js", "wasm"],
|
"build-tags": ["js", "wasm"],
|
||||||
"goos": "js",
|
"goos": "js",
|
||||||
"goarch": "wasm",
|
"goarch": "wasm",
|
||||||
"compiler": "clang",
|
|
||||||
"linker": "wasm-ld",
|
"linker": "wasm-ld",
|
||||||
"libc": "wasi-libc",
|
"libc": "wasi-libc",
|
||||||
"cflags": [
|
"cflags": [
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
"build-tags": ["xtensa", "baremetal", "linux", "arm"],
|
"build-tags": ["xtensa", "baremetal", "linux", "arm"],
|
||||||
"gc": "conservative",
|
"gc": "conservative",
|
||||||
"scheduler": "none",
|
"scheduler": "none",
|
||||||
"compiler": "clang",
|
|
||||||
"cflags": [
|
"cflags": [
|
||||||
"--target=xtensa",
|
"--target=xtensa",
|
||||||
"-Oz",
|
"-Oz",
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче