- Separate cross-compilation logic to crosscompile.vsh - Manage Docker in make.vsh, no more manual running `docker build`, etc. - Add MANUAL.md instruction - Enchance Dockerfile
1.8 KiB
V Cross-compilation Example
This example shows how to build statically linked binaries for different OS and platforms for V 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:(disabled for now)amd64
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 (: