From a5fd7f2eba8fbf7f3d0b7c41308bac42b753807f Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 19:31:50 +0800 Subject: [PATCH] internal/cl:include llvm-config --cflags to find libunwind.h --- internal/crosscompile/cosscompile.go | 6 ++++++ xtool/env/llvm/llvm.go | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/crosscompile/cosscompile.go b/internal/crosscompile/cosscompile.go index 8865aba6..cc4b15c6 100644 --- a/internal/crosscompile/cosscompile.go +++ b/internal/crosscompile/cosscompile.go @@ -6,9 +6,11 @@ import ( "os" "path/filepath" "runtime" + "strings" "github.com/goplus/llgo/internal/env" "github.com/goplus/llgo/internal/xtool/llvm" + envllvm "github.com/goplus/llgo/xtool/env/llvm" ) type Export struct { @@ -66,6 +68,10 @@ func Use(goos, goarch string, wasiThreads, changeRpath bool) (export Export, err "-latomic", "-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions. ) + llvmEnv := envllvm.New("") + if cflags := llvmEnv.Cflags(); cflags != "" { + export.CFLAGS = append(export.CFLAGS, strings.Fields(cflags)...) + } } return } diff --git a/xtool/env/llvm/llvm.go b/xtool/env/llvm/llvm.go index a34757c9..e1a18abd 100644 --- a/xtool/env/llvm/llvm.go +++ b/xtool/env/llvm/llvm.go @@ -50,6 +50,7 @@ func defaultLLVMConfigBin() string { // Env represents an LLVM installation. type Env struct { binDir string + cflags string } // New creates a new [Env] instance. @@ -62,7 +63,12 @@ func New(llvmConfigBin string) *Env { // executables are assumed to be in PATH. binDir, _ := exec.Command(llvmConfigBin, "--bindir").Output() - e := &Env{binDir: strings.TrimSpace(string(binDir))} + cflags, _ := exec.Command(llvmConfigBin, "--cflags").Output() + + e := &Env{ + binDir: strings.TrimSpace(string(binDir)), + cflags: strings.TrimSpace(string(cflags)), + } return e } @@ -70,6 +76,8 @@ func New(llvmConfigBin string) *Env { // means LLVM executables are assumed to be in PATH. func (e *Env) BinDir() string { return e.binDir } +func (e *Env) Cflags() string { return e.cflags } + // Clang returns a new [clang.Cmd] instance. func (e *Env) Clang() *clang.Cmd { bin := filepath.Join(e.BinDir(), "clang++")