germangb / minimp3-rs

minimp3 rust bindings + wrapper
MIT License
65 stars 20 forks source link

Build fails without clang #3

Closed AlexNav73 closed 6 years ago

AlexNav73 commented 6 years ago

Hi, I try to compile the rodio crate with mp3 feature enabled which uses minimp3 crate, but building fails with this error

error: failed to run custom build command for `minimp3-sys v0.2.0`
process didn't exit successfully: `D:\Programms\Rust\melos\target\debug\build\minimp3-sys-ca589f4130bfb632\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any of [\'clang.dll\', \'libclang.dll\'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (skipped: [])"', libcore\result.rs:945:5
stack backtrace:
   0:     0x7ff65253733a - std::sys::windows::backtrace::unwind_backtrace
                               at C:\projects\rust\src\libstd\sys\windows\backtrace\mod.rs:65
   1:     0x7ff6525455af - std::sys_common::backtrace::_print
                               at C:\projects\rust\src\libstd\sys_common\backtrace.rs:71
   2:     0x7ff6525455af - std::sys_common::backtrace::print
                               at C:\projects\rust\src\libstd\sys_common\backtrace.rs:59
   3:     0x7ff65253890e - std::panicking::default_hook::{{closure}}
                               at C:\projects\rust\src\libstd\panicking.rs:207
   4:     0x7ff6525385ba - std::panicking::default_hook
                               at C:\projects\rust\src\libstd\panicking.rs:223
   5:     0x7ff652538ece - std::panicking::rust_panic_with_hook
                               at C:\projects\rust\src\libstd\panicking.rs:402
   6:     0x7ff652538c7f - std::panicking::begin_panic_fmt
                               at C:\projects\rust\src\libstd\panicking.rs:349
   7:     0x7ff652538ba1 - std::panicking::rust_begin_panic
                               at C:\projects\rust\src\libstd\panicking.rs:325
   8:     0x7ff65254b5bc - core::panicking::panic_fmt
                               at C:\projects\rust\src\libcore\panicking.rs:72
   9:     0x7ff6520a1f96 - core::result::unwrap_failed<alloc::string::String>
                               at C:\projects\rust\src\libcore\macros.rs:26
  10:     0x7ff65209bac3 - core::result::Result<(), alloc::string::String>::expect<(),alloc::string::String>
                               at C:\projects\rust\src\libcore\result.rs:809
  11:     0x7ff652053c4d - core::ops::function::FnOnce::call_once<fn() -> alloc::arc::Arc<clang_sys::SharedLibrary>,()>
                               at C:\projects\rust\src\libcore\ops\function.rs:223
  12:     0x7ff65209658a - lazy_static::lazy::{{impl}}::get::{{closure}}<alloc::arc::Arc<clang_sys::SharedLibrary>,fn() -> alloc::arc::Arc<clang_sys::SharedLibrary>>
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.0.1\src\lazy.rs:24
  13:     0x7ff65201303a - std::sync::once::{{impl}}::call_once::{{closure}}<closure>
                               at C:\projects\rust\src\libstd\sync\once.rs:227
  14:     0x7ff652534a51 - std::sync::once::Once::call_inner
                               at C:\projects\rust\src\libstd\sync\once.rs:340
  15:     0x7ff652012de2 - std::sync::once::Once::call_once<closure>
                               at C:\projects\rust\src\libstd\sync\once.rs:227
  16:     0x7ff651fb3e79 - lazy_static::lazy::Lazy<alloc::arc::Arc<clang_sys::SharedLibrary>>::get
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.0.1\src\lazy.rs:23
  17:     0x7ff651fb3e79 - bindgen::ensure_libclang_is_loaded::{{impl}}::deref::__stability
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.37.0\<__lazy_static_internal macros>:13
  18:     0x7ff651fb3e79 - bindgen::ensure_libclang_is_loaded::{{impl}}::deref
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.37.0\<__lazy_static_internal macros>:14
  19:     0x7ff651fad88b - bindgen::ensure_libclang_is_loaded
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.37.0\src\lib.rs:1528
  20:     0x7ff651fad976 - bindgen::Bindings::generate
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.37.0\src\lib.rs:1543
  21:     0x7ff651fac5b3 - bindgen::Builder::generate
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.37.0\src\lib.rs:1102
  22:     0x7ff651f12787 - build_script_build::main
                               at C:\Users\Aliaksandr\.cargo\registry\src\github.com-1ecc6299db9ec823\minimp3-sys-0.2.0\build.rs:10
  23:     0x7ff651f11783 - std::rt::lang_start::{{closure}}<()>
                               at C:\projects\rust\src\libstd\rt.rs:74
  24:     0x7ff652538adc - std::rt::lang_start_internal::{{closure}}
                               at C:\projects\rust\src\libstd\rt.rs:59
  25:     0x7ff652538adc - std::panicking::try::do_call<closure,i32>
                               at C:\projects\rust\src\libstd\panicking.rs:306
  26:     0x7ff6525483f1 - panic_unwind::__rust_maybe_catch_panic
                               at C:\projects\rust\src\libpanic_unwind\lib.rs:102
  27:     0x7ff652536fa2 - std::panicking::try
                               at C:\projects\rust\src\libstd\panicking.rs:285
  28:     0x7ff652536fa2 - std::panic::catch_unwind
                               at C:\projects\rust\src\libstd\panic.rs:361
  29:     0x7ff652536fa2 - std::rt::lang_start_internal
                               at C:\projects\rust\src\libstd\rt.rs:58
  30:     0x7ff651f11753 - std::rt::lang_start<()>
                               at C:\projects\rust\src\libstd\rt.rs:74
  31:     0x7ff651f12a86 - main
  32:     0x7ff65255898b - invoke_main
                               at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  33:     0x7ff65255898b - __scrt_common_main_seh
                               at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
  34:     0x7fffa6061fe3 - BaseThreadInitThunk
  35:     0x7fffa619f060 - RtlUserThreadStart

