# escape=`
ARG GST_WINDOWS_IMAGE="registry.freedesktop.org/gstreamer/gstreamer/amd64/windows:2025-09-19.0-main"
FROM ${GST_WINDOWS_IMAGE}

# Make sure any failure in PowerShell is fatal
ENV ErrorActionPreference='Stop'
SHELL ["powershell","-NoLogo", "-NonInteractive", "-Command"]

# The rust version is set by the images_template.yml via GST_RS_STABLE
ARG RUST_VERSION="invalid"

RUN choco install -y pkgconfiglite nasm llvm gperf

RUN pip3 install meson==1.10.1

RUN Invoke-WebRequest -Uri https://win.rustup.rs/x86_64 -OutFile C:\rustup-init.exe
RUN C:\rustup-init.exe -y --profile minimal --default-toolchain $env:RUST_VERSION

# https://stackoverflow.com/a/50716450
RUN setx PATH '%PATH%;C:\Program Files\NASM;C:\gst-install\bin;c:\Program Files\gettext-iconv\bin;C:\Users\ContainerAdministrator\.cargo\bin'
ENV PKG_CONFIG_PATH="C:\gst-install\lib\pkgconfig"

RUN cargo install cargo-c

RUN Invoke-WebRequest -Uri https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.21-v1.16/gettext0.21-iconv1.16-shared-64.exe -OutFile C:\gettext0.21.exe
RUN C:\gettext0.21.exe /SILENT

# Headers and a static library for gettext-sys, which would otherwise
# autotools-build a vendored gettext and fail under MSVC.
#
# This must be the *static* package and GETTEXT_STATIC must be set. GLib falls
# back to proxy-libintl and installs it as C:\gst-install\lib\intl.lib, which
# pkg-config then puts on the link line by absolute path ahead of our LIBPATH.
# proxy-libintl only exports g_libintl_*, so linking dynamically leaves
# gettext/textdomain/bind_textdomain_codeset unresolved. Linking our own copy
# statically resolves them in the executable and leaves proxy-libintl to glib.
RUN Invoke-WebRequest -Uri https://github.com/mlocati/gettext-iconv-windows/releases/download/v1.0-v1.19/gettext1.0-iconv1.19-static-64-dev-msvc.zip -OutFile C:\gettext-dev.zip
RUN Expand-Archive -Path C:\gettext-dev.zip -DestinationPath C:\gettext-dev; Remove-Item C:\gettext-dev.zip
ENV GETTEXT_DIR="C:\gettext-dev"
ENV GETTEXT_STATIC="1"

# This is working with wrap files for GTK and GStreamer but need to build pango first
# Prebuilt to save some compile time on Windows
# The build context is the repository root, so that the GTK patches below can
# come from the same place the gtk wrap applies them from, rather than a copy.
COPY ci/windows-docker/common.ps1 ci/windows-docker/install_pango.ps1 ci/windows-docker/install_gst.ps1 ci/windows-docker/install_gtk.ps1 ci/windows-docker/install_libxml2.ps1 ci/windows-docker/install_openssl.ps1 ci/windows-docker/install_libadwaita.ps1 ci/windows-docker/install_glib.ps1 C:\
COPY subprojects/packagefiles/gtk C:\patches
RUN C:\install_glib.ps1
RUN C:\install_pango.ps1
RUN C:\install_libxml2.ps1
RUN C:\install_gtk.ps1
RUN C:\install_openssl.ps1
RUN C:\install_libadwaita.ps1
RUN C:\install_gst.ps1

# needed by gtk
RUN pip3 install packaging
