Skip to content

tinygo can't build packages other than main when modules are used #3464

@the80srobot

Description

@the80srobot

I don't think there is any way to get tinygo to produce a build of a package (e.g. for use as a WASM export) if you're using go modules.

If you have a project with a go.mod file, then you can build it with Go, but not with tinygo. After a couple of hours of messing with tinygo, I haven't discovered any way to get it to actually build a Go project with modules that's not just a main package.

# Succeeds, produces mnist.o:
docker run --rm -v $(pwd):/home/tinygo tinygo/tinygo:0.27.0 go build -o mnist.o ./mnist/

# Fails for made-up reasons?
docker run --rm -v $(pwd):/home/tinygo tinygo/tinygo:0.27.0 tinygo build -o mnist.o ./mnist/
panic: expected main package to have name 'main'

goroutine 1 [running]:
github.com/tinygo-org/tinygo/loader.(*Package).Check(0x40002d9c20)
	/home/runner/work/tinygo/tinygo/loader/loader.go:389 +0x354
github.com/tinygo-org/tinygo/loader.(*Program).Parse(0x4000101110)
	/home/runner/work/tinygo/tinygo/loader/loader.go:315 +0xac
github.com/tinygo-org/tinygo/builder.Build({0xffffefbaff40, 0x8}, {0xffffefbaff38, 0x7}, {0x40000263f0, 0x15}, 0x40001c64b0)
	/home/runner/work/tinygo/tinygo/builder/build.go:205 +0x100c
main.Build({0xffffefbaff40, 0x8}, {0xffffefbaff38, 0x7}, 0x40001d0000)
	/home/runner/work/tinygo/tinygo/main.go:168 +0x194
main.main()
	/home/runner/work/tinygo/tinygo/main.go:1525 +0x2f58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions