Skip to content

Commit

Permalink
main: parse extldflags early so we can report the error message
Browse files Browse the repository at this point in the history
This avoids some weird behavior when the -extldflags flag cannot be
parsed by TinyGo.
  • Loading branch information
aykevl committed Oct 25, 2024
1 parent b8420e7 commit e021d89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 1 addition & 9 deletions compileopts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,7 @@ func (c *Config) LDFlags() []string {
if c.Target.LinkerScript != "" {
ldflags = append(ldflags, "-T", c.Target.LinkerScript)
}

if c.Options.ExtLDFlags != "" {
ext, err := shlex.Split(c.Options.ExtLDFlags)
if err != nil {
// if shlex can't split it, pass it as-is and let the external linker complain
ext = []string{c.Options.ExtLDFlags}
}
ldflags = append(ldflags, ext...)
}
ldflags = append(ldflags, c.Options.ExtLDFlags...)

return ldflags
}
Expand Down
2 changes: 1 addition & 1 deletion compileopts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Options struct {
Timeout time.Duration
WITPackage string // pass through to wasm-tools component embed invocation
WITWorld string // pass through to wasm-tools component embed -w option
ExtLDFlags string
ExtLDFlags []string
}

// Verify performs a validation on the given options, raising an error if options are not valid.
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1639,12 +1639,19 @@ func main() {
Timeout: *timeout,
WITPackage: witPackage,
WITWorld: witWorld,
ExtLDFlags: extLDFlags,
}
if *printCommands {
options.PrintCommands = printCommand
}

if extLDFlags != "" {
options.ExtLDFlags, err = shlex.Split(extLDFlags)
if err != nil {
fmt.Fprintln(os.Stderr, "could not parse -extldflags:", err)
os.Exit(1)
}
}

err = options.Verify()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand Down

0 comments on commit e021d89

Please sign in to comment.