deepspeech-rs
deepspeech-rs copied to clipboard
Cannot build for dynamic loading
Problem:
When we try to build the library with dynamic loading support, it emits the following error at build time:
C:\dev\git\deepspeech-rs> cargo build --features dynamic
Compiling deepspeech v0.9.0 (C:\dev\git\deepspeech-rs)
warning: type `size_t` should have an upper camel case name
--> src\dynamic_bindings.rs:1:10
|
1 | pub type size_t = :: std :: os :: raw :: c_ulong ;
| ^^^^^^ help: convert the identifier to upper camel case: `SizeT`
|
= note: `#[warn(non_camel_case_types)]` on by default
warning: type `DeepSpeech_Error_Codes` should have an upper camel case name
--> src\dynamic_bindings.rs:73:11
|
73 | pub type DeepSpeech_Error_Codes = :: std :: os :: raw :: c_uint ;
| ^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `DeepSpeechErrorCodes`
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> src\dynamic_bindings.rs:79:40
|
79 | let inner = std :: sync :: Arc :: new (libloading :: Library :: new (& path) ?) ;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to previous error; 2 warnings emitted
For more information about this error, try `rustc --explain E0133`.
error: could not compile `deepspeech`
To learn more, run the command again with --verbose.
Environment:
rustc --version --verbose
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-msvc
release: 1.53.0
LLVM version: 12.0.1
After changing the file dynamic_bindings.rs as following it built fine:
--- a/src/dynamic_bindings.rs
+++ b/src/dynamic_bindings.rs
@@ -1,3 +1,7 @@
+#![allow(non_camel_case_types)]
+#![allow(non_upper_case_globals)]
+#![allow(non_snake_case)]
+#![allow(dead_code)]
pub type size_t = :: std :: os :: raw :: c_ulong ;
# [repr (C)] # [repr (align (16))] # [derive (Debug , Copy , Clone)] pub struct max_align_t {
pub __clang_max_align_nonce1 : :: std :: os :: raw :: c_longlong , pub __bindgen_padding_0 : u64 , pub __clang_max_align_nonce2 : u128 ,
@@ -76,7 +80,7 @@ inner : std :: sync :: Arc < libloading :: Library > ,
}
impl LibraryWrapper {
pub fn from_path (path : impl AsRef < std :: ffi :: OsStr >) -> Result < Self , libloading :: Error > {
-let inner = std :: sync :: Arc :: new (libloading :: Library :: new (& path) ?) ;
+let inner = std :: sync :: Arc :: new (unsafe { libloading :: Library :: new (& path) ?} ) ;
Ok (Self { inner })
}
pub unsafe fn DS_ErrorCodeToErrorMessage (& self , aErrorCode : :: std :: os :: raw :: c_int ,) -> Result < * mut :: std :: os :: raw :: c_char , libloading :: Error > {
PS. I know we shouldn't change a binding file by hand, but I'm curious to test this library. 😅