From 0f125e2d09ac4811b22a842e8bafdc9d43c5d51a Mon Sep 17 00:00:00 2001 From: Liam Rosenfeld Date: Tue, 23 Apr 2024 10:13:38 -0400 Subject: [PATCH] fix(rust): use unix + wasi cfg instead of not windows for fd --- lib/binding_rust/ffi.rs | 2 +- lib/binding_rust/lib.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/binding_rust/ffi.rs b/lib/binding_rust/ffi.rs index 001458ee..9168de1b 100644 --- a/lib/binding_rust/ffi.rs +++ b/lib/binding_rust/ffi.rs @@ -8,7 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); #[cfg(not(feature = "bindgen"))] include!("./bindings.rs"); -#[cfg(not(windows))] +#[cfg(any(unix, target_os = "wasi"))] extern "C" { pub(crate) fn _ts_dup(fd: std::os::raw::c_int) -> std::os::raw::c_int; } diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 68d294d1..3ec3b6b0 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -3,7 +3,7 @@ pub mod ffi; mod util; -#[cfg(not(windows))] +#[cfg(any(unix, target_os = "wasi"))] use std::os::fd::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawHandle; @@ -533,10 +533,10 @@ impl Parser { #[doc(alias = "ts_parser_print_dot_graphs")] pub fn print_dot_graphs( &mut self, - #[cfg(not(windows))] file: &impl AsRawFd, + #[cfg(any(unix, target_os = "wasi"))] file: &impl AsRawFd, #[cfg(windows)] file: &impl AsRawHandle, ) { - #[cfg(not(windows))] + #[cfg(any(unix, target_os = "wasi"))] { let fd = file.as_raw_fd(); unsafe { @@ -942,10 +942,10 @@ impl Tree { #[doc(alias = "ts_tree_print_dot_graph")] pub fn print_dot_graph( &self, - #[cfg(not(windows))] file: &impl AsRawFd, + #[cfg(any(unix, target_os = "wasi"))] file: &impl AsRawFd, #[cfg(windows)] file: &impl AsRawHandle, ) { - #[cfg(not(windows))] + #[cfg(any(unix, target_os = "wasi"))] { let fd = file.as_raw_fd(); unsafe { ffi::ts_tree_print_dot_graph(self.0.as_ptr(), fd) }