fix: cross-compiling to *-pc-windows-* from a non-Windows host - #132
Open
Alexigbokwe wants to merge 2 commits into
Open
Alexigbokwe wants to merge 2 commits into
Alexigbokwe wants to merge 2 commits into
Conversation
FFmpeg's configure rejects --target-os=windows (Unknown OS 'windows'); it needs mingw32/mingw64 for GNU or win32/win64 for MSVC. Derive the right name from TARGET_ENV + pointer width so cross-compiling to *-pc-windows-* works.
A build script's #[cfg] resolves for the HOST, so #[cfg(not(target_env=msvc))]
wrongly forced --enable-pthreads when cross-compiling Linux -> Windows, which
then failed ('pthreads requested but not found', no pthread lib on MinGW).
Windows uses native w32threads; gate on CARGO_CFG_TARGET_{ENV,OS}.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two bugs prevent cross-compiling the vendored FFmpeg (the
buildfeature) to a Windows target from a non-Windows host (e.g. Linux →x86_64-pc-windows-gnu, as CI images do for official builds).1.
--target-os=windowsis not a valid FFmpeg OSget_ffmpeg_target_os()returns Rust'sCARGO_CFG_TARGET_OSverbatim, which is"windows". FFmpeg'sconfigurehas nowindowsOS and aborts:FFmpeg expects
mingw32/mingw64(GNU) orwin32/win64(MSVC). This PR maps thewindowstarget to the right name fromCARGO_CFG_TARGET_ENV+ pointer width.2.
--enable-pthreadsis gated by a build-script#[cfg], which resolves for the HOSTA build script's
#[cfg(...)]is evaluated for the host, not the target being built. Cross-compiling from a non-MSVC host (Linux) therefore always adds--enable-pthreads, even when targeting Windows — where MinGW has no pthread library by default, soconfigurefails:Windows uses native w32threads. This PR gates the flag on the target via
CARGO_CFG_TARGET_{ENV,OS}env vars (the correct way to branch on the target inside a build script), skipping--enable-pthreadsfor any Windows target; FFmpeg then auto-selects w32threads.Result
With both fixes, cross-compiling from Linux with the MinGW-w64 toolchain (
--cross-prefix=x86_64-w64-mingw32-, posix-threads variant) configures and builds FFmpeg cleanly forx86_64-pc-windows-gnu, producing a working, self-contained cdylib.Note (not in this PR)
There is a further cross-bindgen wrinkle: with the Windows target, the
hwcontext_wrapper.hD3D11VA/D3D12VA blocks pull in Windows SDK headers (windows.hintrinsics / a missingd3d12sdklayers.h). I worked around it downstream by disabling those blocks, but a proper upstream fix (e.g. gating the D3D blocks on non-cross, or completing the guard suppression) is better decided by maintainers — happy to follow up separately.