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

Guide for cross compiling using docker #1304

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Installing on a Raspberry Pi](./installation/Raspberry-Pi.md)
- [Installing on Ubuntu (from source)](./installation/Ubuntu.md)
- [Cross Compiling on Ubuntu](./installation/Cross-Compiling-on-Ubuntu.md)
- [Cross Compilation using Docker](./installation/cross-compile-using-docker.md)
- [Installing with Homebrew on macOS](./installation/MacOS.md)
- [Installing on FreeBSD](./installation/FreeBSD.md)
- [Installing on OpenBSD](./installation/OpenBSD.md)
Expand Down
41 changes: 41 additions & 0 deletions docs/src/installation/cross-compile-using-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Cross Compilation using Docker

We can also use `docker` to cross compile on every platform and OS that runs `docker` and `qemu`:

1. Setup a docker [custom builder](https://docs.docker.com/build/building/multi-platform/#create-a-custom-builder)

```shell
docker buildx create \
--name container-builder \
--driver docker-container \
--use --bootstrap
```

If you are **not** using Docker-Desktop you might have to install [QEMU](https://docs.docker.com/build/building/multi-platform/#install-qemu-manually)

2. Create a docker `compose-file.yml`

Here we are building a `arm64` binary, so we set `platform: linux/arm64`

```yaml
services:
build-container:
image: rust:1.79-bookworm
platform: linux/arm64
command: bash -c "
apt-get update &&
apt-get install -y \
libasound2-dev \
libssl-dev \
pkg-config &&
curl -sSL https://api.github.com/repos/Spotifyd/spotifyd/tarball/v0.3.5 | tar xz -C /spotifyd --strip-components=1 &&
cargo build --release &&
cp /spotifyd/target/release/spotifyd /build/"
working_dir: /spotifyd
volumes:
- ./:/build
```

3. Run `docker compose up`

This will copy the build `spotifyd` binary in the current directory.