Skip to content

Instantly share code, notes, and snippets.

@klutzy
Last active March 9, 2024 13:38
Show Gist options
  • Save klutzy/6349568 to your computer and use it in GitHub Desktop.
Save klutzy/6349568 to your computer and use it in GitHub Desktop.
rust cross-build script: mingw -> mingw-w64
#!/bin/sh
# this assumes you are using mingw-w64 platform.
# if not, add --linker=x86_64-w64-mingw32-g++.exe option
TARGET=x86_64-w64-mingw32
RUST_ROOT=/c/home/stone/rust
# copy mingw runtime dlls to the dir to prevent dll hell.
RUSTC=/c/home/usr/rust/bin/rustc.exe
"$RUSTC" -v
OUTDIR=/c/home/stone/tmp/wwww
mkdir -p $OUTDIR/bin/rustc/$TARGET/bin
function f() {
SRC=$RUST_ROOT/src/$1/lib.rs
CROSS_DLL=$2
OUTDLL1=$OUTDIR/bin/$CROSS_DLL.dll
OUTDLL2=$OUTDIR/bin/rustc/$TARGET/bin/$CROSS_DLL.dll
echo "$SRC -> $OUTDLL1"
$RUSTC --cfg stage2 --cfg debug \
--target=$TARGET \
$SRC -L $OUTDIR/bin \
-Z extra-debug-info -Z no-opt -Z time-passes \
--out-dir=$OUTDIR/bin 2>&1 | tee $1-time &&
cp -pv $OUTDLL1 $OUTDLL2
}
CROSS_STD_DLL=std-6425b930ca146ae9-0.9-pre
CROSS_RUSTUV_DLL=rustuv-a13edc95d75df17-0.9-pre
CROSS_EXTRA_DLL=extra-aaa96aab146eb38e-0.9-pre
CROSS_RUSTC_DLL=rustc-8581899a03b03e-0.9-pre
CROSS_SYNTAX_DLL=syntax-2bb2d559d93ae8f0-0.9-pre
CROSS_RUSTDOC_DLL=rustdoc-8fe97af77990febe-0.9-pre
CROSS_RUSTPKG_DLL=rustpkg-8b82ba56c736b1-0.9-pre
f "libstd" $CROSS_STD_DLL
f "librustuv" $CROSS_RUSTUV_DLL
f "libextra" $CROSS_EXTRA_DLL
f "libsyntax" $CROSS_SYNTAX_DLL
# rustc needs some variables
export CFG_VERSION=0.9-pre
export CFG_VERSION_WIN=0.9
export CFG_PREFIX=xxx # what was this?
export CFG_LIBDIR=bin
export CFG_COMPILER=$TARGET
f "librustc" $CROSS_RUSTC_DLL
function g() {
SRC=$RUST_ROOT/src/driver/driver.rs
CROSS_EXE=$1
OUTEXE=$OUTDIR/bin/$CROSS_EXE.exe
echo "$SRC -> $OUTEXE"
$RUSTC --cfg debug --cfg $CROSS_EXE \
--target=$TARGET \
$SRC -L $OUTDIR/bin \
-o $OUTEXE
}
g rustc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment