Skip to content

Instantly share code, notes, and snippets.

@aeldar
Created February 2, 2021 13:58
Show Gist options
  • Save aeldar/b357662a3b7e42e95497a5db737b3d82 to your computer and use it in GitHub Desktop.
Save aeldar/b357662a3b7e42e95497a5db737b3d82 to your computer and use it in GitHub Desktop.
Build rust app for windows inside docker container
# Reduce the size of the executable file:
[profile.release]
lto = true
codegen-units = 1
opt-level = "z"
panic = 'abort'
# Place this Dockerfile into a `windows-builder` empty directory next to the `build-for-windows.sh` file
FROM rust:1
RUN rustup target add x86_64-pc-windows-gnu
RUN apt-get update \
&& apt-get install -y mingw-w64
#!/usr/bin/env sh
SCRIPT_PATH=`readlink -f "$0"`
SCRIPT_DIR=`dirname "$SCRIPT_PATH"`
docker run \
--rm \
-it \
--user "$(id -u)":"$(id -g)" \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp $(docker build -q $SCRIPT_DIR/windows-builder) \
cargo build --release --target x86_64-pc-windows-gnu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment