-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
The Gio library contains a module (gioui.org/ui) for creating GUI programs in Go. For desktop platforms, running a Gio program is as easy as any other Go program, provided you have a few common system libraries and a C compiler installed:
$ go run gioui.org/apps/hello
Running Gio programs on Android, iOS and in the browser requires packaging several support files and meta data, so the Gio project includes the gogio
tool in the `gioui.org/cmd module to automate the tedious work.
Note that the gogio
tool is not general purpose: it is intrinsically bound to the gioui.org/ui module. Similar examples are the gobind
and gomobile
tools from the Gomobile project.
This issue is about providing an easy and portable way to run such support tools.
In #33468 I described a possible solution in terms of go run
because go run
is very close to what I want. This is the simple and portable one-liner for creating an Android app for a Gio program:
$ go run gioui.org/cmd/gogio -target android gioui.org/apps/gophers
Unfortunately, according to #33468 (comment), #25416 and #25416 (comment), it is almost accidental that go run
can run the above one-liner.
go install
@bcmills brings up the usual way to use Go tools: go install
and setting up $PATH to run them:
You could give separate instructions for cmd.exe and for Unix-like shells. Or assume that they have their PATH configured appropriately (perhaps by reference to some other document) and tell everyone:
go install gioui.org/cmd/gogio
gio -target android gioui.org/apps/gophers
However, setting up PATH is not portable and not nearly as simple as go run
, in particular for Windows users.
Case in point: go env
can now set environment variables for the Go tool because (#30411)
Setting environment variables for go command configuration
is too difficult and system-specific.
go build
#25416 (comment) suggests
$ go build -o /some/dir/gogio gioui.org/cmd/gogio
$ /some/dir/gogio ...
which doesn't depend on the environment, but still more awkward than just go run
.
(Some) Solutions
- Let
go run
be the way to conveniently run Go commands without fiddling with the environment. cmd/go: speed up 'go run' by caching binaries #33468 is about speeding upgo run
so that it is (nearly) as fast as running ago install
'ed binary.go run
is also the only way to get reproducible builds; see proposal: cmd/go: provide a portable and simple way to run SDK-like Go tools #33518 (comment). - Set up the user's environment when installing Go so that
go install
'ed programs are guaranteed to be in PATH. - As a variant to the above, provide a portable and simple way to run a
go install
'ed binary that doesn't depend on the environment.