tazz4843 / whisper-rs

Rust bindings to https://github.com/ggerganov/whisper.cpp
The Unlicense
692 stars 110 forks source link

whisper_gretype mismatch under msvc build #147

Open hlhr202 opened 6 months ago

hlhr202 commented 6 months ago

toolchain: stable-x86_64-pc-windows-msvc (default) rustc 1.76.0 (07dca489a 2024-02-04)

clang: clang version 17.0.6 Target: x86_64-w64-windows-gnu Thread model: posix InstalledDir: C:/msys64/mingw64/bin

cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32824 for x64

when building whisper-rs with whisper-rs-sys, the type mismatched.

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:13:11
   |
13 |     End = whisper_gretype_WHISPER_GRETYPE_END,
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:15:17
   |
15 |     Alternate = whisper_gretype_WHISPER_GRETYPE_ALT,
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:17:21
   |
17 |     RuleReference = whisper_gretype_WHISPER_GRETYPE_RULE_REF,
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:19:17
   |
19 |     Character = whisper_gretype_WHISPER_GRETYPE_CHAR,
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:21:20
   |
21 |     NotCharacter = whisper_gretype_WHISPER_GRETYPE_CHAR_NOT,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:23:27
   |
23 |     CharacterRangeUpper = whisper_gretype_WHISPER_GRETYPE_CHAR_RNG_UPPER,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

error[E0308]: mismatched types
  --> C:\Users\Lenovo\.cargo\git\checkouts\whisper-rs-c8b9fa7c09c8c913\4dca14d\src\whisper_grammar.rs:25:26
   |
25 |     CharacterAlternate = whisper_gretype_WHISPER_GRETYPE_CHAR_ALT,
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `whisper-rs` (lib) due to 7 previous errors

I m wondering the problem came from here

https://github.com/tazz4843/whisper-rs/blob/4dca14d5ec88fb7e420d46789656628b8e191bec/src/whisper_grammar.rs#L9

we should align msvc special type just to be u32

#[cfg_attr(any(not(windows), target_env = "gnu"), repr(u32))] // include windows-gnu
#[cfg_attr(all(windows, not(target_env = "gnu")), repr(u32))] // msvc being *special* again
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum WhisperGrammarElementType {
    /// End of rule definition
    End = whisper_gretype_WHISPER_GRETYPE_END,
    /// Start of alternate definition for a rule
    Alternate = whisper_gretype_WHISPER_GRETYPE_ALT,
    /// Non-terminal element: reference to another rule
    RuleReference = whisper_gretype_WHISPER_GRETYPE_RULE_REF,
    /// Terminal element: character (code point)
    Character = whisper_gretype_WHISPER_GRETYPE_CHAR,
    /// Inverse of a character(s)
    NotCharacter = whisper_gretype_WHISPER_GRETYPE_CHAR_NOT,
    /// Modifies a preceding [Self::Character] to be an inclusive range
    CharacterRangeUpper = whisper_gretype_WHISPER_GRETYPE_CHAR_RNG_UPPER,
    /// Modifies a preceding [Self::Character] to add an alternate character to match
    CharacterAlternate = whisper_gretype_WHISPER_GRETYPE_CHAR_ALT,
}
astral-shpx commented 4 months ago

I'm getting those errors but with the types the other way around with the stable-x86_64-pc-windows-gnu toolchain. No errors if I switch the toolchain to msvc.