From 94913c6742c6d6a319c2a904122ae37da89483f9 Mon Sep 17 00:00:00 2001 From: Nils <31704359+mietzen@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:53:30 +0200 Subject: [PATCH 1/3] Added add guide for cross compiling using docker Add documentation for e.g. building arm64 as described in #1053 --- .../cross-compile-using-docker.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/src/installation/cross-compile-using-docker.md diff --git a/docs/src/installation/cross-compile-using-docker.md b/docs/src/installation/cross-compile-using-docker.md new file mode 100644 index 00000000..40dae8cc --- /dev/null +++ b/docs/src/installation/cross-compile-using-docker.md @@ -0,0 +1,33 @@ +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 +``` + +2. Create a docker `compose-file.yml`: +```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. From 3dcde2e0d66fb5cc0bbedc6b2ed4d658bd1ac0c0 Mon Sep 17 00:00:00 2001 From: Nils Stein <31704359+mietzen@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:07:11 +0200 Subject: [PATCH 2/3] Formatting and rewording --- .../cross-compile-using-docker.md | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/docs/src/installation/cross-compile-using-docker.md b/docs/src/installation/cross-compile-using-docker.md index 40dae8cc..97277648 100644 --- a/docs/src/installation/cross-compile-using-docker.md +++ b/docs/src/installation/cross-compile-using-docker.md @@ -1,33 +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 -``` - -2. Create a docker `compose-file.yml`: -```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 -``` + + ```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. + This will copy the build `spotifyd` binary in the current directory. From 3cf858b4e03e4640b94b8aed45bcb763f8398b2e Mon Sep 17 00:00:00 2001 From: Nils Stein <31704359+mietzen@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:07:38 +0200 Subject: [PATCH 3/3] Added Cross Compilation using Docker to Summary --- docs/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index a01e51d9..c755633b 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -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)