goplus / gop

The Go+ programming language is designed for engineering, STEM education, and data science
https://goplus.org
Apache License 2.0
8.89k stars 547 forks source link

select Go compiler in `go.mod` #1914

Closed xushiwei closed 3 weeks ago

xushiwei commented 3 weeks ago

By default Go+ use go command as the underlying compiler tool. But in many case we want use llgo or tinygo command as the underlying compiler tool.

For now, we can select llgo or tinygo by using the environment variable GOP_GOCMD. For example:

GOP_GOCMD=llgo gop run .     # or:
GOP_GOCMD=tinygo gop run .

Let us assume that we introduce the following grammar in go.mod:

module hello

go 1.18  // llgo 0.9

or:

module hello

go 1.18  // tinygo 0.32

We specify that this project should use llgo or tinygo instead of go by introducing // llgo <ver> or // tinygo <ver>.

Of course you can still select the Go compiler by specifying GOP_GOCMD. At this time, we will ignore the // llgo <ver> or // tinygo <ver> information in go.mod.

Also, we can select llgo or tinygo by adding switch -llgo or -tinygo to the gop mod init command:

gop mod init -llgo <module-path>
gop mod init -tinygo <module-path>
aofei commented 3 weeks ago

I think GOP_COMPILER is more intuitive. GOP_GO_COMPILER works too, but it's a bit verbose.

This is a great idea, as it not only allows the use of LLGo but also enables other Go compilers like TinyGo.

xushiwei commented 3 weeks ago

I think GOP_COMPILER is more intuitive. GOP_GO_COMPILER works too, but it's a bit verbose.

GOP_COMPILER is ambiguous and can easily lead to misunderstanding. GOP_GO_COMPILER is clear but GOP_GOCMD is already supported.

xushiwei commented 2 weeks ago

llgo demo: https://github.com/goplus/gop/tree/main/demo/_llgo tinygo demo: https://github.com/goplus/gop/tree/main/demo/_tinygo