Files
llgo/internal/crosscompile/libc.go

79 lines
2.3 KiB
Go
Raw Normal View History

2025-08-25 19:05:30 +08:00
package crosscompile
import (
"fmt"
"path/filepath"
2025-08-28 20:11:13 +08:00
2025-08-29 11:30:25 +08:00
"github.com/goplus/llgo/internal/crosscompile/compile"
"github.com/goplus/llgo/internal/crosscompile/compile/libc"
"github.com/goplus/llgo/internal/crosscompile/compile/rtlib"
2025-08-25 19:05:30 +08:00
)
2025-09-04 19:08:48 +08:00
// for testing, in testing env, we use fake path, it will cause downloading failure
var needSkipDownload = false
2025-09-09 17:45:02 +08:00
// getLibcCompileConfigByName retrieves libc compilation configuration by name
// Returns the actual libc output dir, compilation config and err
2025-09-04 19:08:48 +08:00
func getLibcCompileConfigByName(baseDir, libcName, target, mcpu string) (outputDir string, cfg compile.CompileConfig, err error) {
2025-08-25 19:05:30 +08:00
if libcName == "" {
2025-09-04 19:08:48 +08:00
err = fmt.Errorf("libc name cannot be empty")
return
2025-08-25 19:05:30 +08:00
}
2025-09-04 19:08:48 +08:00
var libcDir string
var config compile.LibConfig
var compileConfig compile.CompileConfig
2025-08-25 19:05:30 +08:00
switch libcName {
case "picolibc":
2025-09-04 19:08:48 +08:00
config = libc.GetPicolibcConfig()
libcDir = filepath.Join(baseDir, config.String())
compileConfig = libc.GetPicolibcCompileConfig(libcDir, target)
2025-08-28 20:11:13 +08:00
case "newlib-esp32":
2025-09-04 19:08:48 +08:00
config = libc.GetNewlibESP32Config()
libcDir = filepath.Join(baseDir, config.String())
compileConfig = libc.GetNewlibESP32CompileConfig(libcDir, target, mcpu)
2025-08-25 19:05:30 +08:00
default:
2025-09-04 19:08:48 +08:00
err = fmt.Errorf("unsupported libc: %s", libcName)
return
}
if needSkipDownload {
return libcDir, compileConfig, err
2025-08-25 19:05:30 +08:00
}
2025-09-04 19:08:48 +08:00
if err = checkDownloadAndExtractLib(config.Url, libcDir, config.ArchiveSrcDir); err != nil {
return
}
return libcDir, compileConfig, nil
2025-08-25 19:05:30 +08:00
}
2025-08-29 11:30:25 +08:00
2025-09-09 17:45:02 +08:00
// getRTCompileConfigByName retrieves runtime library compilation configuration by name
// Returns the actual libc output dir, compilation config and err
2025-09-04 19:08:48 +08:00
func getRTCompileConfigByName(baseDir, rtName, target string) (outputDir string, cfg compile.CompileConfig, err error) {
2025-08-29 11:30:25 +08:00
if rtName == "" {
2025-09-04 19:08:48 +08:00
err = fmt.Errorf("rt name cannot be empty")
return
2025-08-29 11:30:25 +08:00
}
2025-09-04 19:08:48 +08:00
var rtDir string
var config compile.LibConfig
var compileConfig compile.CompileConfig
2025-08-29 11:30:25 +08:00
switch rtName {
case "compiler-rt":
2025-09-04 19:08:48 +08:00
config = rtlib.GetCompilerRTConfig()
rtDir = filepath.Join(baseDir, config.String())
compileConfig = rtlib.GetCompilerRTCompileConfig(rtDir, target)
2025-08-29 11:30:25 +08:00
default:
2025-09-04 19:08:48 +08:00
err = fmt.Errorf("unsupported rt: %s", rtName)
2025-08-29 11:30:25 +08:00
}
2025-09-04 19:08:48 +08:00
if needSkipDownload {
return rtDir, compileConfig, err
}
if err = checkDownloadAndExtractLib(config.Url, rtDir, config.ArchiveSrcDir); err != nil {
return
}
return rtDir, compileConfig, nil
2025-08-29 11:30:25 +08:00
}