vfsgen
vfsgen copied to clipboard
Generation of assets fails with GOOS=freebsd
When generating contents prior to building for freebsd, generation fails with a segfault:
I'm executing the generate
step as a dependency of the build
step, therefore the env variables are also set for the generate step. The behaviour is the same when I run GOOS=freebsd GOARCH=amd64 go generate code.vikunja.io/api/pkg/static
directly.
$ GOOS=freebsd GOARCH=amd64 make build
go generate code.vikunja.io/api/pkg/static
signal: segmentation fault (core dumped)
pkg/static/static.go:17: running "go": exit status 1
make: *** [Makefile:105: generate] Error 1
The code is here.
If I generate the assets for my own platform (linux) and run the build with all env set for freebsd
, it seems to work, but only if I don't run the generate
step.
I'm not sure if this is an issue with vfsgen or some other part of the go toolchain. It is imho not critical since the workaround with running the generate
step first and only then setting the env variables for freebsd when compiling the binary is an okay-ish workaround. I only happend to stuble upon this because of the way my makefile is set up.
Thanks for reporting. The problem is at https://kolaente.dev/vikunja/api/src/commit/79970ebb4a29f2450b40ebd4ce7acb0acf54f235/pkg/static/static.go#L17.
That go generate directive is invoking go run
. When you run GOOS=freebsd GOARCH=amd64 go generate
, the GOOS
/GOARCH
environment variables are passed on to go run
, which builds a binary for FreeBSD and then attempts to execute it. Doing so on Linux causes a segmentation fault.
You shouldn't try to do GOOS=freebsd go generate
when on Linux. Do go generate
instead.
An alternative fix you could consider is to modify that line to do something like:
//go:generate sh -c "GOOS=$GOHOSTOS GOARCH=$GOHOSTOS go run -tags=dev templates_generate.go"
But I wouldn't recommend it because it adds more complexity than just running go generate
with GOOS
/GOARCH
values that can be used by go run
on your system, and it adds a dependency on sh
.
I see, I think I understand now. Thank you for clarifying.