Skip to content

Commit e021d89

Browse files
committed
main: parse extldflags early so we can report the error message
This avoids some weird behavior when the -extldflags flag cannot be parsed by TinyGo.
1 parent b8420e7 commit e021d89

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compileopts/config.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,7 @@ func (c *Config) LDFlags() []string {
406406
if c.Target.LinkerScript != "" {
407407
ldflags = append(ldflags, "-T", c.Target.LinkerScript)
408408
}
409-
410-
if c.Options.ExtLDFlags != "" {
411-
ext, err := shlex.Split(c.Options.ExtLDFlags)
412-
if err != nil {
413-
// if shlex can't split it, pass it as-is and let the external linker complain
414-
ext = []string{c.Options.ExtLDFlags}
415-
}
416-
ldflags = append(ldflags, ext...)
417-
}
409+
ldflags = append(ldflags, c.Options.ExtLDFlags...)
418410

419411
return ldflags
420412
}

compileopts/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type Options struct {
5858
Timeout time.Duration
5959
WITPackage string // pass through to wasm-tools component embed invocation
6060
WITWorld string // pass through to wasm-tools component embed -w option
61-
ExtLDFlags string
61+
ExtLDFlags []string
6262
}
6363

6464
// Verify performs a validation on the given options, raising an error if options are not valid.

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,12 +1639,19 @@ func main() {
16391639
Timeout: *timeout,
16401640
WITPackage: witPackage,
16411641
WITWorld: witWorld,
1642-
ExtLDFlags: extLDFlags,
16431642
}
16441643
if *printCommands {
16451644
options.PrintCommands = printCommand
16461645
}
16471646

1647+
if extLDFlags != "" {
1648+
options.ExtLDFlags, err = shlex.Split(extLDFlags)
1649+
if err != nil {
1650+
fmt.Fprintln(os.Stderr, "could not parse -extldflags:", err)
1651+
os.Exit(1)
1652+
}
1653+
}
1654+
16481655
err = options.Verify()
16491656
if err != nil {
16501657
fmt.Fprintln(os.Stderr, err.Error())

0 commit comments

Comments
 (0)