Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Meson for mpv instead of Waf #2359

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 106 additions & 17 deletions build/media-suite_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2384,9 +2384,11 @@ if [[ $mpv != n ]] && pc_exists libavcodec libavformat libswscale libavfilter; t
hide_conflicting_libs
create_ab_pkgconfig

log bootstrap /usr/bin/python bootstrap.py
if [[ -d build ]]; then
# Temporarily keep this until Waf is reasonably phased out.
# Not all users will run this weekly, so keep the cleanup for now.
/usr/bin/python waf distclean >/dev/null 2>&1
rm -rf build # Meson's recommended way to clean up previous runs!
do_uninstall bin-video/mpv{.exe,-2.dll}.debug "${_check[@]}"
fi

Expand Down Expand Up @@ -2415,9 +2417,13 @@ if [[ $mpv != n ]] && pc_exists libavcodec libavformat libswscale libavfilter; t

[[ -f mpv_extra.sh ]] && source mpv_extra.sh

mpv_enabled mruby &&
{ git merge --no-edit --no-gpg-sign origin/mruby ||
git merge --abort && do_removeOption MPV_OPTS "--enable-mruby"; }
# The mruby branch cannot (currently) be built with Meson, and hasn't seen
# any activity in over 5 years; for now it's statically disabled.
# https://github.com/mpv-player/mpv/issues/11078
if mpv_enabled mruby; then
do_removeOption MPV_OPTS "--enable-mruby";
do_simple_print "${orange}mruby in mpv is no longer supported"'!'"${reset}"
fi

if files_exist libavutil.a; then
MPV_OPTS+=(--enable-static-build)
Expand All @@ -2432,27 +2438,107 @@ if [[ $mpv != n ]] && pc_exists libavcodec libavformat libswscale libavfilter; t
done
fi

