orph3usLyre / muddy-waters

A static string obfuscation library for rust projects
Apache License 2.0
73 stars 3 forks source link

Error build on Windows: could not find `unix` in `os` #2

Closed mrauhu closed 8 months ago

mrauhu commented 8 months ago

Hello @orph3usLyre.

I found a bug when building a project with muddy dependency on Windows:

   |
 3 | muddy_init!();
   | ^^^^^^^^^^^^^
   | |
   | could not find `unix` in `os`
   | in this macro invocation
   |
  ::: ...\muddy_macros-0.2.0\src\lib.rs:88:1
   |
88 | pub fn muddy_init(input: TokenStream) -> TokenStream {
   | ---------------------------------------------------- in this expansion of `muddy_init!`
   |

The source of bug is an import of std::os::unix::ffi::OsStrExt without config:

https://github.com/orph3usLyre/muddy-waters/blob/5c08d21b6b2e896bbf5fb91b45f5a929983e1525/muddy_macros/src/internal.rs#L73-L77

Possible solution is:

     #[cfg(unix)]
     use std::os::unix::ffi::OsStrExt;
     #[cfg(wasi)]
     std::os::wasi::ffi::OsStrExt;
     #[cfg(windows)]
     std::os::windows::ffi::OsStrExt;

Please, see the OsStrExt trait implementation: https://doc.rust-lang.org/std/index.html?search=OsStrExt.

Best wishes, Sergey.

orph3usLyre commented 8 months ago

Good catch, thanks! Merged.