Skip to content

Commit

Permalink
suite: fix a ton of things
Browse files Browse the repository at this point in the history
give Rust a config file (from sztomi here briansmith/ring#894) so that CLANG64/32 Rust compilations actually work, fix some issues with mismatched variables in the batch file, delimit some right parenthesis in the batch file to prevent reconfiguration, point to the exact location of cargo.exe when on CLANG64/32, fix malformed srt & kvazaar pkgconfig files on CLANG64/32, link pthread when compiling vpx on CLANG64/32, make local64_*clang/bin's batch files point to relevant clang counterparts, and probably some other things i missed. i know it's a lot
  • Loading branch information
woot000 committed Feb 11, 2022
1 parent 9159efc commit 47e5019
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 51 deletions.
17 changes: 14 additions & 3 deletions build/media-suite_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1159,11 +1159,18 @@ if { enabled libvpx || [[ $vpx = y ]]; } && do_vcs "https://chromium.googlesourc
[[ $ffmpeg = sharedlibs ]] || extracommands+=(--enable-{vp9-postproc,vp9-highbitdepth})
get_external_opts extracommands
get_custom_flags userflags
CFLAGS+=" ${userflags[0]}" CXXFLAGS+=" ${userflags[1]}" \
case $CC in
*gcc) CFLAGS+=" ${userflags[0]}" CXXFLAGS+=" ${userflags[1]}" \
CPPFLAGS+=" ${userflags[2]}" LDFLAGS+=" ${userflags[3]}" config_path=.. \
do_configure --target="${arch}-win${bits%bit}-gcc" \
--disable-{avx512,shared,unit-tests,docs,install-bins} \
"${extracommands[@]}"
"${extracommands[@]}" ;;
*clang) CFLAGS+=" ${userflags[0]}" CXXFLAGS+=" ${userflags[1]}" \
CPPFLAGS+=" ${userflags[2]}" LDFLAGS+=" ${userflags[3]} -pthread" config_path=.. \
do_configure --target="${arch}-win${bits%bit}-gcc" \
--disable-{avx512,shared,unit-tests,docs,install-bins} \
"${extracommands[@]}" ;;
esac
sed -i 's;HAVE_GNU_STRIP=yes;HAVE_GNU_STRIP=no;' -- ./*.mk
do_make
do_makeinstall
Expand Down Expand Up @@ -1278,7 +1285,7 @@ if { [[ $rav1e = y ]] || [[ $libavif = y ]] || enabled librav1e; } &&
--destdir="$PWD/install-$bits" ;;
CLANG*) CFLAGS+=" ${userflags[0]}" CXXFLAGS+=" ${userflags[1]}" \
CPPFLAGS+=" ${userflags[2]}" LDFLAGS+=" ${userflags[3]}" \
log "install-rav1e-c" "cargo.exe" capi install \
log "install-rav1e-c" "$MINGW_PREFIX/bin/cargo.exe" capi install \
--release --jobs "$cpuCount" --prefix="$LOCALDESTDIR" \
--destdir="$PWD/install-$bits" ;;
esac
Expand Down Expand Up @@ -1355,6 +1362,8 @@ if { [[ $other265 = y ]] || { [[ $ffmpeg != no ]] && enabled libkvazaar; }; } &&
unset userflags
fi

pc_exists kvazaar && [[ ${CC##* } = clang ]] && sed -i -z 's/-lkvazaar\nLibs.private: \n/-lkvazaar\nLibs.private: -lpthread\n/g' "$LOCALDESTDIR/lib/pkgconfig/kvazaar.pc"

_check=(libSDL2{,_test,main}.a sdl2.pc SDL2/SDL.h)
if { { [[ $ffmpeg != no ]] &&
{ enabled sdl2 || ! disabled_any sdl2 autodetect; }; } ||
Expand Down Expand Up @@ -1989,6 +1998,8 @@ if enabled libsrt && do_vcs "https://github.com/Haivision/srt.git"; then
unset userflags
fi

pc_exists srt && [[ ${CC##* } = clang ]] && sed -i "s/-l-l:libunwind.a/-l:libunwind.a/g" "$LOCALDESTDIR/lib/pkgconfig/srt.pc"

_check=(librist.{a,pc} librist/librist.h)
[[ $standalone = y ]] && _check+=(bin-global/rist{sender,receiver,2rist,srppasswd}.exe)
if enabled librist && do_vcs "https://code.videolan.org/rist/librist.git"; then
Expand Down
38 changes: 19 additions & 19 deletions build/media-suite_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ do_mesoninstall() {
do_rust() {
case $MSYSTEM in
MINGW*|UCRT64) log "rust.update" "$RUSTUP_HOME/bin/cargo.exe" update ;;
CLANG*) log "rust.update" "cargo.exe" update ;;
CLANG*) log "rust.update" "$MINGW_PREFIX/bin/cargo.exe" update ;;
esac
# use this array to pass additional parameters to cargo
local rust_extras=()
Expand All @@ -1356,7 +1356,7 @@ do_rust() {
MINGW*|UCRT64) log "rust.build" "$RUSTUP_HOME/bin/cargo.exe" build --release \
--target="$CARCH"-pc-windows-gnu \
--jobs="$cpuCount" "$@" "${rust_extras[@]}" ;;
CLANG*) log "rust.build" "cargo.exe" build --release \
CLANG*) log "rust.build" "$MINGW_PREFIX/bin/cargo.exe" build --release \
--target="$CARCH"-pc-windows-gnu \
--jobs="$cpuCount" "$@" "${rust_extras[@]}" ;;
esac
Expand All @@ -1367,7 +1367,7 @@ do_rust() {
do_rustinstall() {
case $MSYSTEM in
MINGW*|UCRT64) log "rust.update" "$RUSTUP_HOME/bin/cargo.exe" update ;;
CLANG*) log "rust.update" "cargo.exe" update ;;
CLANG*) log "rust.update" "$MINGW_PREFIX/bin/cargo.exe" update ;;
esac
# use this array to pass additional parameters to cargo
local rust_extras=()
Expand All @@ -1378,7 +1378,7 @@ do_rustinstall() {
MINGW*|UCRT64) log "rust.install" "$RUSTUP_HOME/bin/cargo.exe" install \
--target="$CARCH"-pc-windows-gnu \
--jobs="$cpuCount" "${@:---path=.}" "${rust_extras[@]}" ;;
CLANG*) log "rust.install" "cargo.exe" install \
CLANG*) log "rust.install" "$MINGW_PREFIX/bin/cargo.exe" install \
--target="$CARCH"-pc-windows-gnu \
--jobs="$cpuCount" "${@:---path=.}" "${rust_extras[@]}" ;;
esac
Expand Down Expand Up @@ -2103,37 +2103,37 @@ EOF
}

create_ab_ccache() {
local bin temp_file bin2 ccache_path=false ccache_win_path=
local bin temp_file ccache_path=false ccache_win_path=
temp_file=$(mktemp)
if [[ $ccache == y ]] && type ccache > /dev/null 2>&1; then
ccache_path="$(command -v ccache)"
ccache_win_path=$(cygpath -m "$ccache_path")
fi
mkdir -p "$LOCALDESTDIR"/bin > /dev/null 2>&1
for bin in {$MINGW_CHOST-,}{gcc,g++} clang{,++} cc cpp c++; do
if [[ $CC = *clang ]]; then
declare -a arrbin=({$MINGW_CHOST-,}{clang,clang++} cc cpp c++)
else
declare -a arrbin=({$MINGW_CHOST-,}{gcc,g++} clang{,++} cc cpp c++)
fi
for bin in "${arrbin[@]}"; do
type "$bin" > /dev/null 2>&1 || continue
if [[ $MSYSTEM == UCRT64 && $CC = clang* ]]; then
case $bin in
"gcc" | "cc") bin2=clang ;;
"g++" | "c++") bin2=clang++ ;;
"cpp") bin2=clang-cpp ;;
--) bin2=$bin ;;
*) bin2=$bin ;;
esac
else
bin2=$bin
fi
cat << EOF > "$temp_file"
@echo off >nul 2>&1
rem() { "\$@"; }
rem test -f nul && rm nul
rem $ccache_path --help > /dev/null 2>&1 && $ccache_path $(command -v $bin2) "\$@" || $(command -v $bin2) "\$@"
rem $ccache_path --help > /dev/null 2>&1 && $ccache_path $(command -v $bin) "\$@" || $(command -v $bin) "\$@"
rem exit \$?
$ccache_win_path $(cygpath -m "$(command -v $bin2)") %*
$ccache_win_path $(cygpath -m "$(command -v $bin)") %*
EOF
diff -q "$temp_file" "$LOCALDESTDIR/bin/$bin.bat" > /dev/null 2>&1 || cp -f "$temp_file" "$LOCALDESTDIR/bin/$bin.bat"
chmod +x "$LOCALDESTDIR/bin/$bin.bat"
done
if [[ $CC = *clang ]]; then
cp -f "$LOCALDESTDIR/bin/clang.bat" "$LOCALDESTDIR/bin/gcc.bat"
cp -f "$LOCALDESTDIR/bin/clang++.bat" "$LOCALDESTDIR/bin/g++.bat"
cp -f "$LOCALDESTDIR/bin/x86_64-w64-mingw32-clang.bat" "$LOCALDESTDIR/bin/x86_64-w64-mingw32-gcc.bat"
cp -f "$LOCALDESTDIR/bin/x86_64-w64-mingw32-clang++.bat" "$LOCALDESTDIR/bin/x86_64-w64-mingw32-g++.bat"
fi
rm "$temp_file"
}

Expand Down
76 changes: 47 additions & 29 deletions media-autobuild_suite.bat
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ if %license2INI%==0 (
echo. 4 = LGPLv3
echo. [Disables x264, x265, XviD, GPL filters, etc.
echo. but reenables OpenSSL/FDK-AAC]
echo. 5 = LGPLv2.1 [same disables as LGPLv3 + GPLv2.1]
echo. 5 = LGPLv2.1 [same disables as LGPLv3 ^+ GPLv2.1]
echo.
echo. If building for yourself, it's OK to choose non-free.
echo. If building to redistribute online, choose GPL or LGPL.
Expand Down Expand Up @@ -1188,8 +1188,8 @@ if %useUcrtINI%==0 (
echo. 2 = No [recommended]
echo.
echo. Use Universal C Runtime based environment instead of msvcrt environment.
echo. Allows for the Clang toolchain to use libgcc and libstdc^+^+, and
echo. for the MinGW toolchain to use libc^+^+, all within the ucrt environment.
echo. Allows for the Clang toolchain to use libgcc and libstdc++, and
echo. for the MinGW toolchain to use libc++, all within the ucrt environment.
echo.
echo. Experimental. In order for compilation and produced binaries to function on
echo. older OSes, an update must be installed, which is available from Microsoft's
Expand All @@ -1212,8 +1212,8 @@ if %addFlags1INI%==0 (
echo -------------------------------------------------------------------------------
echo.
echo. Select the architecture flags that you prefer:
echo. 1 = -march=native (Fastest, but ^not sharable!)
echo. 2 = -mtune=generic (Sharable, but ^not the fastest!) [recommended]
echo. 1 = -march=native (Fastest, but ^not sharable!^)
echo. 2 = -mtune=generic (Sharable, but ^not the fastest!^) [recommended]
echo.
echo -------------------------------------------------------------------------------
echo -------------------------------------------------------------------------------
Expand All @@ -1232,29 +1232,29 @@ if %addFlags2INI%==0 (
echo -------------------------------------------------------------------------------
echo.
echo. Select the optimization flags that you prefer:
echo. 0 = -O0 (No optimizations!)
echo. 1 = -O1 (Low optimizations!)
echo. 2 = -O2 (Some optimizations!) [recommended]
echo. 3 = -O3 (High optimizations!)
echo. 4 = -Os (Optimize ^for small code size!)
echo. 5 = -Os, opt-level=z (Rust has an option that optimizes code size even more)
echo. 6 = -Os -fdata-sections -ffunction-sections -Wl,--gc-sections, opt-level=z
echo. -C panic=abort (This is about as small as it can get!)
echo. 1 = -O1 (Low optimizations!^)
echo. 2 = -O2 (Some optimizations!^) [recommended]
echo. 3 = -O3 (High optimizations!^)
echo. 4 = -O0 (No optimizations!^)
echo. 5 = -Os (Optimize for small code size!^)
echo. 6 = -Os, opt-level=z (Rust has an option that optimizes code size even more^)
echo. 7 = -Os -fdata-sections -ffunction-sections -Wl,--gc-sections, opt-level=z
echo. -C panic=abort (This is about as small as it can get!^)
echo.
echo -------------------------------------------------------------------------------
echo -------------------------------------------------------------------------------
set /P optFlags="Optimization level: "
) else set optFlags=%addFlags2INI%

if "%optFlags%"=="" GOTO addFlags2
if %optFlags%==0 set "addFlags2=none"
if %optFlags%==1 set "addFlags2=low"
if %optFlags%==2 set "addFlags2=med"
if %optFlags%==3 set "addFlags2=high"
if %optFlags%==4 set "addFlags2=small"
if %optFlags%==5 set "addFlags2=smaller"
if %optFlags%==6 set "addFlags2=smallest"
if %optFlags% GTR 6 GOTO addFlags2
if %optFlags%==4 set "addFlags2=none"
if %optFlags%==5 set "addFlags2=small"
if %optFlags%==6 set "addFlags2=smaller"
if %optFlags%==7 set "addFlags2=smallest"
if %optFlags% GTR 7 GOTO addFlags2
if %deleteINI%==1 echo.addFlags2=^%optFlags%>>%ini%

:numCores
Expand Down Expand Up @@ -1758,19 +1758,19 @@ if %skipUpdate%==y (
rem setflags

if %addFlags1%==native (
set suiteCflags=-march=native
set suiteRustflags=-C target-cpu=native
set "suiteCflags=-march=native"
set "suiteRustflags=-C target-cpu=native"
) else (
set suiteCflags=-mtune=generic
set suiteRustflags=-C target-cpu=generic
set "suiteCflags=-mtune=generic"
set "suiteRustflags=-C target-cpu=generic"
)
if %addFlags2%==none set suiteCflags=%suiteCflags% -O0 && set suiteRustflags=%suiteRustflags% -C opt-level=0
if %addFlags2%==low set suiteCflags=%suiteCflags% -O1 && set suiteRustflags=%suiteRustflags% -C opt-level=1
if %addFlags2%==med set suiteCflags=%suiteCflags% -O2 && set suiteRustflags=%suiteRustflags% -C opt-level=2
if %addFlags2%==high set suiteCflags=%suiteCflags% -O3 && set suiteRustflags=%suiteRustflags% -C opt-level=3
if %addFlags2%==small set suiteCflags=%suiteCflags% -Os && set suiteRustflags=%suiteRustflags% -C opt-level=s
if %addFlags2%==smaller set suiteCflags=%suiteCflags% -Os && set suiteRustflags=%suiteRustflags% -C opt-level=z
if %addFlags2%==smallest set suiteCflags=%suiteCflags% -Os -fdata-sections -ffunction-sections -Wl,--gc-sections && set suiteRustflags=%suiteRustflags% -C opt-level=z -C panic=abort
if %addFlags2%==none set "suiteCflags=%suiteCflags% -O0" && set "suiteRustflags=%suiteRustflags% -C opt-level=0"
if %addFlags2%==low set "suiteCflags=%suiteCflags% -O1" && set "suiteRustflags=%suiteRustflags% -C opt-level=1"
if %addFlags2%==med set "suiteCflags=%suiteCflags% -O2" && set "suiteRustflags=%suiteRustflags% -C opt-level=2"
if %addFlags2%==high set "suiteCflags=%suiteCflags% -O3" && set "suiteRustflags=%suiteRustflags% -C opt-level=3"
if %addFlags2%==small set "suiteCflags=%suiteCflags% -Os" && set "suiteRustflags=%suiteRustflags% -C opt-level=s"
if %addFlags2%==smaller set "suiteCflags=%suiteCflags% -Os" && set "suiteRustflags=%suiteRustflags% -C opt-level=z"
if %addFlags2%==smallest set "suiteCflags=%suiteCflags% -Os -fdata-sections -ffunction-sections -Wl,--gc-sections" && set "suiteRustflags=%suiteRustflags% -C opt-level=z -C panic=abort"

rem ------------------------------------------------------------------
rem write config profiles:
Expand All @@ -1792,16 +1792,34 @@ if exist %instdir%\msys64\etc\profile.pacnew ^
findstr /C:"profile2.local" %instdir%\msys64\etc\profile.d\Zab-suite.sh >nul 2>&1 || (
echo.if [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = MINGW64 ]]; then
echo. source /local64_gcc/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo.elif [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = MINGW32 ]]; then
echo. source /local32_gcc/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo.elif [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = CLANG64 ]]; then
echo. source /local64_clang/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo. cat ^<^< EOF ^> $CARGO_HOME/config.toml
echo.[target.x86_64-pc-windows-gnu]
echo.linker = "x86_64-w64-mingw32-clang"
echo.env = { TARGET_CC="x86_64-w64-mingw32-clang", TARGET_AR="llvm-ar" }
echo.rustflags = [ "-L", "clang64/lib/clang/13.0.1/lib/windows" ]
echo.EOF
echo.elif [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = CLANG32 ]]; then
echo. source /local32_clang/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo. cat ^<^< EOF ^> $CARGO_HOME/config.toml
echo.[target.i686-pc-windows-gnu]
echo.linker = "i686-w64-mingw32-clang"
echo.env = { TARGET_CC="i686-w64-mingw32-clang", TARGET_AR="llvm-ar" }
echo.rustflags = [ "-L", "clang32/lib/clang/13.0.1/lib/windows" ]
echo.EOF
echo.elif [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = UCRT64 ]] ^&^& grep -Fxq CC=1 /build/media-autobuild_suite.ini; then
echo. source /local64_ucrtclang/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo.elif [[ -z "$MSYSTEM" ^|^| "$MSYSTEM" = UCRT64 ]] ^&^& grep -Fxq CC=2 /build/media-autobuild_suite.ini; then
echo. source /local64_ucrtgcc/etc/profile2.local
echo. rm -f $CARGO_HOME/config.toml
echo.fi
)>%instdir%\msys64\etc\profile.d\Zab-suite.sh

Expand Down

0 comments on commit 47e5019

Please sign in to comment.