# Translate the Waf flags to Meson options instead.
# It should be fairly easy to overwrite the mpv_options file,
# though differentiating would require ugly hacks like a header marker.
# This allows reusing old configs and doesn't rely on correctly formatted input,
# since users editing a config may easily slip up with `-D` prepended to every line.
# The alternative is having users only specify everything after it in the config, e.g.
# `lua=luajit` and `cdda=enabled` (optionally omitting `=enabled` for on/off features)
local meson_opts=()
local default_lib="both"
local option
for option in "${MPV_OPTS[@]}"; do
# Process Waf flags into Meson options.
# starting with boolean flags
if [[ $option =~ ^--enable-(gpl|cplayer|build-date|tests|ta-leak-report) ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TA Leak can only be turned off by also adjusting an env var; perhaps make some accessible entry point for people to inject the option from a custom patch instead of setting it here?

meson_opts+=("${option/--enable-/-D}=true")
elif [[ $option =~ ^--disable-(gpl|cplayer|build-date|tests|ta-leak-report) ]]; then
meson_opts+=("${option/--disable-/-D}=false")
elif [[ $option =~ ^--enable-libmpv(-shared)? ]]; then
meson_opts+=("-Dlibmpv=true")
elif [[ $option =~ ^--disable-libmpv(-shared)? ]]; then
meson_opts+=("-Dlibmpv=false")
default_lib="static"
# features in the misc section
elif [[ $option =~ ^--enable-(cdda|cplugins|dvbin|dvdnav|iconv|javascript|lcms2|libarchive|libavdevice|libbluray|pthread-debug|rubberband|sdl2|sdl2-gamepad|stdatomic|uchardet|uwp|vapoursynth|vector|win32-internal-pthreads|zimg|zlib) ]]; then
meson_opts+=("${option/--enable-/-D}=enabled")
elif [[ $option =~ ^--disable-(cdda|cplugins|dvbin|dvdnav|iconv|javascript|lcms2|libarchive|libavdevice|libbluray|pthread-debug|rubberband|sdl2|sdl2-gamepad|stdatomic|uchardet|uwp|vapoursynth|vector|win32-internal-pthreads|zimg|zlib) ]]; then
meson_opts+=("${option/--disable-/-D}=disabled")
# Audio option time! This goes in twos; we're unconditionally disabling non-Windows options and warning the user.
elif [[ $option =~ ^--enable-(alsa|audiounit|coreaudio|oss-audio|pipewire|pulse|sndio) ]]; then
meson_opts+=("${option/--enable-/-D}=disabled")
do_simple_print "${orange}Disabling option '${option}' as it's not usable on Windows"'!'"${reset}"
elif [[ $option =~ ^--enable-(jack|openal|opensles|sdl2-audio|wasapi) ]]; then
meson_opts+=("${option/--enable-/-D}=enabled")
elif [[ $option =~ ^--disable-(jack|openal|opensles|sdl2-audio|wasapi) ]]; then
meson_opts+=("${option/--disable-/-D}=disabled")
# Video corner, same as with audio
elif [[ $option =~ ^--enable-(cocoa|drm|egl-android|*-drm|*-wayland|*-x11|*-cocoa|gbm|rpi|vdpau|vdpau-*|vaapi|vaapi-*|wayland|x11|xv) ]]; then
meson_opts+=("${option/--enable-/-D}=disabled")
do_simple_print "${orange}Disabling option '${option}' as it's not usable on Windows"'!'"${reset}"
elif [[ $option =~ ^--enable-(caca|d3d11|direct3d|egl|egl-*|plain-gl|gl|gl-*|jpeg|libplacebo|sdl2-video|shaderc|sixel|spirv-cross|vulkan) ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to change this one a bit, as the suite doesn't include sixel (yet) and there's no release that can be grabbed from the repos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also some things to note about SPIRV-Cross, see issue linked in the initial comment on the PR

meson_opts+=("${option/--enable-/-D}=enabled")
elif [[ $option =~ ^--disable-(caca|d3d11|direct3d|egl|egl-*|plain-gl|gl|gl-*|jpeg|libplacebo|sdl2-video|shaderc|sixel|spirv-cross|vulkan) ]]; then
meson_opts+=("${option/--disable-/-D}=disabled")
# hwaccel features
elif [[ $option =~ ^--enable-(android-media-ndk|ios-gl|rpi-mmal|videotoolbox-gl) ]]; then
meson_opts+=("${option/--enable-/-D}=disabled")
do_simple_print "${orange}Disabling option '${option}' as it's not usable on Windows"'!'"${reset}"
elif [[ $option =~ ^--enable-(cuda-hwaccel|cuda-interop|d3d-hwaccel|d3d9-hwaccel|gl-dxinterop-d3d9) ]]; then
meson_opts+=("${option/--enable-/-D}=enabled")
elif [[ $option =~ ^--disable-(cuda-hwaccel|cuda-interop|d3d-hwaccel|d3d9-hwaccel|gl-dxinterop-d3d9) ]]; then
meson_opts+=("${option/--disable-/-D}=disabled")
# Mac-only options, we might as well catch and squash them
elif [[ $option =~ ^--enable-(macos-*|swift-*) ]]; then
meson_opts+=("${option/--enable-/-D}=disabled")
do_simple_print "${orange}Disabling option '${option}' as it's not usable on Windows"'!'"${reset}"
# Manpages corner
elif [[ $option =~ ^--enable-(html-build|manpage-build) ]]; then
meson_opts+=("${option/--enable-/-D}=enabled")
elif [[ $option =~ ^--disable-(html-build|manpage-build) ]]; then
meson_opts+=("${option/--disable-/-D}=disabled")
elif [[ $option =~ ^--enable-pdf-build ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remnant of the old code, which silently and unconditionally disabled PDF doc builds, but this needs to be tested

meson_opts+=("${option/--disable-/-D}=disabled")
do_simple_print "${orange}Disabling PDF manual, currently broken"'!'"${reset}"
elif [[ $option =~ ^--lua=lua* ]]; then
# `meson setup build` does not take kindly to a format not matching lua(jit|\d\.\d)
local luaver="${option/--lua=lua}"
if [[ luaver =~ ^(5|-5) ]]; then
luaver='5.${luaver:-1}'
elif [[ luaver =~ ^jit ]]; then
luaver='jit'
fi
meson_opts+=("-Dlua=lua${luaver}")
# Remove the `-Dlua=enabled` flag if present, since the order of flags matters.
# - `-Dlua=lua5.2 -Dlua=enabled` makes Meson behave like only `-Dlua=enabled` was specified;
# - `-Dlua=enabled -Dlua=lua5.2` makes Meson take lua5.2 if available, erroring otherwise;
meson_opts=("${meson_opts[@]/ -Dlua=enabled}")
elif [[ $option =~ ^--enable-lua ]] && ! [[ "${meson_opts[@]}" =~ -Dlua= ]]; then
meson_opts+=("-Dlua=enabled")
fi
unset option
done
do_simple_print "${meson_opts[@]}"

extra_script pre configure
CFLAGS+=" ${mpv_cflags[*]} -Wno-int-conversion" LDFLAGS+=" ${mpv_ldflags[*]}" \
local old_ldf="$LDFLAGS"
CFLAGS+=" ${mpv_cflags[*]} -Wno-int-conversion" LDFLAGS+=" ${mpv_ldflags[*]} -larchive -lb2 -lzstd" \
RST2MAN="${MINGW_PREFIX}/bin/rst2man" \
RST2HTML="${MINGW_PREFIX}/bin/rst2html" \
RST2PDF="${MINGW_PREFIX}/bin/rst2pdf2" \
PKG_CONFIG="$LOCALDESTDIR/bin/ab-pkg-config" \
log configure /usr/bin/python waf configure \
"--prefix=$LOCALDESTDIR" "--bindir=$LOCALDESTDIR/bin-video" \
"${MPV_OPTS[@]}"
RST2PDF="${MINGW_PREFIX}/bin/rst2pdf2"
mkdir build
PKG_CONFIG="pkgconf --keep-system-libs --keep-system-cflags" CC=${CC/ccache /}.bat CXX=${CXX/ccache /}.bat \
log "meson.setup" meson setup build "${meson_opts[@]}" --prefix="${LOCALDESTDIR}" --bindir="${LOCALDESTDIR}/bin-video" --default-library="${default_lib}" --buildtype=release
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log names are non-standard atm, but I expect there to be more changes required to the Meson calls.
Kept this order for now so that it

  1. doesn't break existing mpv_extra.sh setups
  2. I wanted it to work first, and then adapt it to use the helper functions later

extra_script post configure

replace="LIBPATH_lib\1 = ['${LOCALDESTDIR}/lib','${MINGW_PREFIX}/lib']"
sed -r -i "s:LIBPATH_lib(ass|av(|device|filter)) = .*:$replace:g" ./build/c4che/_cache.py

extra_script pre build
log build /usr/bin/python waf -j "${cpuCount:-1}"
log "meson.compile" meson compile -C build
extra_script post build

extra_script pre install
log install /usr/bin/python waf -j1 install ||
log install /usr/bin/python waf -j1 install
cpuCount=1 log "meson.install" meson install -C build &&
mv "${LOCALDESTDIR}/bin-video/libmpv-2.dll" "$LOCALDESTDIR/bin-video/mpv-2.dll"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find a way to tell Meson I don't want the output file to be named libmpv-2.dll, hence the manual move

extra_script post install

if ! files_exist libavutil.a; then
Expand All @@ -2464,7 +2550,10 @@ if [[ $mpv != n ]] && pc_exists libavcodec libavformat libswscale libavfilter; t
done
fi

unset mpv_ldflags replace PKGCONF_STATIC
LDFLAGS="$old_ldf"
replace=" ${mpv_cflags[*]} -Wno-int-conversion"
CFLAGS="${CFLAGS/$replace}"
unset mpv_ldflags replace PKGCONF_STATIC meson_opts default_lib old_ldf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely happy with this cleanup, but it works:tm:
I'll look into extra-cflags options and similar for Meson

hide_conflicting_libs -R
files_exist share/man/man1/mpv.1 && dos2unix -q "$LOCALDESTDIR"/share/man/man1/mpv.1
! mpv_disabled debug-build &&
Expand Down