Merge pull request #1228 from visualfc/dev_check

build: dev support checkLinkArgs/CheckLLFiles/GenLLFiles
This commit is contained in:
xushiwei
2025-08-24 08:42:38 +08:00
committed by GitHub
6 changed files with 54 additions and 57 deletions

View File

@@ -47,11 +47,7 @@ func runCmd(cmd *base.Command, args []string) {
}
conf := build.NewDefaultConf(build.ModeBuild)
conf.Tags = flags.Tags
conf.Verbose = flags.Verbose
conf.OutFile = flags.OutputFile
conf.Target = flags.Target
conf.AbiMode = build.AbiMode(flags.AbiMode)
flags.UpdateConfig(conf)
args = cmd.Flag.Args()

View File

@@ -3,6 +3,7 @@ package flags
import (
"flag"
"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/buildenv"
)
@@ -17,6 +18,9 @@ var BuildEnv string
var Tags string
var Target string
var AbiMode int
var CheckLinkArgs bool
var CheckLLFiles bool
var GenLLFiles bool
func AddBuildFlags(fs *flag.FlagSet) {
fs.BoolVar(&Verbose, "v", false, "Verbose mode")
@@ -25,8 +29,9 @@ func AddBuildFlags(fs *flag.FlagSet) {
fs.StringVar(&Target, "target", "", "Target platform (e.g., rp2040, wasi)")
if buildenv.Dev {
fs.IntVar(&AbiMode, "abi", 2, "ABI mode (default 2). 0 = none, 1 = cfunc, 2 = allfunc.")
} else {
AbiMode = 2
fs.BoolVar(&CheckLinkArgs, "check-linkargs", false, "check link args valid")
fs.BoolVar(&CheckLLFiles, "check-llfiles", false, "check .ll files valid")
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
}
}
@@ -35,3 +40,21 @@ var Gen bool
func AddCmpTestFlags(fs *flag.FlagSet) {
fs.BoolVar(&Gen, "gen", false, "Generate llgo.expect file")
}
func UpdateConfig(conf *build.Config) {
conf.Tags = Tags
conf.Verbose = Verbose
conf.Target = Target
switch conf.Mode {
case build.ModeBuild:
conf.OutFile = OutputFile
case build.ModeCmpTest:
conf.GenExpect = Gen
}
if buildenv.Dev {
conf.AbiMode = build.AbiMode(AbiMode)
conf.CheckLinkArgs = CheckLinkArgs
conf.CheckLLFiles = CheckLLFiles
conf.GenLL = GenLLFiles
}
}

View File

@@ -45,9 +45,7 @@ func runCmd(cmd *base.Command, args []string) {
}
conf := build.NewDefaultConf(build.ModeInstall)
conf.Tags = flags.Tags
conf.Verbose = flags.Verbose
conf.AbiMode = build.AbiMode(flags.AbiMode)
flags.UpdateConfig(conf)
args = cmd.Flag.Args()
_, err := build.Do(args, conf)

View File

@@ -68,11 +68,7 @@ func runCmdEx(cmd *base.Command, args []string, mode build.Mode) {
}
conf := build.NewDefaultConf(mode)
conf.Tags = flags.Tags
conf.Verbose = flags.Verbose
conf.GenExpect = flags.Gen
conf.Target = flags.Target
conf.AbiMode = build.AbiMode(flags.AbiMode)
flags.UpdateConfig(conf)
args = cmd.Flag.Args()
args, runArgs, err := parseRunArgs(args)

View File

@@ -27,10 +27,7 @@ func runCmd(cmd *base.Command, args []string) {
}
conf := build.NewDefaultConf(build.ModeTest)
conf.Tags = flags.Tags
conf.Verbose = flags.Verbose
conf.Target = flags.Target
conf.AbiMode = build.AbiMode(flags.AbiMode)
flags.UpdateConfig(conf)
args = cmd.Flag.Args()
_, err := build.Do(args, conf)

View File

@@ -72,21 +72,23 @@ const (
)
type Config struct {
Goos string
Goarch string
Target string // target name (e.g., "rp2040", "wasi") - takes precedence over Goos/Goarch
BinPath string
AppExt string // ".exe" on Windows, empty on Unix
OutFile string // only valid for ModeBuild when len(pkgs) == 1
RunArgs []string // only valid for ModeRun
Mode Mode
AbiMode AbiMode
GenExpect bool // only valid for ModeCmpTest
Verbose bool
GenLL bool // generate pkg .ll files
Tags string
GlobalNames map[string][]string // pkg => names
GlobalDatas map[string]string // pkg.name => data
Goos string
Goarch string
Target string // target name (e.g., "rp2040", "wasi") - takes precedence over Goos/Goarch
BinPath string
AppExt string // ".exe" on Windows, empty on Unix
OutFile string // only valid for ModeBuild when len(pkgs) == 1
RunArgs []string // only valid for ModeRun
Mode Mode
AbiMode AbiMode
GenExpect bool // only valid for ModeCmpTest
Verbose bool
GenLL bool // generate pkg .ll files
CheckLLFiles bool // check .ll files valid
CheckLinkArgs bool // check linkargs valid
Tags string
GlobalNames map[string][]string // pkg => names
GlobalDatas map[string]string // pkg.name => data
}
func NewDefaultConf(mode Mode) *Config {
@@ -278,14 +280,12 @@ func Do(args []string, conf *Config) ([]Package, error) {
output := conf.OutFile != ""
ctx := &context{env: env, conf: cfg, progSSA: progSSA, prog: prog, dedup: dedup,
patches: patches, built: make(map[string]none), initial: initial, mode: mode,
output: output,
needRt: make(map[*packages.Package]bool),
needPyInit: make(map[*packages.Package]bool),
buildConf: conf,
crossCompile: export,
isCheckEnabled: IsCheckEnabled(),
isCheckLinkArgsEnabled: IsCheckLinkArgsEnabled(),
cTransformer: cabi.NewTransformer(prog, conf.AbiMode),
output: output,
needRt: make(map[*packages.Package]bool),
needPyInit: make(map[*packages.Package]bool),
buildConf: conf,
crossCompile: export,
cTransformer: cabi.NewTransformer(prog, conf.AbiMode),
}
pkgs, err := buildAllPkgs(ctx, initial, verbose)
check(err)
@@ -375,9 +375,6 @@ type context struct {
nLibdir int
output bool
isCheckEnabled bool
isCheckLinkArgsEnabled bool
needRt map[*packages.Package]bool
needPyInit map[*packages.Package]bool
@@ -485,7 +482,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs
ctx.nLibdir++
}
}
if ctx.isCheckLinkArgsEnabled {
if ctx.buildConf.CheckLinkArgs {
if err := ctx.compiler().CheckLinkArgs(pkgLinkArgs, isWasmTarget(ctx.buildConf.Goos)); err != nil {
panic(fmt.Sprintf("test link args '%s' failed\n\texpanded to: %v\n\tresolved to: %v\n\terror: %v", param, expdArgs, pkgLinkArgs, err))
}
@@ -1022,7 +1019,7 @@ func exportObject(ctx *context, pkgPath string, exportFile string, data []byte)
if err != nil {
return exportFile, err
}
if ctx.isCheckEnabled {
if ctx.buildConf.CheckLLFiles {
if msg, err := llcCheck(ctx.env, f.Name()); err != nil {
fmt.Fprintf(os.Stderr, "==> lcc %v: %v\n%v\n", pkgPath, f.Name(), msg)
}
@@ -1162,11 +1159,9 @@ const llgoDebug = "LLGO_DEBUG"
const llgoDbgSyms = "LLGO_DEBUG_SYMBOLS"
const llgoTrace = "LLGO_TRACE"
const llgoOptimize = "LLGO_OPTIMIZE"
const llgoCheck = "LLGO_CHECK"
const llgoWasmRuntime = "LLGO_WASM_RUNTIME"
const llgoWasiThreads = "LLGO_WASI_THREADS"
const llgoStdioNobuf = "LLGO_STDIO_NOBUF"
const llgoCheckLinkArgs = "LLGO_CHECK_LINKARGS"
const llgoFullRpath = "LLGO_FULL_RPATH"
const defaultWasmRuntime = "wasmtime"
@@ -1207,18 +1202,10 @@ func IsOptimizeEnabled() bool {
return isEnvOn(llgoOptimize, true)
}
func IsCheckEnabled() bool {
return isEnvOn(llgoCheck, false)
}
func IsWasiThreadsEnabled() bool {
return isEnvOn(llgoWasiThreads, true)
}
func IsCheckLinkArgsEnabled() bool {
return isEnvOn(llgoCheckLinkArgs, false)
}
func IsFullRpathEnabled() bool {
return isEnvOn(llgoFullRpath, true)
}