https://github.com/gechandesu/v-cross-compilation-example
A simple way to build static binaries for different architectures and OSes without a real hardware or virtual machines.
https://github.com/gechandesu/v-cross-compilation-example
build-system cross-compilation vlang vlang-example
Last synced: 4 months ago
JSON representation
A simple way to build static binaries for different architectures and OSes without a real hardware or virtual machines.
- Host: GitHub
- URL: https://github.com/gechandesu/v-cross-compilation-example
- Owner: gechandesu
- License: unlicense
- Created: 2025-09-19T21:22:33.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-10-01T21:32:26.000Z (8 months ago)
- Last Synced: 2025-10-10T20:14:59.462Z (8 months ago)
- Topics: build-system, cross-compilation, vlang, vlang-example
- Language: V
- Homepage: https://github.com/gechandesu/v-cross-compilation-example/releases/tag/v1.0.0
- Size: 7.81 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# V Cross-compilation Example
This example shows how to build statically linked binaries for different OS
and platforms for [V](https://vlang.io) programs.
The build is performed by the make.vsh script in V. I think it could be
simplified further, but the current version LGTM. Please read the comments
inside make.vsh for details.
The build is done inside a docker container with Debian 13 Trixie. Host is
`x86_64` Linux.
Produced binaries:
* Linux: `amd64`, `arm64`, `arm32` (`armhf`), `ppc64le`, `s390x`, `riscv64`
* Windows: `amd64`
* ~~FreeBSD: `amd64`~~ (disabled for now)
The example programm is just `Hello World!`. For complex programs you may need
to add more dependencies in build container.
I relied on Debian's excellent cross-compilation support (see the Dockerfile),
but with some elbow grease, you can compile the program for other architectures
and operating systems.
**Build**
Run:
```
./make.vsh
```
make.vsh script will build the Docker image and run crosscompile.vsh inside
a container.
The container image is large (almost 3GiB) due to the number of libraries
required for cross-compilation. The size could actually be reduced, but that's
what Debian provides by default in the `crossbuild-essential-*` packages. For
the same reason, building the image isn't very fast (up to ~3 minutes for me).
You may need change `docker_command` in `make.vsh` to `sudo docker` if your
host user does not have access to Docker daemon.
Look inside `release/` dir after compilation (:
## See Also
* [MANUAL.md](MANUAL.md) in this repository.
* `v help build`
* `v help build-c`
* https://docs.vlang.io/cross-compilation.html
* https://wiki.debian.org/CrossCompiling
* https://en.wikipedia.org/wiki/Cross_compiler#GCC_and_cross_compilation
* https://clang.llvm.org/docs/CrossCompilation.html