Skip to content

Commit 058f62a

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 4e49ba5 commit 058f62a

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
@@ -1641,12 +1641,19 @@ func main() {
16411641
Timeout: *timeout,
16421642
WITPackage: witPackage,
16431643
WITWorld: witWorld,
1644-
ExtLDFlags: extLDFlags,
16451644
}
16461645
if *printCommands {
16471646
options.PrintCommands = printCommand
16481647
}
16491648

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

0 commit comments

Comments
 (0)