Merge commit '7de4137d4678a3bcbd735f887028489f97f1e479' into embed-cmds
# Conflicts: # internal/build/build.go
This commit is contained in:
@@ -104,7 +104,7 @@ func getMacOSSysroot() (string, error) {
|
||||
|
||||
// getESPClangRoot returns the ESP Clang root directory, checking LLGoROOT first,
|
||||
// then downloading if needed and platform is supported
|
||||
func getESPClangRoot() (clangRoot string, err error) {
|
||||
func getESPClangRoot(forceEspClang bool) (clangRoot string, err error) {
|
||||
llgoRoot := env.LLGoROOT()
|
||||
|
||||
// First check if clang exists in LLGoROOT
|
||||
@@ -114,6 +114,10 @@ func getESPClangRoot() (clangRoot string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if !forceEspClang {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Try to download ESP Clang if platform is supported
|
||||
platformSuffix := getESPClangPlatform(runtime.GOOS, runtime.GOARCH)
|
||||
if platformSuffix != "" {
|
||||
@@ -192,52 +196,57 @@ func getOrCompileWithConfig(
|
||||
return
|
||||
}
|
||||
|
||||
func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
||||
func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, err error) {
|
||||
targetTriple := llvm.GetTargetTriple(goos, goarch)
|
||||
llgoRoot := env.LLGoROOT()
|
||||
|
||||
// Check for ESP Clang support for target-based builds
|
||||
clangRoot, err := getESPClangRoot()
|
||||
clangRoot, err := getESPClangRoot(forceEspClang)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Set ClangRoot and CC if clang is available
|
||||
export.ClangRoot = clangRoot
|
||||
export.CC = filepath.Join(clangRoot, "bin", "clang++")
|
||||
if clangRoot != "" {
|
||||
export.CC = filepath.Join(clangRoot, "bin", "clang++")
|
||||
} else {
|
||||
export.CC = "clang++"
|
||||
}
|
||||
|
||||
if runtime.GOOS == goos && runtime.GOARCH == goarch {
|
||||
clangLib := filepath.Join(clangRoot, "lib")
|
||||
clangInc := filepath.Join(clangRoot, "include")
|
||||
// not cross compile
|
||||
// Set up basic flags for non-cross-compile
|
||||
export.LDFLAGS = []string{
|
||||
"-L" + clangLib,
|
||||
"-target", targetTriple,
|
||||
"-Qunused-arguments",
|
||||
"-Wno-unused-command-line-argument",
|
||||
"-Wl,--error-limit=0",
|
||||
"-fuse-ld=lld",
|
||||
}
|
||||
export.CFLAGS = append(export.CFLAGS, "-I"+clangInc)
|
||||
if clangRoot != "" {
|
||||
clangLib := filepath.Join(clangRoot, "lib")
|
||||
clangInc := filepath.Join(clangRoot, "include")
|
||||
export.CFLAGS = append(export.CFLAGS, "-I"+clangInc)
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-L"+clangLib)
|
||||
// Add platform-specific rpath flags
|
||||
switch goos {
|
||||
case "darwin":
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
case "linux":
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
case "windows":
|
||||
// Windows doesn't support rpath, DLLs should be in PATH or same directory
|
||||
default:
|
||||
// For other Unix-like systems, try the generic rpath
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
}
|
||||
}
|
||||
export.CCFLAGS = []string{
|
||||
"-Qunused-arguments",
|
||||
"-Wno-unused-command-line-argument",
|
||||
}
|
||||
|
||||
// Add platform-specific rpath flags
|
||||
switch goos {
|
||||
case "darwin":
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
case "linux":
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
case "windows":
|
||||
// Windows doesn't support rpath, DLLs should be in PATH or same directory
|
||||
default:
|
||||
// For other Unix-like systems, try the generic rpath
|
||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||
}
|
||||
|
||||
// Add sysroot for macOS only
|
||||
if goos == "darwin" {
|
||||
sysrootPath, sysrootErr := getMacOSSysroot()
|
||||
@@ -272,7 +281,9 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
||||
"--gc-sections",
|
||||
"-lm",
|
||||
"-latomic",
|
||||
"-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
|
||||
// libpthread & libdl is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
|
||||
"-lpthread",
|
||||
"-ldl",
|
||||
)
|
||||
}
|
||||
return
|
||||
@@ -429,7 +440,7 @@ func UseTarget(targetName string) (export Export, err error) {
|
||||
}
|
||||
|
||||
// Check for ESP Clang support for target-based builds
|
||||
clangRoot, err := getESPClangRoot()
|
||||
clangRoot, err := getESPClangRoot(true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -634,9 +645,9 @@ func UseTarget(targetName string) (export Export, err error) {
|
||||
|
||||
// Use extends the original Use function to support target-based configuration
|
||||
// If targetName is provided, it takes precedence over goos/goarch
|
||||
func Use(goos, goarch string, wasiThreads bool, targetName string) (export Export, err error) {
|
||||
func Use(goos, goarch, targetName string, wasiThreads, forceEspClang bool) (export Export, err error) {
|
||||
if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") {
|
||||
return UseTarget(targetName)
|
||||
}
|
||||
return use(goos, goarch, wasiThreads)
|
||||
return use(goos, goarch, wasiThreads, forceEspClang)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user