main: move ldflags to compileopts
Этот коммит содержится в:
родитель
ac330f4a70
коммит
18cce571a2
2 изменённых файлов: 22 добавлений и 13 удалений
|
@ -4,6 +4,7 @@ package compileopts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tinygo-org/tinygo/goenv"
|
"github.com/tinygo-org/tinygo/goenv"
|
||||||
|
@ -104,6 +105,26 @@ func (c *Config) CFlags() []string {
|
||||||
return cflags
|
return cflags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LDFlags returns the flags to pass to the linker. A few more flags are needed
|
||||||
|
// (like the one for the compiler runtime), but this represents the majority of
|
||||||
|
// the flags.
|
||||||
|
func (c *Config) LDFlags() []string {
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
// Merge and adjust LDFlags.
|
||||||
|
ldflags := append([]string{}, c.Options.LDFlags...)
|
||||||
|
for _, flag := range c.Target.LDFlags {
|
||||||
|
ldflags = append(ldflags, strings.Replace(flag, "{root}", root, -1))
|
||||||
|
}
|
||||||
|
ldflags = append(ldflags, "-L", root)
|
||||||
|
if c.Target.GOARCH == "wasm" {
|
||||||
|
// Round heap size to next multiple of 65536 (the WebAssembly page
|
||||||
|
// size).
|
||||||
|
heapSize := (c.Options.HeapSize + (65536 - 1)) &^ (65536 - 1)
|
||||||
|
ldflags = append(ldflags, "--initial-memory="+strconv.FormatInt(heapSize, 10))
|
||||||
|
}
|
||||||
|
return ldflags
|
||||||
|
}
|
||||||
|
|
||||||
// DumpSSA returns whether to dump Go SSA while compiling (-dumpssa flag). Only
|
// DumpSSA returns whether to dump Go SSA while compiling (-dumpssa flag). Only
|
||||||
// enable this for debugging.
|
// enable this for debugging.
|
||||||
func (c *Config) DumpSSA() bool {
|
func (c *Config) DumpSSA() bool {
|
||||||
|
|
14
main.go
14
main.go
|
@ -187,25 +187,13 @@ func Compile(pkgName, outpath string, spec *compileopts.TargetSpec, options *com
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge and adjust LDFlags.
|
|
||||||
ldflags := append([]string{}, options.LDFlags...)
|
|
||||||
for _, flag := range spec.LDFlags {
|
|
||||||
ldflags = append(ldflags, strings.Replace(flag, "{root}", root, -1))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare link command.
|
// Prepare link command.
|
||||||
executable := filepath.Join(dir, "main")
|
executable := filepath.Join(dir, "main")
|
||||||
tmppath := executable // final file
|
tmppath := executable // final file
|
||||||
ldflags = append(ldflags, "-o", executable, objfile, "-L", root)
|
ldflags := append(compilerConfig.LDFlags(), "-o", executable, objfile)
|
||||||
if spec.RTLib == "compiler-rt" {
|
if spec.RTLib == "compiler-rt" {
|
||||||
ldflags = append(ldflags, librt)
|
ldflags = append(ldflags, librt)
|
||||||
}
|
}
|
||||||
if spec.GOARCH == "wasm" {
|
|
||||||
// Round heap size to next multiple of 65536 (the WebAssembly page
|
|
||||||
// size).
|
|
||||||
heapSize := (options.HeapSize + (65536 - 1)) &^ (65536 - 1)
|
|
||||||
ldflags = append(ldflags, "--initial-memory="+strconv.FormatInt(heapSize, 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile extra files.
|
// Compile extra files.
|
||||||
for i, path := range spec.ExtraFiles {
|
for i, path := range spec.ExtraFiles {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче