slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.12k stars 580 forks source link

ffmpeg example build needs llvm on windows, and this is not documented #4621

Open 0xhellord opened 7 months ago

0xhellord commented 7 months ago

PS E:\Data\Git\slint\examples\ffmpeg> rustc.exe --version
rustc 1.76.0 (07dca489a 2024-02-04)

PS E:\Data\Git\slint\examples\ffmpeg> vcpkg --version
vcpkg package management program version 2024-02-07-8a83681f921b10d86ae626fd833c253f4f8c355b

See LICENSE.txt for license information.

PS E:\Data\Git\slint\examples\ffmpeg> rustup.exe check 
stable-x86_64-pc-windows-msvc - Up to date : 1.76.0 (07dca489a 2024-02-04)
rustup - Up to date : 1.26.0

PS E:\Data\Git\slint\examples\ffmpeg> vcpkg install ffmpeg --triplet x64-windows
Computing installation plan...
The following packages are already installed:
    ffmpeg[core,zlib,xml2,x265,x264,webp,vpx,vorbis,theora,tesseract,swscale,swresample,ssh,srt,speex,soxr,snappy,sdl2,qsv,postproc,opus,openssl,openmpt,openjpeg,openh264,opengl,opencl,nvcodec,nonfree,mp3lame,modplug,lzma,ilbc,iconv,gpl,fribidi,freetype,fontconfig,fdk-aac,dav1d,bzip2,avisynthplus,avformat,avfilter,avdevice,avcodec,ass,aom,amf,all-nonfree,all-gpl,all]:x64-windows@6.1.1
ffmpeg:x64-windows is already installed
Total install time: 142 us
To use ffmpeg add the following to your CMake project:

    find_package(FFMPEG REQUIRED)
    target_include_directories(main PRIVATE ${FFMPEG_INCLUDE_DIRS})
    target_link_directories(main PRIVATE ${FFMPEG_LIBRARY_DIRS})
    target_link_libraries(main PRIVATE ${FFMPEG_LIBRARIES})

PS E:\Data\Git\slint\examples\ffmpeg> vcpkg list|select-string ffmpeg

ffmpeg:x64-windows                                6.1.1               a library to decode, encode, transcode, mux, dem...
ffmpeg:x64-windows-static                         6.1.1               a library to decode, encode, transcode, mux, dem...
ffmpeg:x64-windows-static-md                      6.1.1               a library to decode, encode, transcode, mux, dem...
ffmpeg:x86-windows                                6.1.1               a library to decode, encode, transcode, mux, dem...
ffmpeg:x86-windows-static                         6.1.1               a library to decode, encode, transcode, mux, dem...
ffmpeg:x86-windows-static-md                      6.1.1               a library to decode, encode, transcode, mux, dem...

PS E:\Data\Git\slint\examples\ffmpeg> cargo build
   Compiling ffmpeg-sys-next v6.1.0
The following warnings were emitted during compilation:

warning: ffmpeg-sys-next@6.1.0: vcpkg gave up trying to resolve pkg-config ordering.

error: failed to run custom build command for `ffmpeg-sys-next v6.1.0`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `E:\Data\Git\slint\target\debug\build\ffmpeg-sys-next-a66522e5d046651d\build-script-build` (exit code: 101)

PS E:\Data\Git\slint\examples\ffmpeg> $env:RUST_BACKTRACE='full'
PS E:\Data\Git\slint\examples\ffmpeg> E:\Data\Git\slint\target\debug\build\ffmpeg-sys-next-a66522e5d046651d\build-script-build
Could not find ffmpeg with vcpkg: the vcpkg-rs Vcpkg build helper can only find libraries built for the MSVC ABI.
cargo:rerun-if-env-changed=LIBAVUTIL_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
thread 'main' panicked at C:\Users\t70sa\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ffmpeg-sys-next-6.1.0\build.rs:716:14:
called `Result::unwrap()` on an `Err` value: Could not run `PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags libavutil`
The pkg-config command could not be found.

Most likely, you need to install a pkg-config package for your OS.

If you've already installed it, ensure the pkg-config command is one of the
directories in the PATH environment variable.

