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