felixc / rexiv2

Rust library for read/write access to media-file metadata (Exif, XMP, and IPTC)
GNU General Public License v3.0
79 stars 17 forks source link

Unable to build project on Windows #59

Closed TechnikTobi closed 1 year ago

TechnikTobi commented 2 years ago

Hi, I’m currently trying to get one of my projects to build on windows (using a GitHub action on a windows-latest runner, so the environment should be easily reproducible) and ran into a problem regarding the libraries usage of some unix-specific functionality (see following error messages).

(This is my first GitHub issue ever, so I am sorry if I missed something critical and I’ll be happy to provide you with any further information required to solve this bug.)

error[E0433]: failed to resolve: could not find `unix` in `os`
   --> C:\Users\runneradmin\.cargo\registry\src\…\rexiv2-0.9.1\src\lib.rs:47:14
   |
47 | use std::os::unix::ffi::OsStrExt;
   |              ^^^^ could not find `unix` in `os`

error[E0599]: no method named `as_bytes` found for reference `&OsStr` in the current scope
   --> C:\Users\runneradmin\.cargo\registry\src\…\rexiv2-0.9.1\src\lib.rs:279:58
    |
279 |         let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
    |                                                          ^^^^^^^^ method not found in `&OsStr`

error[E0599]: no method named `as_bytes` found for reference `&OsStr` in the current scope
   --> C:\Users\runneradmin\.cargo\registry\src\…\src\lib.rs:327:58
    |
327 |         let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
    |                                                          ^^^^^^^^ method not found in `&OsStr`

error[E0599]: no method named `as_bytes` found for reference `&OsStr` in the current scope
   --> C:\Users\runneradmin\.cargo\registry\src\…\src\lib.rs:734:58
    |
734 |         let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
    |                                                          ^^^^^^^^ method not found in `&OsStr`

error[E0599]: no method named `as_bytes` found for reference `&OsStr` in the current scope
   --> C:\Users\runneradmin\.cargo\registry\src\…\rexiv2-0.9.1\src\lib.rs:888:58
    |
888 |         let c_str_path = ffi::CString::new(path.as_ref().as_bytes()).unwrap();
    |                                                          ^^^^^^^^ method not found in `&OsStr`

Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `rexiv2` due to 5 previous errors
felixc commented 2 years ago

Hi, and thanks for the report!

Looks like std::os::unix::ffi::OsStrExt brings in as_bytes() (https://doc.rust-lang.org/std/os/unix/ffi/trait.OsStrExt.html) which is being used here to convert between Rust strings and the CString used to pass data to the underlying C library.

I'm sure there must be a cross-platform way to write this, but I don't have Windows experience or access to a Windows machine, so I don't know it off-hand. A patch to make things cross-platform would be very welcome, if you'd be willing to investigate what the "standard" way of passing CString paths to FFI libraries is. If you're not up for that, no worries, but I might not get to it for a while (busy time right now, unfortunately).

felixc commented 1 year ago

Resolved in #60 -- thanks again!