main: move ldflags to compileopts

Этот коммит содержится в:
Ayke van Laethem 2019-11-03 11:55:51 +01:00 коммит произвёл Ron Evans
родитель ac330f4a70
коммит 18cce571a2
2 изменённых файлов: 22 добавлений и 13 удалений

Просмотреть файл

@ -4,6 +4,7 @@ package compileopts
import (
"fmt"
"strconv"
"strings"
"github.com/tinygo-org/tinygo/goenv"
@ -104,6 +105,26 @@ func (c *Config) CFlags() []string {
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
// enable this for debugging.
func (c *Config) DumpSSA() bool {

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.
executable := filepath.Join(dir, "main")
tmppath := executable // final file
ldflags = append(ldflags, "-o", executable, objfile, "-L", root)
ldflags := append(compilerConfig.LDFlags(), "-o", executable, objfile)
if spec.RTLib == "compiler-rt" {
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.
for i, path := range spec.ExtraFiles {