env:find crosscompile llvm

This commit is contained in:
luoliwoshang
2025-09-09 10:16:39 +08:00
parent 848432ea68
commit 68623f0b27
3 changed files with 17 additions and 8 deletions

View File

@@ -27,7 +27,6 @@ builds:
ldflags:
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=../crosscompile/clang/bin/llvm-config
env:
- CC=o64-clang
- CXX=o64-clang++
@@ -48,7 +47,6 @@ builds:
ldflags:
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=../crosscompile/clang/bin/llvm-config
env:
- CC=oa64-clang
- CXX=oa64-clang++
@@ -69,7 +67,6 @@ builds:
ldflags:
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=../crosscompile/clang/bin/llvm-config
env:
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
@@ -90,7 +87,6 @@ builds:
ldflags:
- -X github.com/goplus/llgo/internal/env.buildVersion=v{{.Version}}
- -X github.com/goplus/llgo/internal/env.buildTime={{.Date}}
- -X github.com/goplus/llgo/xtool/env/llvm.ldLLVMConfigBin=../crosscompile/clang/bin/llvm-config
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++

View File

@@ -15,6 +15,7 @@ import (
"github.com/goplus/llgo/internal/flash"
"github.com/goplus/llgo/internal/targets"
"github.com/goplus/llgo/internal/xtool/llvm"
envllvm "github.com/goplus/llgo/xtool/env/llvm"
)
type Export struct {
@@ -108,7 +109,7 @@ func getESPClangRoot(forceEspClang bool) (clangRoot string, err error) {
llgoRoot := env.LLGoROOT()
// First check if clang exists in LLGoROOT
espClangRoot := filepath.Join(llgoRoot, "crosscompile", "clang")
espClangRoot := filepath.Join(llgoRoot, envllvm.CrosscompileClangPath)
if _, err = os.Stat(espClangRoot); err == nil {
clangRoot = espClangRoot
return

View File

@@ -22,6 +22,7 @@ import (
"path/filepath"
"strings"
"github.com/goplus/llgo/internal/env"
"github.com/goplus/llgo/xtool/clang"
"github.com/goplus/llgo/xtool/llvm/install_name_tool"
"github.com/goplus/llgo/xtool/llvm/llvmlink"
@@ -30,9 +31,13 @@ import (
// -----------------------------------------------------------------------------
// defaultLLVMConfigBin returns the default path to the llvm-config binary. It
// checks the LLVM_CONFIG environment variable first, then searches in PATH. If
// not found, it returns [ldLLVMConfigBin] as a last resort.
const (
// CrosscompileClangPath is the relative path from LLGO_ROOT to the clang installation
CrosscompileClangPath = "crosscompile/clang"
)
// -----------------------------------------------------------------------------
func defaultLLVMConfigBin() string {
bin := os.Getenv("LLVM_CONFIG")
if bin != "" {
@@ -42,6 +47,13 @@ func defaultLLVMConfigBin() string {
if bin != "" {
return bin
}
llgoRoot := env.LLGoROOT()
// Check LLGO_ROOT/crosscompile/clang for llvm-config
crossLLVMConfigBin := filepath.Join(llgoRoot, CrosscompileClangPath, "bin", "llvm-config")
if _, err := os.Stat(crossLLVMConfigBin); err == nil {
return crossLLVMConfigBin
}
return ldLLVMConfigBin
}