compileopts: don't filter build tags, use specific build tags instead
This basically reverts https://github.com/tinygo-org/tinygo/pull/3357 and replaces it with a different mechanism to get to the same goal. I do not think filtering tags like this is a good idea: it's the wrong part of the compiler to be concerned with such tags (that part sets tags, but doesn't modify existing tags). Instead, I've written the //go:build lines in such a way that it has the same effect: WASI defaults to leveldb, everything else defaults to fnv, and it's possible to override the default using build tags.
Этот коммит содержится в:
родитель
af76c807e2
коммит
4c682680ca
5 изменённых файлов: 10 добавлений и 161 удалений
|
@ -75,8 +75,7 @@ func (c *Config) GOARM() string {
|
||||||
|
|
||||||
// BuildTags returns the complete list of build tags used during this build.
|
// BuildTags returns the complete list of build tags used during this build.
|
||||||
func (c *Config) BuildTags() []string {
|
func (c *Config) BuildTags() []string {
|
||||||
targetTags := filterTags(c.Target.BuildTags, c.Options.Tags)
|
tags := append(c.Target.BuildTags, []string{"tinygo", "math_big_pure_go", "gc." + c.GC(), "scheduler." + c.Scheduler(), "serial." + c.Serial()}...)
|
||||||
tags := append(targetTags, []string{"tinygo", "math_big_pure_go", "gc." + c.GC(), "scheduler." + c.Scheduler(), "serial." + c.Serial()}...)
|
|
||||||
for i := 1; i <= c.GoMinorVersion; i++ {
|
for i := 1; i <= c.GoMinorVersion; i++ {
|
||||||
tags = append(tags, fmt.Sprintf("go1.%d", i))
|
tags = append(tags, fmt.Sprintf("go1.%d", i))
|
||||||
}
|
}
|
||||||
|
@ -552,27 +551,3 @@ type TestConfig struct {
|
||||||
BenchMem bool
|
BenchMem bool
|
||||||
Shuffle string
|
Shuffle string
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterTags removes predefined build tags for a target if a conflicting option
|
|
||||||
// is provided by the user.
|
|
||||||
func filterTags(targetTags []string, userTags []string) []string {
|
|
||||||
var filtered []string
|
|
||||||
for _, t := range targetTags {
|
|
||||||
switch {
|
|
||||||
case strings.HasPrefix(t, "runtime_memhash_"):
|
|
||||||
overridden := false
|
|
||||||
for _, ut := range userTags {
|
|
||||||
if strings.HasPrefix(ut, "runtime_memhash_") {
|
|
||||||
overridden = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !overridden {
|
|
||||||
filtered = append(filtered, t)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
filtered = append(filtered, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filtered
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,132 +0,0 @@
|
||||||
package compileopts
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestBuildTags(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
targetTags []string
|
|
||||||
userTags []string
|
|
||||||
result []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
targetTags: []string{},
|
|
||||||
userTags: []string{},
|
|
||||||
result: []string{
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{"bear"},
|
|
||||||
userTags: []string{},
|
|
||||||
result: []string{
|
|
||||||
"bear",
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{},
|
|
||||||
userTags: []string{"cat"},
|
|
||||||
result: []string{
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
"cat",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{"bear"},
|
|
||||||
userTags: []string{"cat"},
|
|
||||||
result: []string{
|
|
||||||
"bear",
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
"cat",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
|
||||||
userTags: []string{"cat"},
|
|
||||||
result: []string{
|
|
||||||
"bear",
|
|
||||||
"runtime_memhash_leveldb",
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
"cat",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
|
||||||
userTags: []string{"cat", "runtime_memhash_leveldb"},
|
|
||||||
result: []string{
|
|
||||||
"bear",
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
"cat",
|
|
||||||
"runtime_memhash_leveldb",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
targetTags: []string{"bear", "runtime_memhash_leveldb"},
|
|
||||||
userTags: []string{"cat", "runtime_memhash_sip"},
|
|
||||||
result: []string{
|
|
||||||
"bear",
|
|
||||||
"tinygo",
|
|
||||||
"math_big_pure_go",
|
|
||||||
"gc.conservative",
|
|
||||||
"scheduler.none",
|
|
||||||
"serial.none",
|
|
||||||
"cat",
|
|
||||||
"runtime_memhash_sip",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range tests {
|
|
||||||
tt := tc
|
|
||||||
t.Run(fmt.Sprintf("%s+%s", strings.Join(tt.targetTags, ","), strings.Join(tt.userTags, ",")), func(t *testing.T) {
|
|
||||||
c := &Config{
|
|
||||||
Target: &TargetSpec{
|
|
||||||
BuildTags: tt.targetTags,
|
|
||||||
},
|
|
||||||
Options: &Options{
|
|
||||||
Tags: tt.userTags,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res := c.BuildTags()
|
|
||||||
|
|
||||||
if len(res) != len(tt.result) {
|
|
||||||
t.Errorf("expected %d tags, got %d", len(tt.result), len(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tag := range tt.result {
|
|
||||||
if tag != res[i] {
|
|
||||||
t.Errorf("tag %d: expected %s, got %s", i, tt.result[i], tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,7 @@
|
||||||
//go:build !runtime_memhash_tsip && !runtime_memhash_leveldb
|
//go:build (!wasi && !runtime_memhash_tsip && !runtime_memhash_leveldb) || (wasi && runtime_memhash_fnv)
|
||||||
|
|
||||||
|
// This is the default for all targets except WASI, unless a more specific build
|
||||||
|
// tag is set.
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
//go:build runtime_memhash_leveldb
|
//go:build runtime_memhash_leveldb || (wasi && !runtime_memhash_fnv && !runtime_memhash_tsip)
|
||||||
|
|
||||||
|
// This is the default for WASI, but can also be used on other targets with the
|
||||||
|
// right build tag.
|
||||||
|
|
||||||
// This is the hash function from Google's leveldb key-value storage system. It
|
// This is the hash function from Google's leveldb key-value storage system. It
|
||||||
// processes 4 bytes at a time making it faster than the FNV hash for buffer
|
// processes 4 bytes at a time making it faster than the FNV hash for buffer
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"llvm-target": "wasm32-unknown-wasi",
|
"llvm-target": "wasm32-unknown-wasi",
|
||||||
"cpu": "generic",
|
"cpu": "generic",
|
||||||
"features": "+bulk-memory,+nontrapping-fptoint,+sign-ext",
|
"features": "+bulk-memory,+nontrapping-fptoint,+sign-ext",
|
||||||
"build-tags": ["tinygo.wasm", "wasi", "runtime_memhash_leveldb"],
|
"build-tags": ["tinygo.wasm", "wasi"],
|
||||||
"goos": "linux",
|
"goos": "linux",
|
||||||
"goarch": "arm",
|
"goarch": "arm",
|
||||||
"linker": "wasm-ld",
|
"linker": "wasm-ld",
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче