builder: add -mcpu flag while building libraries

This flag is important for the Xtensa backend because by default a more
powerful backend (ESP32) is assumed. Therefore, compiling for the
ESP8266 won't work by default and needs the -mcpu flag.
Этот коммит содержится в:
Ayke van Laethem 2021-02-10 23:37:07 +01:00 коммит произвёл Ron Evans
родитель 74fe213b15
коммит 8a54615a09
2 изменённых файлов: 13 добавлений и 5 удалений

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

@ -171,7 +171,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
// Add compiler-rt dependency if needed. Usually this is a simple load from
// a cache.
if config.Target.RTLib == "compiler-rt" {
path, job, err := CompilerRT.load(config.Triple(), dir)
path, job, err := CompilerRT.load(config.Triple(), config.CPU(), dir)
if err != nil {
return err
}
@ -187,7 +187,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
// Add libc dependency if needed.
if config.Target.Libc == "picolibc" {
path, job, err := Picolibc.load(config.Triple(), dir)
path, job, err := Picolibc.load(config.Triple(), config.CPU(), dir)
if err != nil {
return err
}

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

@ -42,7 +42,7 @@ func (l *Library) sourcePaths(target string) []string {
// The resulting file is stored in the provided tmpdir, which is expected to be
// removed after the Load call.
func (l *Library) Load(target, tmpdir string) (path string, err error) {
path, job, err := l.load(target, tmpdir)
path, job, err := l.load(target, "", tmpdir)
if err != nil {
return "", err
}
@ -59,7 +59,7 @@ func (l *Library) Load(target, tmpdir string) (path string, err error) {
// path is valid.
// The provided tmpdir will be used to store intermediary files and possibly the
// output archive file, it is expected to be removed after use.
func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err error) {
func (l *Library) load(target, cpu, tmpdir string) (path string, job *compileJob, err error) {
// Try to load a precompiled library.
precompiledPath := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", target, l.name+".a")
if _, err := os.Stat(precompiledPath); err == nil {
@ -68,7 +68,12 @@ func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err
return precompiledPath, nil, nil
}
outfile := l.name + "-" + target + ".a"
var outfile string
if cpu != "" {
outfile = l.name + "-" + target + "-" + cpu + ".a"
} else {
outfile = l.name + "-" + target + ".a"
}
// Try to fetch this library from the cache.
if path, err := cacheLoad(outfile, l.sourcePaths(target)); path != "" || err != nil {
@ -89,6 +94,9 @@ func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err
// reproducible. Otherwise the temporary directory is stored in the archive
// itself, which varies each run.
args := append(l.cflags(), "-c", "-Oz", "-g", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir)
if cpu != "" {
args = append(args, "-mcpu="+cpu)
}
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft")
}