Is it really nessesary to compile c++ lib with clang not with the default compiler? In my case, with Visual Studio 2017 Build tools

PS D:\Programms\Rust\melos> cargo -vV
cargo 1.26.0 (0e7c5a931 2018-04-06)
release: 1.26.0
commit-hash: 0e7c5a93159076952f609e05760e2458828d0d1f
commit-date: 2018-04-06
PS D:\Programms\Rust\melos> rustc -vV
rustc 1.26.2 (594fb253c 2018-06-01)
binary: rustc
commit-hash: 594fb253c2b02b320c728391a425d028e6dc7a09
commit-date: 2018-06-01
host: x86_64-pc-windows-msvc
release: 1.26.2
LLVM version: 6.0
germangb commented 6 years ago

Libclang is used by bindgen to generate the bindings (in the minimp3-sys crate). This way we don't have to put an ugly auto-generated file in source control...

If you don't want or can't install libclang, You can also try to [patch] minimp3-sys and include the generated bindings in the source. I can help if you need it.

AlexNav73 commented 6 years ago

Oh, that would be great, if you do like in rusqlite.

As of rusqlite 0.10.1, we avoid running bindgen at build-time by shipping pregenerated bindings for several versions of SQLite. When compiling rusqlite, we use your selected Cargo features to pick the bindings for the minimum SQLite version that supports your chosen features. If you are using libsqlite3-sys directly, you can use the same features to choose which pregenerated bindings are chosen: min_sqlite_version_3_6_8 - SQLite 3.6.8 bindings (this is the default) min_sqlite_version_3_6_11 - SQLite 3.6.11 bindings min_sqlite_version_3_6_23 - SQLite 3.6.23 bindings min_sqlite_version_3_7_3 - SQLite 3.7.3 bindings min_sqlite_version_3_7_4 - SQLite 3.7.4 bindings

I think it can help others use this crate and do not to create forks with generated bindings. As a windows user, I will very appreciate that.

Or, if you absolutely don't want to pregenerate bindings, just put in the README.md a requirement for the Clang.

germangb commented 6 years ago

Hi, I just published 0.3 of minimp3 to crates-io. Could you try it with rodio? It should remove the dependency with bindgen.

AlexNav73 commented 6 years ago

Hi, now it compiles and perfectly works, awesome!! Thank you! I'll close this issue and make a PR to rodio with a version bump