diff --git a/cmd/fyne/internal/commands/build.go b/cmd/fyne/internal/commands/build.go index 0592ca515e..e0c9f46764 100644 --- a/cmd/fyne/internal/commands/build.go +++ b/cmd/fyne/internal/commands/build.go @@ -2,6 +2,7 @@ package commands import ( "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -173,6 +174,10 @@ func (b *Builder) build() error { goos = targetOS() } + if goos == "gopherjs" && runtime.GOOS == "windows" { + return errors.New("gopherjs doesn't support Windows. Only wasm target is supported for the web output. You can also use fyne-cross to solve this") + } + fyneGoModRunner := b.runner if b.runner == nil { fyneGoModRunner = newCommand("go") diff --git a/cmd/fyne/internal/commands/build_test.go b/cmd/fyne/internal/commands/build_test.go index 530b760bf4..5637602b20 100644 --- a/cmd/fyne/internal/commands/build_test.go +++ b/cmd/fyne/internal/commands/build_test.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "runtime" "testing" "github.com/mcuadros/go-version" @@ -164,39 +165,47 @@ func Test_BuildWasmReleaseVersion(t *testing.T) { } func Test_BuildGopherJSReleaseVersion(t *testing.T) { - expected := []mockRunner{ - { - expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, - mockReturn: mockReturn{ - ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"} }"), - }, - }, - { - expectedValue: expectedValue{ - args: []string{"version"}, - osEnv: true, - }, - mockReturn: mockReturn{ - ret: []byte(""), - err: nil, + expected := []mockRunner{} + + if runtime.GOOS != "windows" { + expected = []mockRunner{ + { + expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, + mockReturn: mockReturn{ + ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"} }"), + }, }, - }, - { - expectedValue: expectedValue{ - args: []string{"build", "--tags", "release"}, - osEnv: true, - dir: "myTest", + { + expectedValue: expectedValue{ + args: []string{"version"}, + osEnv: true, + }, + mockReturn: mockReturn{ + ret: []byte(""), + err: nil, + }, }, - mockReturn: mockReturn{ - ret: []byte(""), + { + expectedValue: expectedValue{ + args: []string{"build", "--tags", "release"}, + osEnv: true, + dir: "myTest", + }, + mockReturn: mockReturn{ + ret: []byte(""), + }, }, - }, + } } gopherJSBuildTest := &testCommandRuns{runs: expected, t: t} b := &Builder{appData: &appData{}, os: "gopherjs", srcdir: "myTest", release: true, runner: gopherJSBuildTest} err := b.build() - assert.Nil(t, err) + if runtime.GOOS == "windows" { + assert.NotNil(t, err) + } else { + assert.Nil(t, err) + } gopherJSBuildTest.verifyExpectation() } diff --git a/cmd/fyne/internal/commands/package.go b/cmd/fyne/internal/commands/package.go index 7bb6ec6f75..da5e1d79bd 100644 --- a/cmd/fyne/internal/commands/package.go +++ b/cmd/fyne/internal/commands/package.go @@ -11,6 +11,7 @@ import ( "log" "os" "path/filepath" + "runtime" "strconv" "strings" @@ -47,7 +48,7 @@ func Package() *cli.Command { &cli.StringFlag{ Name: "target", Aliases: []string{"os"}, - Usage: "The mobile platform to target (android, android/arm, android/arm64, android/amd64, android/386, ios, iossimulator).", + Usage: "The mobile platform to target (android, android/arm, android/arm64, android/amd64, android/386, ios, iossimulator, wasm, gopherjs, web).", Destination: &p.os, }, &cli.StringFlag{ @@ -229,6 +230,10 @@ func (p *Packager) buildPackage(runner runner) ([]string, error) { return nil, err } + if runtime.GOOS == "windows" { + return []string{bWasm.target}, nil + } + bGopherJS := &Builder{ os: "gopherjs", srcdir: p.srcDir, diff --git a/cmd/fyne/internal/commands/package_test.go b/cmd/fyne/internal/commands/package_test.go index be90b0625e..56a741ecb4 100644 --- a/cmd/fyne/internal/commands/package_test.go +++ b/cmd/fyne/internal/commands/package_test.go @@ -234,6 +234,9 @@ func Test_PackageWasm(t *testing.T) { } func Test_buildPackageGopherJS(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip() + } expected := []mockRunner{ { expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, @@ -292,6 +295,9 @@ func Test_buildPackageGopherJS(t *testing.T) { } func Test_PackageGopherJS(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip() + } expected := []mockRunner{ { expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, @@ -471,7 +477,11 @@ func Test_BuildPackageWeb(t *testing.T) { files, err := p.buildPackage(webBuildTest) assert.Nil(t, err) assert.NotNil(t, files) - assert.Equal(t, 2, len(files)) + expectedFiles := 2 + if runtime.GOOS == "windows" { + expectedFiles = 1 + } + assert.Equal(t, expectedFiles, len(files)) } func Test_PackageWeb(t *testing.T) { @@ -499,33 +509,38 @@ func Test_PackageWeb(t *testing.T) { ret: []byte(""), }, }, - { - expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, - mockReturn: mockReturn{ - ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"} }"), - }, - }, - { - expectedValue: expectedValue{ - args: []string{"version"}, - osEnv: true, - }, - mockReturn: mockReturn{ - ret: []byte(""), - err: nil, - }, - }, - { - expectedValue: expectedValue{ - args: []string{"build", - "-o", "myTest.js"}, - osEnv: true, - dir: "myTest", - }, - mockReturn: mockReturn{ - ret: []byte(""), - }, - }, + } + + if runtime.GOOS != "windows" { + expected = append(expected, []mockRunner{ + { + expectedValue: expectedValue{args: []string{"mod", "edit", "-json"}}, + mockReturn: mockReturn{ + ret: []byte("{ \"Module\": { \"Path\": \"fyne.io/fyne/v2\"} }"), + }, + }, + { + expectedValue: expectedValue{ + args: []string{"version"}, + osEnv: true, + }, + mockReturn: mockReturn{ + ret: []byte(""), + err: nil, + }, + }, + { + expectedValue: expectedValue{ + args: []string{"build", + "-o", "myTest.js"}, + osEnv: true, + dir: "myTest", + }, + mockReturn: mockReturn{ + ret: []byte(""), + }, + }, + }...) } p := &Packager{ diff --git a/cmd/fyne/internal/commands/serve.go b/cmd/fyne/internal/commands/serve.go index 7f7aab4caa..d954c0d1a3 100644 --- a/cmd/fyne/internal/commands/serve.go +++ b/cmd/fyne/internal/commands/serve.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net/http" + "runtime" "strconv" "github.com/urfave/cli/v2" @@ -20,6 +21,11 @@ type Server struct { func Serve() *cli.Command { s := &Server{appData: &appData{}} + target := "web" + if runtime.GOOS == "windows" { + target = "wasm" + } + return &cli.Command{ Name: "serve", Usage: "Package an application using WebAssembly and expose it via a web server.", @@ -46,7 +52,7 @@ func Serve() *cli.Command { Name: "target", Aliases: []string{"os"}, Usage: "The web runtime to target (wasm, gopherjs, web).", - Value: "web", + Value: target, Destination: &s.os, }, },