chore: fix some wrong commets
This commit is contained in:
@@ -27,12 +27,16 @@ type CompileGroup struct {
|
|||||||
LDFlags []string // Linker flags
|
LDFlags []string // Linker flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCompiled checks if the compile group has already been compiled by verifying
|
||||||
|
// if the output archive file exists in the specified directory
|
||||||
func (g CompileGroup) IsCompiled(outputDir string) bool {
|
func (g CompileGroup) IsCompiled(outputDir string) bool {
|
||||||
archive := filepath.Join(outputDir, filepath.Base(g.OutputFileName))
|
archive := filepath.Join(outputDir, filepath.Base(g.OutputFileName))
|
||||||
_, err := os.Stat(archive)
|
_, err := os.Stat(archive)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compile compiles all source files in the group into a static library archive
|
||||||
|
// If the archive already exists, compilation is skipped
|
||||||
func (g CompileGroup) Compile(
|
func (g CompileGroup) Compile(
|
||||||
outputDir string, options CompileOptions,
|
outputDir string, options CompileOptions,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
@@ -101,11 +105,13 @@ type CompileConfig struct {
|
|||||||
|
|
||||||
type LibConfig struct {
|
type LibConfig struct {
|
||||||
Url string
|
Url string
|
||||||
Name string // compile name (e.g., "picolibc", "musl", "glibc")
|
Name string // Library name (e.g., "picolibc", "musl", "glibc")
|
||||||
Version string
|
Version string
|
||||||
ArchiveSrcDir string
|
ArchiveSrcDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a string representation of the library configuration
|
||||||
|
// in the format "name-version"
|
||||||
func (cfg LibConfig) String() string {
|
func (cfg LibConfig) String() string {
|
||||||
return fmt.Sprintf("%s-%s", cfg.Name, cfg.Version)
|
return fmt.Sprintf("%s-%s", cfg.Name, cfg.Version)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/goplus/llgo/xtool/nm"
|
"github.com/goplus/llgo/xtool/nm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsCompile(t *testing.T) {
|
func TestIsCompiled(t *testing.T) {
|
||||||
t.Run("IsCompile Not Exists", func(t *testing.T) {
|
t.Run("IsCompiled Not Exists", func(t *testing.T) {
|
||||||
cfg := CompileConfig{
|
cfg := CompileConfig{
|
||||||
Groups: []CompileGroup{
|
Groups: []CompileGroup{
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ func TestIsCompile(t *testing.T) {
|
|||||||
t.Errorf("unexpected result: should false")
|
t.Errorf("unexpected result: should false")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("IsCompile Exists", func(t *testing.T) {
|
t.Run("IsCompiled Exists", func(t *testing.T) {
|
||||||
tmpFile, err := os.CreateTemp("", "test*.a")
|
tmpFile, err := os.CreateTemp("", "test*.a")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ var _libcCCFlags = []string{
|
|||||||
"-ffreestanding",
|
"-ffreestanding",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// withDefaultCCFlags appends default C compiler flags to the provided flags
|
||||||
func withDefaultCCFlags(ccflags []string) []string {
|
func withDefaultCCFlags(ccflags []string) []string {
|
||||||
return append(ccflags, _libcCCFlags...)
|
return append(ccflags, _libcCCFlags...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNewlibESP32Config returns the configuration for downloading and building newlib for ESP32
|
||||||
func GetNewlibESP32Config() compile.LibConfig {
|
func GetNewlibESP32Config() compile.LibConfig {
|
||||||
return compile.LibConfig{
|
return compile.LibConfig{
|
||||||
Url: "https://github.com/goplus/newlib/archive/refs/tags/esp-4.3.0_20250211-patch3.tar.gz",
|
Url: "https://github.com/goplus/newlib/archive/refs/tags/esp-4.3.0_20250211-patch3.tar.gz",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/goplus/llgo/internal/crosscompile/compile"
|
"github.com/goplus/llgo/internal/crosscompile/compile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetPicolibcConfig returns the configuration for downloading and building picolibc
|
||||||
func GetPicolibcConfig() compile.LibConfig {
|
func GetPicolibcConfig() compile.LibConfig {
|
||||||
return compile.LibConfig{
|
return compile.LibConfig{
|
||||||
Name: "picolibc",
|
Name: "picolibc",
|
||||||
|
|||||||
@@ -167,10 +167,14 @@ func getESPClangPlatform(goos, goarch string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ldFlagsFromFileName extracts the library name from a filename for use in linker flags
|
||||||
|
// For example, "libmath.a" becomes "math" for use with "-lmath"
|
||||||
func ldFlagsFromFileName(fileName string) string {
|
func ldFlagsFromFileName(fileName string) string {
|
||||||
return strings.TrimPrefix(strings.TrimSuffix(fileName, ".a"), "lib")
|
return strings.TrimPrefix(strings.TrimSuffix(fileName, ".a"), "lib")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compileWithConfig compiles libraries according to the provided configuration
|
||||||
|
// and returns the necessary linker flags for linking against the compiled libraries
|
||||||
func compileWithConfig(
|
func compileWithConfig(
|
||||||
compileConfig compile.CompileConfig,
|
compileConfig compile.CompileConfig,
|
||||||
outputDir string, options compile.CompileOptions,
|
outputDir string, options compile.CompileOptions,
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ func TestUseCrossCompileSDK(t *testing.T) {
|
|||||||
name: "Same Platform",
|
name: "Same Platform",
|
||||||
goos: runtime.GOOS,
|
goos: runtime.GOOS,
|
||||||
goarch: runtime.GOARCH,
|
goarch: runtime.GOARCH,
|
||||||
expectSDK: true, // Changed: now we expect flags even for same platform
|
expectSDK: true, // We expect flags even for same platform
|
||||||
expectCCFlags: true, // Changed: CCFLAGS will contain sysroot
|
expectCCFlags: true, // CCFLAGS will contain sysroot
|
||||||
expectCFlags: false, // Changed: CFLAGS will not contain include paths
|
expectCFlags: false, // CFLAGS will not contain include paths
|
||||||
expectLDFlags: false, // Changed: LDFLAGS will not contain library paths
|
expectLDFlags: false, // LDFLAGS will not contain library paths
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WASM Target",
|
name: "WASM Target",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// for testing, in testing env, we use fake path, it will cause downloading failure
|
// for testing, in testing env, we use fake path, it will cause downloading failure
|
||||||
var needSkipDownload = false
|
var needSkipDownload = false
|
||||||
|
|
||||||
// GetCompileConfigByName retrieves libc compilation configuration by name
|
// getLibcCompileConfigByName retrieves libc compilation configuration by name
|
||||||
// Returns compilation file lists and corresponding cflags
|
// Returns compilation file lists and corresponding cflags
|
||||||
func getLibcCompileConfigByName(baseDir, libcName, target, mcpu string) (outputDir string, cfg compile.CompileConfig, err error) {
|
func getLibcCompileConfigByName(baseDir, libcName, target, mcpu string) (outputDir string, cfg compile.CompileConfig, err error) {
|
||||||
if libcName == "" {
|
if libcName == "" {
|
||||||
@@ -47,6 +47,8 @@ func getLibcCompileConfigByName(baseDir, libcName, target, mcpu string) (outputD
|
|||||||
return libcDir, compileConfig, nil
|
return libcDir, compileConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getRTCompileConfigByName retrieves runtime library compilation configuration by name
|
||||||
|
// Returns compilation file lists and corresponding flags for the specified runtime library
|
||||||
func getRTCompileConfigByName(baseDir, rtName, target string) (outputDir string, cfg compile.CompileConfig, err error) {
|
func getRTCompileConfigByName(baseDir, rtName, target string) (outputDir string, cfg compile.CompileConfig, err error) {
|
||||||
if rtName == "" {
|
if rtName == "" {
|
||||||
err = fmt.Errorf("rt name cannot be empty")
|
err = fmt.Errorf("rt name cannot be empty")
|
||||||
|
|||||||
Reference in New Issue
Block a user