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

@@ -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
}