If you did not expect this build to link to a pre-installed system library,
then check documentation of the sys crate for an option to
build the library from source, or disable features or dependencies
that require pkg-config.
stack backtrace:
   0:     0x7ff6f5e9adb3 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff6f5ebdadd - core::fmt::rt::Argument::fmt
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\fmt\rt.rs:142
   2:     0x7ff6f5ebdadd - core::fmt::write
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\fmt\mod.rs:1120
   3:     0x7ff6f5e96101 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\io\mod.rs:1762
   4:     0x7ff6f5e9abba - std::sys_common::backtrace::_print
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff6f5e9abba - std::sys_common::backtrace::print
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff6f5e9d3b9 - std::panicking::default_hook::closure$1
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:272
   7:     0x7ff6f5e9d07b - std::panicking::default_hook
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:292
   8:     0x7ff6f5e9d8a4 - std::panicking::rust_panic_with_hook
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:779
   9:     0x7ff6f5e9d775 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:657
  10:     0x7ff6f5e9b6a9 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\sys_common\backtrace.rs:170
  11:     0x7ff6f5e9d484 - std::panicking::begin_panic_handler
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:645
  12:     0x7ff6f5ec64b7 - core::panicking::panic_fmt
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:72
  13:     0x7ff6f5ec6a73 - core::result::unwrap_failed
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\result.rs:1653
  14:     0x7ff6f5906e23 - core::result::Result<T,E>::unwrap::h3741b931bdc2a877
  15:     0x7ff6f58fe549 - build_script_build::link_to_libraries::{{closure}}::hadfac78533e32300
  16:     0x7ff6f59053b6 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2dcc0455ffc5c157
  17:     0x7ff6f59048d9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9e067861d57ac2b2
  18:     0x7ff6f58f163c - std::rt::lang_start::{{closure}}::h4f026511804cc790
  19:     0x7ff6f5e918e8 - std::rt::lang_start_internal::closure$2
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\rt.rs:148
  20:     0x7ff6f5e918e8 - std::panicking::try::do_call
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:552
  21:     0x7ff6f5e918e8 - std::panicking::try
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:516
  22:     0x7ff6f5e918e8 - std::panic::catch_unwind
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panic.rs:142
  23:     0x7ff6f5e918e8 - std::rt::lang_start_internal
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\rt.rs:148
  24:     0x7ff6f58f1617 - std::rt::lang_start::h1cf78d0e563682df
  25:     0x7ff6f5904559 - main
  26:     0x7ff6f5ec3df0 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  27:     0x7ff6f5ec3df0 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  28:     0x7ffc1f9e257d - BaseThreadInitThunk
  29:     0x7ffc2058aa58 - RtlUserThreadStart

VCPKG_ROOT set to E:\DevEnv\Library\vcpkg.

ogoffart commented 7 months ago

The error message is telling you that you are missing dependencies. In this case pkg-config needed to get ffmpeg.

Did you follow the instructions from https://github.com/slint-ui/slint/tree/master/examples/ffmpeg#building ? Maybe it is missing an instruction on how to install pkg-config?

0xhellord commented 7 months ago

The error message is telling you that you are missing dependencies. In this case pkg-config needed to get ffmpeg.

Did you follow the instructions from https://github.com/slint-ui/slint/tree/master/examples/ffmpeg#building ? Maybe it is missing an instruction on how to install pkg-config?

Yes, I followed the instructions in the documentation.

I think the pkg-config in the error message is somewhat misleading.

The build.rs in ffmpeg-sys-next shows that if vcpkg failed, then fall back to pkg-config. On Windows, vcpkg should be preferred over pkg-config, as using pkg-config on Windows is particularly troublesome. It seems that the issue here is, why ffmpeg can be found in the vcpkg list, but ffmpeg-sys-next's try_vcpkg cannot find it.

image

I've also tried setting the FFMPEG_DIR environment variable, but it still doesn't work.

0xhellord commented 7 months ago

I plan to add some logs in ffmpeg-sys-next's build.rs and in vcpkg_rs to see what exactly is happening.

0xhellord commented 7 months ago

@ogoffart I found the reason, it requires llvm. I performed these steps and then it compiled successfully: vcpkg install llvm[clang,target-x86]:x64-windows, then set the environment variable LIBCLANG_PATH to E:\DevEnv\Library\vcpkg\installed\x64-windows\bin