refine internal/clang: don't depends internal/crosscompile
This commit is contained in:
@@ -389,13 +389,27 @@ type context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) compiler() *clang.Cmd {
|
func (c *context) compiler() *clang.Cmd {
|
||||||
cmd := clang.NewCompiler(c.crossCompile)
|
config := clang.NewConfig(
|
||||||
|
c.crossCompile.CC,
|
||||||
|
c.crossCompile.CCFLAGS,
|
||||||
|
c.crossCompile.CFLAGS,
|
||||||
|
c.crossCompile.LDFLAGS,
|
||||||
|
c.crossCompile.Linker,
|
||||||
|
)
|
||||||
|
cmd := clang.NewCompiler(config)
|
||||||
cmd.Verbose = c.buildConf.Verbose
|
cmd.Verbose = c.buildConf.Verbose
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) linker() *clang.Cmd {
|
func (c *context) linker() *clang.Cmd {
|
||||||
cmd := clang.NewLinker(c.crossCompile)
|
config := clang.NewConfig(
|
||||||
|
c.crossCompile.CC,
|
||||||
|
c.crossCompile.CCFLAGS,
|
||||||
|
c.crossCompile.CFLAGS,
|
||||||
|
c.crossCompile.LDFLAGS,
|
||||||
|
c.crossCompile.Linker,
|
||||||
|
)
|
||||||
|
cmd := clang.NewLinker(config)
|
||||||
cmd.Verbose = c.buildConf.Verbose
|
cmd.Verbose = c.buildConf.Verbose
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,55 +24,74 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goplus/llgo/internal/crosscompile"
|
|
||||||
"github.com/goplus/llgo/xtool/safesplit"
|
"github.com/goplus/llgo/xtool/safesplit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cmd represents a clang command with environment and crosscompile support.
|
// Config represents clang configuration parameters.
|
||||||
type Cmd struct {
|
type Config struct {
|
||||||
app string
|
CC string // Compiler to use (e.g., "clang", "clang++")
|
||||||
Env []string
|
CCFLAGS []string // Compiler flags for C/C++ compilation
|
||||||
Verbose bool
|
CFLAGS []string // C-specific flags
|
||||||
Stdin io.Reader
|
LDFLAGS []string // Linker flags
|
||||||
Stdout io.Writer
|
Linker string // Linker to use (e.g., "ld.lld", "avr-ld")
|
||||||
Stderr io.Writer
|
|
||||||
crossCompile crosscompile.Export
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new clang command with crosscompile configuration.
|
// NewConfig creates a new Config with the specified parameters.
|
||||||
func New(app string, crossCompile crosscompile.Export) *Cmd {
|
func NewConfig(cc string, ccflags, cflags, ldflags []string, linker string) Config {
|
||||||
|
return Config{
|
||||||
|
CC: cc,
|
||||||
|
CCFLAGS: ccflags,
|
||||||
|
CFLAGS: cflags,
|
||||||
|
LDFLAGS: ldflags,
|
||||||
|
Linker: linker,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cmd represents a clang command with environment and configuration support.
|
||||||
|
type Cmd struct {
|
||||||
|
app string
|
||||||
|
config Config
|
||||||
|
Env []string
|
||||||
|
Verbose bool
|
||||||
|
Stdin io.Reader
|
||||||
|
Stdout io.Writer
|
||||||
|
Stderr io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new clang command with configuration.
|
||||||
|
func New(app string, config Config) *Cmd {
|
||||||
if app == "" {
|
if app == "" {
|
||||||
app = "clang"
|
app = "clang"
|
||||||
}
|
}
|
||||||
return &Cmd{
|
return &Cmd{
|
||||||
app: app,
|
app: app,
|
||||||
Env: nil,
|
config: config,
|
||||||
Verbose: false,
|
Env: nil,
|
||||||
Stdin: nil,
|
Verbose: false,
|
||||||
Stdout: os.Stdout,
|
Stdin: nil,
|
||||||
Stderr: os.Stderr,
|
Stdout: os.Stdout,
|
||||||
crossCompile: crossCompile,
|
Stderr: os.Stderr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCompiler creates a compiler command with proper flag merging.
|
// NewCompiler creates a compiler command with proper flag merging.
|
||||||
func NewCompiler(crossCompile crosscompile.Export) *Cmd {
|
func NewCompiler(config Config) *Cmd {
|
||||||
app := "clang"
|
app := "clang"
|
||||||
if crossCompile.CC != "" {
|
if config.CC != "" {
|
||||||
app = crossCompile.CC
|
app = config.CC
|
||||||
}
|
}
|
||||||
return New(app, crossCompile)
|
return New(app, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLinker creates a linker command with proper flag merging.
|
// NewLinker creates a linker command with proper flag merging.
|
||||||
func NewLinker(crossCompile crosscompile.Export) *Cmd {
|
func NewLinker(config Config) *Cmd {
|
||||||
app := "clang"
|
app := "clang"
|
||||||
if crossCompile.Linker != "" {
|
if config.Linker != "" {
|
||||||
app = crossCompile.Linker
|
app = config.Linker
|
||||||
} else if crossCompile.CC != "" {
|
} else if config.CC != "" {
|
||||||
app = crossCompile.CC
|
app = config.CC
|
||||||
}
|
}
|
||||||
return New(app, crossCompile)
|
return New(app, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile executes a compilation command with merged flags.
|
// Compile executes a compilation command with merged flags.
|
||||||
@@ -93,7 +112,7 @@ func (c *Cmd) Link(args ...string) error {
|
|||||||
return c.exec(allArgs...)
|
return c.exec(allArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeCompilerFlags merges environment CCFLAGS/CFLAGS with crossCompile flags.
|
// mergeCompilerFlags merges environment CCFLAGS/CFLAGS with config flags.
|
||||||
func (c *Cmd) mergeCompilerFlags() []string {
|
func (c *Cmd) mergeCompilerFlags() []string {
|
||||||
var flags []string
|
var flags []string
|
||||||
|
|
||||||
@@ -107,16 +126,16 @@ func (c *Cmd) mergeCompilerFlags() []string {
|
|||||||
flags = append(flags, safesplit.SplitPkgConfigFlags(envCFlags)...)
|
flags = append(flags, safesplit.SplitPkgConfigFlags(envCFlags)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add crossCompile CCFLAGS
|
// Add config CCFLAGS
|
||||||
flags = append(flags, c.crossCompile.CCFLAGS...)
|
flags = append(flags, c.config.CCFLAGS...)
|
||||||
|
|
||||||
// Add crossCompile CFLAGS
|
// Add config CFLAGS
|
||||||
flags = append(flags, c.crossCompile.CFLAGS...)
|
flags = append(flags, c.config.CFLAGS...)
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeLinkerFlags merges environment CCFLAGS/LDFLAGS with crossCompile flags.
|
// mergeLinkerFlags merges environment CCFLAGS/LDFLAGS with config flags.
|
||||||
func (c *Cmd) mergeLinkerFlags() []string {
|
func (c *Cmd) mergeLinkerFlags() []string {
|
||||||
var flags []string
|
var flags []string
|
||||||
|
|
||||||
@@ -130,8 +149,8 @@ func (c *Cmd) mergeLinkerFlags() []string {
|
|||||||
flags = append(flags, safesplit.SplitPkgConfigFlags(envLDFlags)...)
|
flags = append(flags, safesplit.SplitPkgConfigFlags(envLDFlags)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add crossCompile LDFLAGS
|
// Add config LDFLAGS
|
||||||
flags = append(flags, c.crossCompile.LDFLAGS...)
|
flags = append(flags, c.config.LDFLAGS...)
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user