svartalf / rust-battery

Rust crate providing cross-platform information about the notebook batteries.
https://crates.io/crates/battery
Apache License 2.0
354 stars 40 forks source link

Build error for target i686-pc-windows-msvc #98

Closed Asthowen closed 1 year ago

Asthowen commented 1 year ago

Hello!

When I build for this target with GitHub action, I get this error:

error[E0793]: reference to packed field is unaligned
   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\battery-0.7.8\src\platform\windows\ffi\mod.rs:113:36
    |
113 |         let device_path = unsafe { (***pdidd).DevicePath.as_ptr() };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
    = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)

error[E0793]: reference to packed field is unaligned
   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\battery-0.7.8\src\platform\windows\ffi\mod.rs:143:17
    |
143 |                 &mut query.BatteryTag as *mut _ as minwindef::LPVOID,
    |                 ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
    = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
anis-dr commented 10 months ago

Hey @Asthowen, how did you solve this issue please?

Asthowen commented 10 months ago

Hello @anis-dr! I've been on the starship fork (https://github.com/starship/rust-battery), the compilation for i686-pc-windows-msvc works with it.

anis-dr commented 10 months ago

Thank you