Skip to content

Commit 95e3ef6

Browse files
committed
add cross-compilation script for windows target
1 parent 1dba6da commit 95e3ef6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

make-win-targets

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
### This follows instructions in
4+
### "Let's cross-compile examples from rust-sdl2 project from Ubuntu to
5+
### Windows x86_64 [source].
6+
7+
set -x
8+
9+
cat ~/.cargo/config|grep "target.x86_64-pc-windows-gnu"
10+
if [ $? -ne 0 ]
11+
then
12+
cat << EOF >> ~/.cargo/config
13+
[target.x86_64-pc-windows-gnu]
14+
linker = "x86_64-w64-mingw32-gcc"
15+
ar = "x86_64-w64-mingw32-gcc-ar"
16+
EOF
17+
fi
18+
19+
20+
sudo apt install gcc-mingw-w64-x86-64 -y
21+
# use rustup to add target https://github.com/rust-lang/rustup.rs#cross-compilation
22+
rustup target add x86_64-pc-windows-gnu
23+
24+
# Based on instructions from https://github.com/AngryLawyer/rust-sdl2/
25+
26+
# First we need sdl2 libs
27+
# links to packages https://www.libsdl.org/download-2.0.php
28+
29+
sudo apt-get install libsdl2-dev -y
30+
curl -s https://www.libsdl.org/release/SDL2-devel-2.0.10-mingw.tar.gz | tar xvz -C /tmp
31+
32+
# Prepare files for building
33+
34+
mkdir -p ~/tmp/projects
35+
pushd ~/tmp/projects
36+
git clone https://github.com/Rust-SDL2/rust-sdl2
37+
cd rust-sdl2
38+
cp -r /tmp/SDL2-2.0.10/x86_64-w64-mingw32/lib/* ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
39+
cp /tmp/SDL2-2.0.10/x86_64-w64-mingw32/bin/SDL2.dll .
40+
popd
41+
42+
43+
## Prevent [compiler error] `undefined reference to__onexitend`
44+
pushd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
45+
mv crt2.o crt2.o.bak
46+
cp /usr/x86_64-w64-mingw32/lib/crt2.o ./
47+
popd
48+
49+
cargo build --target=x86_64-pc-windows-gnu --release
50+
51+
52+
### [source]: https://stackoverflow.com/questions/31492799/cross-compile-a-rust-application-from-linux-to-windows
53+
### [compiler error]: https://stackoverflow.com/questions/56602101/i-cant-get-cross-compiling-from-ubuntu-to-windows-working

0 commit comments

Comments
 (0)