Hugal31 / yara-rust

Rust bindings for VirusTotal/Yara
Apache License 2.0
73 stars 29 forks source link

fix: avoid warnings in generated bindings on x64 windows msvc #62

Closed vthib closed 2 years ago

vthib commented 2 years ago

The bindings generated by bindgen on the x86_64-pc-windows-msvc target produces a log of warnings, such as:

warning: `extern` block uses type `u128`, which is not FFI-safe
     |         compiler: *mut YR_COMPILER,
     |                   ^^^^^^^^^^^^^^^^ not FFI-safe
     |
     = note: 128-bit integers don't currently have a known stable ABI

This is due to the fact that:

This is an issue on the bindgen side, which should not use u128 types for alignments. See https://github.com/rust-lang/rust-bindgen/issues/2105

To avoid those warnings however, there is a somewhat simple solution: do not make the YR_COMPILER type opaque, but make opaque all its dependencies. This keeps the size of the generated bindings small, but allows bindgen to expand the definition of jmp_buf, fixing the warnings.

At the same time, some other types whose definitions were not needed have been marked opaque, to reduce the generated codesize a bit more. This includes YR_AC_MATCH and YR_RULES.

Hugal31 commented 2 years ago

LGTM. Thanks!