fix: exclude APIs that dup given file descriptors from WASI builds
WASI doesn't support `dup(2)` system call, so we cannot implement the
`print_dot_graph` and `print_dot_graphs` functions with exactly the same
semantics as in other platforms.
(cherry picked from commit 94a8262110)
This commit is contained in:
parent
d10308528d
commit
bf094bd98a
3 changed files with 15 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
|||
#[cfg(not(feature = "bindgen"))]
|
||||
include!("./bindings.rs");
|
||||
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
#[cfg(unix)]
|
||||
#[cfg(feature = "std")]
|
||||
extern "C" {
|
||||
pub(crate) fn _ts_dup(fd: std::os::raw::c_int) -> std::os::raw::c_int;
|
||||
|
|
|
|||
|
|
@ -548,13 +548,14 @@ impl Parser {
|
|||
/// want to pipe these graphs directly to a `dot(1)` process in order to
|
||||
/// generate SVG output.
|
||||
#[doc(alias = "ts_parser_print_dot_graphs")]
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
#[cfg(feature = "std")]
|
||||
pub fn print_dot_graphs(
|
||||
&mut self,
|
||||
#[cfg(any(unix, target_os = "wasi"))] file: &impl AsRawFd,
|
||||
#[cfg(unix)] file: &impl AsRawFd,
|
||||
#[cfg(windows)] file: &impl AsRawHandle,
|
||||
) {
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let fd = file.as_raw_fd();
|
||||
unsafe {
|
||||
|
|
@ -946,13 +947,14 @@ impl Tree {
|
|||
/// graph directly to a `dot(1)` process in order to generate SVG
|
||||
/// output.
|
||||
#[doc(alias = "ts_tree_print_dot_graph")]
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
#[cfg(feature = "std")]
|
||||
pub fn print_dot_graph(
|
||||
&self,
|
||||
#[cfg(any(unix, target_os = "wasi"))] file: &impl AsRawFd,
|
||||
#[cfg(unix)] file: &impl AsRawFd,
|
||||
#[cfg(windows)] file: &impl AsRawHandle,
|
||||
) {
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let fd = file.as_raw_fd();
|
||||
unsafe { ffi::ts_tree_print_dot_graph(self.0.as_ptr(), fd) }
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ void ts_tree_print_dot_graph(const TSTree *self, int fd) {
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
#else
|
||||
#elif !defined(__wasi__) // WASI doesn't support dup
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -162,4 +162,11 @@ void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor) {
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor) {
|
||||
(void)self;
|
||||
(void)file_descriptor;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue