cmd/ebitnmobile: Bug fix: using ebitenmobile with EBITENMOBILE_GOMOBILE failed

Closes #1667
This commit is contained in:
Hajime Hoshi 2021-06-09 22:45:16 +09:00
parent 9cf30d9b70
commit cf1a91a344

View File

@ -102,14 +102,25 @@ func prepareGomobileCommands() error {
os.Chdir(pwd) os.Chdir(pwd)
}() }()
if err := runGo("mod", "init", "ebitenmobiletemporary"); err != nil { const modname = "ebitenmobiletemporary"
if err := runGo("mod", "init", modname); err != nil {
return err
}
if err := os.WriteFile("tools.go", []byte(fmt.Sprintf(`// +build tools
package %s
import (
_ "golang.org/x/mobile/cmd/gobind"
_ "golang.org/x/mobile/cmd/gomobile"
)
`, modname)), 0644); err != nil {
return err return err
} }
// To record gomobile to go.sum for Go 1.16 and later, go-get gomobile instaed of golang.org/x/mobile (#1487). // To record gomobile to go.sum for Go 1.16 and later, go-get gomobile instaed of golang.org/x/mobile (#1487).
// This also records gobind as gomobile depends on gobind indirectly. // This also records gobind as gomobile depends on gobind indirectly.
// Using `...` doesn't work on Windows since mobile/internal/mobileinit cannot be compiled on Windows w/o Cgo (#1493). // Using `...` doesn't work on Windows since mobile/internal/mobileinit cannot be compiled on Windows w/o Cgo (#1493).
// Note that `go mod tidy` doesn't work since this removes all the indirect imports.
if err := runGo("get", "golang.org/x/mobile/cmd/gomobile@"+gomobileHash); err != nil { if err := runGo("get", "golang.org/x/mobile/cmd/gomobile@"+gomobileHash); err != nil {
return err return err
} }
@ -121,6 +132,9 @@ func prepareGomobileCommands() error {
return err return err
} }
} }
if err := runGo("mod", "tidy"); err != nil {
return err
}
if err := runGo("build", "-o", exe(filepath.Join("bin", "gomobile")), "golang.org/x/mobile/cmd/gomobile"); err != nil { if err := runGo("build", "-o", exe(filepath.Join("bin", "gomobile")), "golang.org/x/mobile/cmd/gomobile"); err != nil {
return err return err
} }