I looked into this a bit. I think I'm basically on the right track, but it would be so much work to see it through, so I didn't.
The problem is ffmpeg-sys-next using a check program to do feature detection of `FF_API_*` deprecation guards and generate a bunch of feature flags like `ff_api_vaapi`: https://github.com/zmwangx/rust-ffmpeg-sys/blob/aaccc155d1dc0d21751a80d676fcf5d82075cdc7/build.rs#L319-L469
The check program of course has to run on the host to be of any use in the compilation process, but during cross compilation it is built by a cross compiler for the target (linux in this case), so it won't run. Note that we're actually only checking macros and printing info so basically only cpp and stdio are involved, so in theory there might be a workaround... In practice I can think of writing a hell lot of code for almost nothing.
But no matter, the feature flags aren't actually used much since ffmpeg-sys switched to using bindgen, and when I forked the project I basically decided to use explicit version flags instead of relying on flags generated by the feature detection anyway (because I didn't look very closely at ffmpeg-sys...). So `check_features` related code can be removed and we only have to fix `ffmpeg-next` a little (I only noticed problems due to `ff_api_vaapi` missing; note that `FF_API_VAAPI` is defined as `(LIBAVUTIL_VERSION_MAJOR < 57)` in `libavutil/version.h`, and since `LIBAVUTIL_VERSION_MAJOR` is 56 for FFmpeg 4, so far it's always set). Here are the patches for `rust-ffmpeg-sys` and `rust-ffmpeg`:
https://gist.githubusercontent.com/zmwangx/2421192066afcb972dd26e31f0b3a124/raw/26213510f332c8b2bda7ee93a120697fd38b2325/rust-ffmpeg-sys.patch
https://gist.githubusercontent.com/zmwangx/2421192066afcb972dd26e31f0b3a124/raw/26213510f332c8b2bda7ee93a120697fd38b2325/rust-ffmpeg.patch
With these patches, in theory cross compilation could proceed.
Then I actually tried:
- Installed `musl-cross`: `brew install FiloSottile/musl-cross/musl-cross`;
- Configured the linker in `.cargo/config`:
```toml
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
```
- Got no interest in cross compiling FFmpeg, so I downloaded prebuilt packages from alpine:
- http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/ffmpeg-dev-4.2.3-r1.apk
- http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/ffmpeg-libs-4.2.3-r1.apk
Unpacked into a prefix, say `/tmp/ffmpeg-alpine`.
Had to fix up all the paths in `usr/lib/pkgconfig/*.pc` (with sed).
- Compile:
```
PKG_CONFIG_PATH=/tmp/ffmpeg-alpine/usr/lib/pkgconfig PKG_CONFIG_ALLOW_CROSS=1 cargo build -vv --target x86_64-unknown-linux-musl --examples
```
A million errors generated (as expected, since all the dynamic libraries `ffmpeg-libs` depends on are missing):
```
/usr/local/Cellar/musl-cross/0.9.9/libexec/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/bin/ld: warning: libva-drm.so.2, needed by /tmp/ffmpeg-alpine/usr/lib/libavutil.so, not found (try using -rpath or -rpath-link)
...
/usr/local/Cellar/musl-cross/0.9.9/libexec/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/bin/ld: /tmp/ffmpeg-alpine/usr/lib/libavformat.so: undefined reference to `gnutls_init@GNUTLS_3_4'
...
```
But at least we got past the compiler stage, and apparently the linker is looking into the right things.
Now, just need to download the myriad deps, and deps of deps...
---
Okay that was rough. I would just compile things natively in Docker. Any reason you can't?
warning: `extern` block uses type `u128`, which is not FFI-safe
===============================================================
Just want to document this as a known issue. Whenever `ffmpeg-sys-next` is being built, rustc dumps tons of warnings:
```
warning: `extern` block uses type `u128`, which is not FFI-safe
--> .../binding.rs:...
|
| ... u128
| ^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
```
This is https://github.com/rust-lang/rust-bindgen/issues/1549, and above my pay grade to fix.
I’m not working on it and actually prefer to spend as little time as possible here, so yes please! You can use the wiki, I’ll eventually link to wiki articles from README.
Oh, didn’t notice you’re cross compiling.
At a minimum you need to set `PKG_CONFIG_ALLOW_CROSS=1`.
https://docs.rs/pkg-config/0.3.17/pkg_config/enum.Error.html#variant.CrossCompilation
I haven’t tried to cross compile myself so not sure if you’ll run into other problems, don’t have time to check. Let me know how it goes.