Skip to content

Commit

Permalink
Setup cross compiling using the cross project (tgstation#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
optimumtact authored Jun 29, 2021
1 parent efc88c0 commit dc43630
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.i686-pc-windows-gnu]
image = "rustembedded/cross:i686-pc-windows-gnu"

[target.i686-unknown-linux-gnu]
image = "rustg/i686-unknown-linux-gnu"

[build.env]
passthrough = [
"PKG_CONFIG_ALLOW_CROSS"
]

5 changes: 5 additions & 0 deletions docker/Dockerfile.i686-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM rustembedded/cross:i686-unknown-linux-gnu

RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install --assume-yes zlib1g-dev:i386 libssl-dev:i386 pkg-config:i386
12 changes: 9 additions & 3 deletions scripts/prepare_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ set -euo pipefail

touch build.rs

echo '==== Make sure cross is installed ===='
cargo install cross

echo '==== Linux build ====' # ------------------------------------------------
rustup target add i686-unknown-linux-gnu
env PKG_CONFIG_ALLOW_CROSS=1 \
cargo build --release --target i686-unknown-linux-gnu
cargo build --release --target i686-unknown-linux-gnu

mv target/rust_g.dm target/rust_g.linux.dm

echo '==== Windows build ====' # ----------------------------------------------
rustup target add i686-pc-windows-gnu
cargo build --release --target i686-pc-windows-gnu
cross build --release --target i686-pc-windows-gnu
# https://github.com/rust-lang/rust/issues/12859#issuecomment-62255275
# Most distros ship 32-bit toolchains with SJLJ unwinding, but for 32-bit Rust
# can only cross-compile targeting DWARF. All 64-bit toolchains use SEH, where
Expand All @@ -27,6 +29,10 @@ cargo build --release --target i686-pc-windows-gnu
# tar xf rust-mingw-nightly-i686-pc-windows-gnu.tar.gz
# ./rust-mingw-nightly-i686-pc-windows-gnu/install.sh --prefix=$(rustc --print sysroot)

# Luckily we are taking the third workaround, which is using the cross projects i686
# windows toolchain docker which comes with an updated version of mingw that supports
# the DWARF based unwinding, freeing us from such earthly concerns

# Make sure the `rust_g.dm` produced for each platform are the same, just in
# case.
cmp target/rust_g.dm target/rust_g.linux.dm
Expand Down

0 comments on commit dc43630

Please sign in to comment.