DEV Community

Cover image for Golang/Rust Project Workflow
initdc
initdc

Posted on

Golang/Rust Project Workflow

We may encounter problems running programs on non-x86 architectures.

For example, running a DNS-over-HTTPS client on a Raspberry Pi 4B, or a VPN server on a MIPS architecture OpenWRT router.

Common sense says that this should be simple. But in reality it is a complex and painful task.

The next scenario occurs when the software is not included in a Linux distribution, or an embedded distribution without a package manager.

First you need to download the binary for your architecture, and you'll have to pray that you can find it on GitHub Releases, otherwise you'll need to compile it yourself. Then you run the program, and maybe it works, or maybe it needs more dependencies. You start to get into pain, Docker is a good solution, you start to look for it, and then you find out that the Docker image doesn't have a corresponding architecture.

Why is that? The developer builds a workflow for GitHub Releases, which will generate a binary for the target architecture. Then build another workflow for Docker, usually with only the major architecture, and compile it from source. I started to see the problem, why do I need to run an additional compilation process? I already ran the compilation process when I published Releases on GitHub, why do I need to do it again?

Yes, maybe I just need to use the pre-built binaries to build the Docker image.

I'm a rookie and I didn't learn C properly. I prefer the painless cross-platform Golang and Rust, so I wrote the workflow template for the Golang project first, and then adapted it to Rust.

The template uses a Ruby script to run the build command, linking the files to the appropriate directory that will be used to build the Docker image later. This is a very elegant design that allows me to not bother parsing the TARGETPLATFORM environment variables passed by docker buildx.

Rust's cross-platform compilation is not complete, and the binaries for Windows, Darwin, were not compiled successfully on Linux Host. I am not familiar with the Windows build environment, so I am looking for improvements to this.

The templates are located at
https://github.com/initdc/golang-project-workflow
https://github.com/initdc/rust-project-workflow

Top comments (0)