Skip to content

Commit

Permalink
c2rust-{build-paths,instrument}: Fix #708 by using #[cfg(unix)] i…
Browse files Browse the repository at this point in the history
…nstead of `if cfg!(unix)`.
  • Loading branch information
kkysen committed Nov 3, 2023
1 parent 3ecaab8 commit d7de704
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions c2rust-build-paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ impl SysRoot {
.split(|c| c.is_ascii_whitespace())
.next()
.unwrap_or_default();
let path = if cfg!(unix) {
#[cfg(unix)]
let path = {
use std::os::unix::ffi::OsStrExt;

OsStr::from_bytes(path)
} else {
};
#[cfg(not(unix))]
let path = {
// Windows is hard, so just require UTF-8
let path = str::from_utf8(path).expect("`rustc --print sysroot` is not UTF-8");
OsStr::new(path)
Expand Down
7 changes: 5 additions & 2 deletions dynamic_instrumentation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ fn resolve_sysroot() -> anyhow::Result<PathBuf> {
.split(|c| c.is_ascii_whitespace())
.next()
.unwrap_or_default();
let path = if cfg!(unix) {
#[cfg(unix)]
let path = {
use std::os::unix::ffi::OsStrExt;

OsStr::from_bytes(path)
} else {
};
#[cfg(not(unix))]
let path = {
// Windows is hard, so just require UTF-8
let path = std::str::from_utf8(path).context("`rustc --print sysroot` is not UTF-8")?;
OsStr::new(path)
Expand Down

0 comments on commit d7de704

Please sign in to comment.