Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It gets even more amazing than that. Look at this bit from my GitHub Actions: https://github.com/ncruces/go-sqlite3/blob/fefee692dbfad39f6...

I install QEMU (I have the same setup locally), then it's one line each to run unit tests for: Linux 386, arm64, riscv64, ppc64le and s390x.

With QEMU installed, all you have to do is:

    GOARCH=bla go test ./...


Wait is go test automatically running it under QEMU or what's going on here?


Ah I found this https://ctrl-c.us/posts/test-goarch I guess it's qemu-user-binfmt registering the alternate bin formats to automatically run under QEMU, that's pretty neat


Yep.

The Go build system runs under your current architecture, cross-compiling tests to your target architecture.

Then, the Go test runner also runs under your current architecture, orchestrating running your cross compiled test binaries.

Since you registered to run cross-compiled binaries under QEMU, those test binaries magically run through QEMU.

The Go test runner collects test results, and reports back to you.

The first run might be slowish, as the Go compiler needs to cross compile the standard library and all your dependencies to your target platform. But once that's done and cached, and if your tests are fast, the edit-test cycle becomes pretty quick.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: