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{
|
||||
description: "compile extra file " + path,
|
||||
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
|
||||
return err
|
||||
},
|
||||
|
@ -513,7 +513,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
|||
job := &compileJob{
|
||||
description: "compile CGo file " + abspath,
|
||||
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
|
||||
return err
|
||||
},
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
|
@ -57,7 +56,7 @@ import (
|
|||
// depfile but without invalidating its name. For this reason, the depfile is
|
||||
// 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.
|
||||
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.
|
||||
fileHash, err := hashFile(abspath)
|
||||
if err != nil {
|
||||
|
@ -68,14 +67,12 @@ func compileAndCacheCFile(abspath, tmpdir string, cflags []string, config *compi
|
|||
buf, err := json.Marshal(struct {
|
||||
Path string
|
||||
Hash string
|
||||
Compiler string
|
||||
Flags []string
|
||||
LLVMVersion string
|
||||
}{
|
||||
Path: abspath,
|
||||
Hash: fileHash,
|
||||
Compiler: config.Target.Compiler,
|
||||
Flags: config.CFlags(),
|
||||
Flags: cflags,
|
||||
LLVMVersion: llvm.Version,
|
||||
})
|
||||
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 = append(flags, "-Qunused-arguments")
|
||||
}
|
||||
if config.Options.PrintCommands {
|
||||
fmt.Printf("%s %s\n", config.Target.Compiler, strings.Join(flags, " "))
|
||||
if printCommands {
|
||||
fmt.Printf("clang %s\n", strings.Join(flags, " "))
|
||||
}
|
||||
err = runCCompiler(config.Target.Compiler, flags...)
|
||||
err = runCCompiler(flags...)
|
||||
if err != nil {
|
||||
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
|
||||
compileArgs = append(compileArgs, args...)
|
||||
compileArgs = append(compileArgs, "-o", objpath, srcpath)
|
||||
err := runCCompiler("clang", compileArgs...)
|
||||
err := runCCompiler(compileArgs...)
|
||||
if err != nil {
|
||||
return &commandError{"failed to build", srcpath, err}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
)
|
||||
|
||||
// runCCompiler invokes a C compiler with the given arguments.
|
||||
func runCCompiler(command string, flags ...string) error {
|
||||
if hasBuiltinTools && command == "clang" {
|
||||
func runCCompiler(flags ...string) error {
|
||||
if hasBuiltinTools {
|
||||
// Compile this with the internal Clang compiler.
|
||||
headerPath := getClangHeaderPath(goenv.Get("TINYGOROOT"))
|
||||
if headerPath == "" {
|
||||
|
@ -23,17 +23,8 @@ func runCCompiler(command string, flags ...string) error {
|
|||
return cmd.Run()
|
||||
}
|
||||
|
||||
// Running some other compiler. Maybe it has been defined in the
|
||||
// commands map (unlikely).
|
||||
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()
|
||||
// Compile this with an external invocation of the Clang compiler.
|
||||
return execCommand(commands["clang"], flags...)
|
||||
}
|
||||
|
||||
// link invokes a linker with the given name and flags.
|
||||
|
|
|
@ -31,7 +31,6 @@ type TargetSpec struct {
|
|||
BuildTags []string `json:"build-tags"`
|
||||
GC string `json:"gc"`
|
||||
Scheduler string `json:"scheduler"`
|
||||
Compiler string `json:"compiler"`
|
||||
Linker string `json:"linker"`
|
||||
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
||||
Libc string `json:"libc"`
|
||||
|
@ -244,7 +243,6 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
|||
GOOS: goos,
|
||||
GOARCH: goarch,
|
||||
BuildTags: []string{goos, goarch},
|
||||
Compiler: "clang",
|
||||
Linker: "cc",
|
||||
CFlags: []string{"--target=" + triple},
|
||||
GDB: []string{"gdb"},
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"build-tags": ["avr", "baremetal", "linux", "arm"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm",
|
||||
"compiler": "clang",
|
||||
"gc": "conservative",
|
||||
"linker": "avr-gcc",
|
||||
"scheduler": "none",
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"build-tags": ["cortexm", "baremetal", "linux", "arm"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm",
|
||||
"compiler": "clang",
|
||||
"gc": "conservative",
|
||||
"scheduler": "tasks",
|
||||
"linker": "ld.lld",
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"build-tags": ["gameboyadvance", "arm7tdmi", "baremetal", "linux", "arm"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm",
|
||||
"compiler": "clang",
|
||||
"linker": "ld.lld",
|
||||
"rtlib": "compiler-rt",
|
||||
"libc": "picolibc",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"build-tags": ["nintendoswitch", "arm64"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm64",
|
||||
"compiler": "clang",
|
||||
"linker": "ld.lld",
|
||||
"rtlib": "compiler-rt",
|
||||
"libc": "picolibc",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"goarch": "arm",
|
||||
"build-tags": ["tinygo.riscv", "baremetal", "linux", "arm"],
|
||||
"gc": "conservative",
|
||||
"compiler": "clang",
|
||||
"linker": "ld.lld",
|
||||
"rtlib": "compiler-rt",
|
||||
"libc": "picolibc",
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"build-tags": ["wasm", "wasi"],
|
||||
"goos": "linux",
|
||||
"goarch": "arm",
|
||||
"compiler": "clang",
|
||||
"linker": "wasm-ld",
|
||||
"libc": "wasi-libc",
|
||||
"cflags": [
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
"build-tags": ["js", "wasm"],
|
||||
"goos": "js",
|
||||
"goarch": "wasm",
|
||||
"compiler": "clang",
|
||||
"linker": "wasm-ld",
|
||||
"libc": "wasi-libc",
|
||||
"cflags": [
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"build-tags": ["xtensa", "baremetal", "linux", "arm"],
|
||||
"gc": "conservative",
|
||||
"scheduler": "none",
|
||||
"compiler": "clang",
|
||||
"cflags": [
|
||||
"--target=xtensa",
|
||||
"-Oz",
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче