Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cmd/internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
27 changes: 25 additions & 2 deletions cmd/internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flags
import (
"flag"

"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/buildenv"
)

Expand All @@ -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")
Expand All @@ -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")
}
}

Expand All @@ -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
}
}
4 changes: 1 addition & 3 deletions cmd/internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions cmd/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions cmd/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 25 additions & 38 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,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 {
Expand Down Expand Up @@ -277,14 +279,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)
Expand Down Expand Up @@ -374,9 +374,6 @@ type context struct {
nLibdir int
output bool

isCheckEnabled bool
isCheckLinkArgsEnabled bool

needRt map[*packages.Package]bool
needPyInit map[*packages.Package]bool

Expand Down Expand Up @@ -476,7 +473,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))
}
Expand Down Expand Up @@ -868,7 +865,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)
}
Expand Down Expand Up @@ -1010,11 +1007,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"
Expand Down Expand Up @@ -1055,18 +1050,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)
}
Expand Down
Loading