Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation of assets fails with GOOS=freebsd #87

Open
kolaente opened this issue Sep 1, 2020 · 2 comments
Open

Generation of assets fails with GOOS=freebsd #87

kolaente opened this issue Sep 1, 2020 · 2 comments

Comments

@kolaente
Copy link

kolaente commented Sep 1, 2020

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.

@dmitshur
Copy link
Member

dmitshur commented Sep 1, 2020

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.

@kolaente
Copy link
Author

kolaente commented Sep 1, 2020

I see, I think I understand now. Thank you for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants