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.
Этот коммит содержится в:
родитель
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
|
// Add compiler-rt dependency if needed. Usually this is a simple load from
|
||||||
// a cache.
|
// a cache.
|
||||||
if config.Target.RTLib == "compiler-rt" {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||||
|
|
||||||
// Add libc dependency if needed.
|
// Add libc dependency if needed.
|
||||||
if config.Target.Libc == "picolibc" {
|
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 {
|
if err != nil {
|
||||||
return err
|
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
|
// The resulting file is stored in the provided tmpdir, which is expected to be
|
||||||
// removed after the Load call.
|
// removed after the Load call.
|
||||||
func (l *Library) Load(target, tmpdir string) (path string, err error) {
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (l *Library) Load(target, tmpdir string) (path string, err error) {
|
||||||
// path is valid.
|
// path is valid.
|
||||||
// The provided tmpdir will be used to store intermediary files and possibly the
|
// The provided tmpdir will be used to store intermediary files and possibly the
|
||||||
// output archive file, it is expected to be removed after use.
|
// 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.
|
// Try to load a precompiled library.
|
||||||
precompiledPath := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", target, l.name+".a")
|
precompiledPath := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", target, l.name+".a")
|
||||||
if _, err := os.Stat(precompiledPath); err == nil {
|
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
|
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.
|
// Try to fetch this library from the cache.
|
||||||
if path, err := cacheLoad(outfile, l.sourcePaths(target)); path != "" || err != nil {
|
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
|
// reproducible. Otherwise the temporary directory is stored in the archive
|
||||||
// itself, which varies each run.
|
// 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)
|
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") {
|
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
|
||||||
args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft")
|
args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft")
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче