mirror of
https://github.com/zbanks/radiance.git
synced 2026-06-16 04:26:25 +02:00
add build script
This commit is contained in:
Executable
+104
@@ -0,0 +1,104 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Usage: TARGET=x86_64-pc-windows-gnu ./generate-rustflags.sh
|
||||
|
||||
# Set PKG_CONFIG_PATH based on target
|
||||
export PKG_CONFIG_PATH="../libmpv-static-build/${TARGET}/output/lib/pkgconfig"
|
||||
|
||||
# Get all the static library dependencies
|
||||
LIBS=$(pkg-config --static --libs mpv)
|
||||
|
||||
# Convert pkg-config output to RUSTFLAGS format
|
||||
RUSTFLAGS=""
|
||||
|
||||
# Add all library flags, excluding -lpthread and -lstdc++ (we'll handle these separately)
|
||||
for flag in $LIBS; do
|
||||
if [[ $flag == -l* ]] || [[ $flag == -L* ]]; then
|
||||
# Skip -lpthread and -lstdc++ since we'll link them statically
|
||||
if [[ $flag != "-lpthread" ]] && [[ $flag != "-lstdc++" ]]; then
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=$flag"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Platform-specific linking
|
||||
case "$TARGET" in
|
||||
x86_64-pc-windows-gnu)
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--allow-multiple-definition"
|
||||
# Wrap all static libraries in a group to resolve circular dependencies
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bstatic"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--start-group"
|
||||
# Force static linking of libgcc, libgcc_eh, libstdc++, libwinpthread, and libmingw32
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lmingw32"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lwinpthread"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lgcc_eh"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lgcc"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lstdc++"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--end-group"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bdynamic"
|
||||
# MinGW runtime libraries (mingwex static, msvcrt uses system default CRT)
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--start-group"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bstatic"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lmingwex"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bdynamic"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lmsvcrt"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--end-group"
|
||||
# Windows system libraries (dynamically linked)
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lkernel32"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-ladvapi32"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lshell32"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lole32"
|
||||
|
||||
export RUSTFLAGS
|
||||
echo "Generated RUSTFLAGS: $RUSTFLAGS"
|
||||
|
||||
cargo build --release --target "$TARGET"
|
||||
x86_64-w64-mingw32-strip "target/${TARGET}/release/radiance.exe"
|
||||
;;
|
||||
x86_64-unknown-linux-gnu)
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bstatic"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-lstdc++"
|
||||
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,-Bdynamic"
|
||||
|
||||
# Populate /tmp/native-lib-pc with fake pkg-config files so we only dynamically link the things we want to
|
||||
rm -rf /tmp/native-lib-pc/
|
||||
mkdir -p /tmp/native-lib-pc/
|
||||
|
||||
cat <<EOF >/tmp/native-lib-pc/mpv.pc
|
||||
Name: mpv
|
||||
Description: placeholder
|
||||
Version: 999
|
||||
Cflags:
|
||||
Libs:
|
||||
EOF
|
||||
|
||||
cat <<EOF >/tmp/native-lib-pc/x11.pc
|
||||
Name: X11
|
||||
Description: placeholder
|
||||
Version: 999
|
||||
Cflags:
|
||||
Libs: -lX11
|
||||
EOF
|
||||
|
||||
cat <<EOF >/tmp/native-lib-pc/alsa.pc
|
||||
Name: alsa
|
||||
Description: placeholder
|
||||
Version: 999
|
||||
Cflags:
|
||||
Libs: -lasound
|
||||
EOF
|
||||
|
||||
export RUSTFLAGS
|
||||
echo "Generated RUSTFLAGS: $RUSTFLAGS"
|
||||
|
||||
PKG_CONFIG_LIBDIR="/tmp/native-lib-pc/" \
|
||||
PKG_CONFIG_PATH="/tmp/native-lib-pc/" \
|
||||
cargo build --release --target "$TARGET"
|
||||
strip "target/${TARGET}/release/radiance"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown target: $TARGET" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user