feat: add target name design
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package libc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/goplus/llgo/internal/crosscompile/compile"
|
||||
)
|
||||
|
||||
// getNewlibESP32Config returns configuration for newlib esp32
|
||||
func GetNewlibESP32Config(baseDir, arch string) *compile.CompileConfig {
|
||||
func GetNewlibESP32Config(baseDir, target string) *compile.CompileConfig {
|
||||
libcDir := filepath.Join(baseDir, "newlib", "libc")
|
||||
|
||||
return &compile.CompileConfig{
|
||||
@@ -15,7 +16,7 @@ func GetNewlibESP32Config(baseDir, arch string) *compile.CompileConfig {
|
||||
Name: "newlib-esp32",
|
||||
Groups: []compile.CompileGroup{
|
||||
{
|
||||
OutputFileName: "libcrt0.a",
|
||||
OutputFileName: fmt.Sprintf("libcrt0-%s.a", target),
|
||||
Files: []string{
|
||||
filepath.Join(baseDir, "libgloss", "xtensa", "clibrary_init.c"),
|
||||
filepath.Join(baseDir, "libgloss", "xtensa", "syscalls.c"),
|
||||
@@ -39,7 +40,7 @@ func GetNewlibESP32Config(baseDir, arch string) *compile.CompileConfig {
|
||||
},
|
||||
},
|
||||
{
|
||||
OutputFileName: "libgloss.a",
|
||||
OutputFileName: fmt.Sprintf("libgloss-%s.a", target),
|
||||
Files: []string{
|
||||
filepath.Join(baseDir, "libgloss", "libnosys", "chown.c"),
|
||||
filepath.Join(baseDir, "libgloss", "libnosys", "close.c"),
|
||||
@@ -236,7 +237,7 @@ func GetNewlibESP32Config(baseDir, arch string) *compile.CompileConfig {
|
||||
},
|
||||
},
|
||||
{
|
||||
OutputFileName: "libc.a",
|
||||
OutputFileName: fmt.Sprintf("libc-%s.a", target),
|
||||
Files: []string{
|
||||
filepath.Join(libcDir, "argz", "argz_add.c"),
|
||||
filepath.Join(libcDir, "argz", "argz_add_sep.c"),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package libc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -8,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// getPicolibcConfig returns configuration for picolibc
|
||||
func GetPicolibcConfig(baseDir string) *compile.CompileConfig {
|
||||
func GetPicolibcConfig(baseDir, target string) *compile.CompileConfig {
|
||||
libcIncludeDir := filepath.Join(baseDir, "libc", "include")
|
||||
libmIncludeDir := filepath.Join(baseDir, "libm", "common")
|
||||
localeIncludeDir := filepath.Join(baseDir, "libc", "locale")
|
||||
@@ -23,7 +24,7 @@ func GetPicolibcConfig(baseDir string) *compile.CompileConfig {
|
||||
Name: "picolibc",
|
||||
Groups: []compile.CompileGroup{
|
||||
{
|
||||
OutputFileName: "libc.a",
|
||||
OutputFileName: fmt.Sprintf("libc-%s.a", target),
|
||||
Files: []string{
|
||||
filepath.Join(baseDir, "libc", "string", "bcmp.c"),
|
||||
filepath.Join(baseDir, "libc", "string", "bcopy.c"),
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package rtlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/goplus/llgo/internal/crosscompile/compile"
|
||||
)
|
||||
|
||||
func GetCompilerRTConfig(baseDir, arch string) *compile.CompileConfig {
|
||||
func GetCompilerRTConfig(baseDir, target string) *compile.CompileConfig {
|
||||
return &compile.CompileConfig{
|
||||
Url: "https://github.com/goplus/compiler-rt/archive/refs/tags/v0.1.0.tar.gz",
|
||||
ArchiveSrcDir: "compiler-rt-0.1.0",
|
||||
Groups: []compile.CompileGroup{
|
||||
{
|
||||
OutputFileName: "libclang_builtins.a",
|
||||
OutputFileName: fmt.Sprintf("libclang_builtins-%s.a", target),
|
||||
Files: []string{
|
||||
filepath.Join(baseDir, "lib", "builtins", "xtensa/ieee754_sqrtf.S"),
|
||||
filepath.Join(baseDir, "lib", "builtins", "absvdi2.c"),
|
||||
|
||||
@@ -227,7 +227,6 @@ func getOrCompileWithConfig(
|
||||
exportCCFlags, exportLDFlags []string,
|
||||
) (ldflags []string, err error) {
|
||||
if err = checkDownloadAndExtractLib(
|
||||
compileConfig,
|
||||
compileConfig.Url, outputDir,
|
||||
compileConfig.ArchiveSrcDir,
|
||||
); err != nil {
|
||||
@@ -613,7 +612,7 @@ func useTarget(targetName string) (export Export, err error) {
|
||||
baseDir := filepath.Join(cacheRoot(), "crosscompile")
|
||||
outputDir := filepath.Join(baseDir, config.Libc)
|
||||
|
||||
compileConfig, err = getLibcCompileConfigByName(baseDir, config.Libc)
|
||||
compileConfig, err = getLibcCompileConfigByName(baseDir, config.Libc, config.LLVMTarget)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -632,7 +631,7 @@ func useTarget(targetName string) (export Export, err error) {
|
||||
baseDir := filepath.Join(cacheRoot(), "crosscompile")
|
||||
outputDir := filepath.Join(baseDir, config.RTLib)
|
||||
|
||||
compileConfig, err = getRTCompileConfigByName(baseDir, config.RTLib)
|
||||
compileConfig, err = getRTCompileConfigByName(baseDir, config.RTLib, config.LLVMTarget)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/goplus/llgo/internal/crosscompile/compile"
|
||||
)
|
||||
|
||||
// checkDownloadAndExtractWasiSDK downloads and extracts WASI SDK
|
||||
@@ -82,9 +80,9 @@ func checkDownloadAndExtractESPClang(platformSuffix, dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkDownloadAndExtractLib(cfg *compile.CompileConfig, url, dstDir, internalArchiveSrcDir string) error {
|
||||
func checkDownloadAndExtractLib(url, dstDir, internalArchiveSrcDir string) error {
|
||||
// Check if already exists
|
||||
if cfg.IsCompiled(dstDir) {
|
||||
if _, err := os.Stat(dstDir); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -97,7 +95,7 @@ func checkDownloadAndExtractLib(cfg *compile.CompileConfig, url, dstDir, interna
|
||||
defer releaseLock(lockFile)
|
||||
|
||||
// Double-check after acquiring lock
|
||||
if cfg.IsCompiled(dstDir) {
|
||||
if _, err := os.Stat(dstDir); err == nil {
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%s not found in LLGO_ROOT or cache, will download and compile.\n", dstDir)
|
||||
@@ -117,10 +115,7 @@ func checkDownloadAndExtractLib(cfg *compile.CompileConfig, url, dstDir, interna
|
||||
srcDir = filepath.Join(tempExtractDir, internalArchiveSrcDir)
|
||||
}
|
||||
|
||||
os.RemoveAll(dstDir)
|
||||
if err := os.Rename(srcDir, dstDir); err != nil {
|
||||
return fmt.Errorf("failed to rename libc directory: %w", err)
|
||||
}
|
||||
os.Rename(srcDir, dstDir)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// GetCompileConfigByName retrieves libc compilation configuration by name
|
||||
// Returns compilation file lists and corresponding cflags
|
||||
func getLibcCompileConfigByName(baseDir, libcName string) (*compile.CompileConfig, error) {
|
||||
func getLibcCompileConfigByName(baseDir, libcName, target string) (*compile.CompileConfig, error) {
|
||||
if libcName == "" {
|
||||
return nil, fmt.Errorf("libc name cannot be empty")
|
||||
}
|
||||
@@ -19,15 +19,15 @@ func getLibcCompileConfigByName(baseDir, libcName string) (*compile.CompileConfi
|
||||
|
||||
switch libcName {
|
||||
case "picolibc":
|
||||
return libc.GetPicolibcConfig(libcDir), nil
|
||||
return libc.GetPicolibcConfig(libcDir, target), nil
|
||||
case "newlib-esp32":
|
||||
return libc.GetNewlibESP32Config(libcDir, "xtensa"), nil
|
||||
return libc.GetNewlibESP32Config(libcDir, target), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported libc: %s", libcName)
|
||||
}
|
||||
}
|
||||
|
||||
func getRTCompileConfigByName(baseDir, rtName string) (*compile.CompileConfig, error) {
|
||||
func getRTCompileConfigByName(baseDir, rtName, target string) (*compile.CompileConfig, error) {
|
||||
if rtName == "" {
|
||||
return nil, fmt.Errorf("rt name cannot be empty")
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func getRTCompileConfigByName(baseDir, rtName string) (*compile.CompileConfig, e
|
||||
|
||||
switch rtName {
|
||||
case "compiler-rt":
|
||||
return rtlib.GetCompilerRTConfig(rtDir, "xtensa"), nil
|
||||
return rtlib.GetCompilerRTConfig(rtDir, target), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported rt: %s", rtName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user