Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/windows gopherjs #3327

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -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")
Expand Down
59 changes: 34 additions & 25 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"runtime"
"testing"

"github.com/mcuadros/go-version"
Expand Down Expand Up @@ -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()
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down
71 changes: 43 additions & 28 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down Expand Up @@ -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"}},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 7 additions & 1 deletion cmd/fyne/internal/commands/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"runtime"
"strconv"

"github.com/urfave/cli/v2"
Expand All @@ -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.",
Expand All @@ -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,
},
},
Expand Down