Skip to content

Commit 48f145c

Browse files
aykevldeadprogram
authored andcommitted
compileopts: enable support for GOARCH=wasm in tinygo test
Support for GOARCH=wasm was only available for `tinygo build`, not for any of the other subcommands (`test`, `run`, etc). With this PR, these subcommands should work again for supported values of GOOS. This fixes the following error for example: $ make tinygo-test-wasip1 GOOS=wasip1 GOARCH=wasm /home/ayke/bin/tinygo test cmp compress/lzw compress/zlib [...etc] cannot resolve packages: GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2. make: *** [GNUmakefile:489: tinygo-test-wasip1] Error 1
1 parent 5a34c64 commit 48f145c

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

compileopts/target.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ func (spec *TargetSpec) resolveInherits() error {
178178

179179
// Load a target specification.
180180
func LoadTarget(options *Options) (*TargetSpec, error) {
181+
if options.Target == "" && options.GOARCH == "wasm" {
182+
// Set a specific target if we're building from a known GOOS/GOARCH
183+
// combination that is defined in a target JSON file.
184+
switch options.GOOS {
185+
case "js":
186+
options.Target = "wasm"
187+
case "wasip1":
188+
options.Target = "wasip1"
189+
case "wasip2":
190+
options.Target = "wasip2"
191+
default:
192+
return nil, errors.New("GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
193+
}
194+
}
195+
181196
if options.Target == "" {
182197
return defaultTarget(options)
183198
}

main.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,24 +1684,9 @@ func main() {
16841684
usage(command)
16851685
os.Exit(1)
16861686
}
1687-
if options.Target == "" {
1688-
switch {
1689-
case options.GOARCH == "wasm":
1690-
switch options.GOOS {
1691-
case "js":
1692-
options.Target = "wasm"
1693-
case "wasip1":
1694-
options.Target = "wasip1"
1695-
case "wasip2":
1696-
options.Target = "wasip2"
1697-
default:
1698-
fmt.Fprintln(os.Stderr, "GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
1699-
os.Exit(1)
1700-
}
1701-
case filepath.Ext(outpath) == ".wasm":
1702-
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
1703-
os.Exit(1)
1704-
}
1687+
if filepath.Ext(outpath) == ".wasm" && options.GOARCH != "wasm" && options.Target == "" {
1688+
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
1689+
os.Exit(1)
17051690
}
17061691

17071692
err := Build(pkgName, outpath, options)

0 commit comments

Comments
 (0)