Skip to content

Commit 7a27cd6

Browse files
committed
attempt to fix CI
1 parent d876500 commit 7a27cd6

File tree

5 files changed

+544
-17
lines changed

5 files changed

+544
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ jobs:
4949
role-session-name: github-ci
5050

5151
- name: check
52-
run: cargo check --workspace --all --bins --examples
52+
run: |
53+
cargo check -p wstd -p wstd-axum --target wasm32-wasip2 --all-targets
54+
cargo check -p test-programs
5355
5456
- name: wstd tests
5557
run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 -- --nocapture
@@ -73,10 +75,12 @@ jobs:
7375
run: cargo fmt --all -- --check
7476

7577
- name: Docs
76-
run: cargo doc
78+
run: cargo doc --target wasm32-wasip2
7779

7880
- name: Clippy
79-
run: cargo clippy --all
81+
run: |
82+
cargo clippy -p wstd -p wstd-axum --target wasm32-wasip2 --all-targets
83+
cargo clippy -p test-programs
8084
8185
verify-publish:
8286
name: Verify publish

Cargo.toml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ rust-version.workspace = true
1616
default = ["json"]
1717
json = ["dep:serde", "dep:serde_json"]
1818

19-
[lints.rust]
20-
unexpected_cfgs = { level = "warn", check-cfg = [
21-
'cfg(feature, values("wasip3"))',
22-
] }
23-
2419
[dependencies]
2520
anyhow.workspace = true
2621
async-task.workspace = true
@@ -50,7 +45,12 @@ serde = { workspace = true, features = ["derive"] }
5045
serde_json.workspace = true
5146

5247
[workspace]
53-
members = ["axum", "axum/macro", "macro", "test-programs"]
48+
members = [
49+
"axum",
50+
"axum/macro",
51+
"macro",
52+
"test-programs",
53+
]
5454
resolver = "2"
5555

5656
[workspace.package]
@@ -86,7 +86,7 @@ http-body-util = "0.1.3"
8686
itoa = "1"
8787
pin-project-lite = "0.2.8"
8888
quote = "1.0"
89-
serde = "1"
89+
serde= "1"
9090
serde_json = "1"
9191
serde_qs = "0.15"
9292
sync_wrapper = "1"
@@ -104,4 +104,6 @@ wstd-macro = { path = "./macro", version = "=0.6.6" }
104104

105105
[package.metadata.docs.rs]
106106
all-features = true
107-
targets = ["wasm32-wasip2"]
107+
targets = [
108+
"wasm32-wasip2"
109+
]

src/io/stdio.rs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
use super::{AsyncInputStream, AsyncOutputStream, AsyncRead, AsyncWrite, Result};
2+
use std::cell::LazyCell;
3+
use wasip2::cli::terminal_input::TerminalInput;
4+
use wasip2::cli::terminal_output::TerminalOutput;
5+
6+
/// Use the program's stdin as an `AsyncInputStream`.
7+
#[derive(Debug)]
8+
pub struct Stdin {
9+
stream: AsyncInputStream,
10+
terminput: LazyCell<Option<TerminalInput>>,
11+
}
12+
13+
/// Get the program's stdin for use as an `AsyncInputStream`.
14+
pub fn stdin() -> Stdin {
15+
let stream = AsyncInputStream::new(wasip2::cli::stdin::get_stdin());
16+
Stdin {
17+
stream,
18+
terminput: LazyCell::new(wasip2::cli::terminal_stdin::get_terminal_stdin),
19+
}
20+
}
21+
22+
impl Stdin {
23+
/// Check if stdin is a terminal.
24+
pub fn is_terminal(&self) -> bool {
25+
LazyCell::force(&self.terminput).is_some()
26+
}
27+
28+
/// Get the `AsyncInputStream` used to implement `Stdin`
29+
pub fn into_inner(self) -> AsyncInputStream {
30+
self.stream
31+
}
32+
}
33+
34+
impl AsyncRead for Stdin {
35+
#[inline]
36+
async fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
37+
self.stream.read(buf).await
38+
}
39+
40+
#[inline]
41+
async fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
42+
self.stream.read_to_end(buf).await
43+
}
44+
45+
#[inline]
46+
fn as_async_input_stream(&self) -> Option<&AsyncInputStream> {
47+
Some(&self.stream)
48+
}
49+
}
50+
51+
/// Use the program's stdout as an `AsyncOutputStream`.
52+
#[derive(Debug)]
53+
pub struct Stdout {
54+
stream: AsyncOutputStream,
55+
termoutput: LazyCell<Option<TerminalOutput>>,
56+
}
57+
58+
/// Get the program's stdout for use as an `AsyncOutputStream`.
59+
pub fn stdout() -> Stdout {
60+
let stream = AsyncOutputStream::new(wasip2::cli::stdout::get_stdout());
61+
Stdout {
62+
stream,
63+
termoutput: LazyCell::new(wasip2::cli::terminal_stdout::get_terminal_stdout),
64+
}
65+
}
66+
67+
impl Stdout {
68+
/// Check if stdout is a terminal.
69+
pub fn is_terminal(&self) -> bool {
70+
LazyCell::force(&self.termoutput).is_some()
71+
}
72+
73+
/// Get the `AsyncOutputStream` used to implement `Stdout`
74+
pub fn into_inner(self) -> AsyncOutputStream {
75+
self.stream
76+
}
77+
}
78+
79+
impl AsyncWrite for Stdout {
80+
#[inline]
81+
async fn write(&mut self, buf: &[u8]) -> Result<usize> {
82+
self.stream.write(buf).await
83+
}
84+
85+
#[inline]
86+
async fn flush(&mut self) -> Result<()> {
87+
self.stream.flush().await
88+
}
89+
90+
#[inline]
91+
async fn write_all(&mut self, buf: &[u8]) -> Result<()> {
92+
self.stream.write_all(buf).await
93+
}
94+
95+
#[inline]
96+
fn as_async_output_stream(&self) -> Option<&AsyncOutputStream> {
97+
self.stream.as_async_output_stream()
98+
}
99+
}
100+
101+
/// Use the program's stdout as an `AsyncOutputStream`.
102+
#[derive(Debug)]
103+
pub struct Stderr {
104+
stream: AsyncOutputStream,
105+
termoutput: LazyCell<Option<TerminalOutput>>,
106+
}
107+
108+
/// Get the program's stdout for use as an `AsyncOutputStream`.
109+
pub fn stderr() -> Stderr {
110+
let stream = AsyncOutputStream::new(wasip2::cli::stderr::get_stderr());
111+
Stderr {
112+
stream,
113+
termoutput: LazyCell::new(wasip2::cli::terminal_stderr::get_terminal_stderr),
114+
}
115+
}
116+
117+
impl Stderr {
118+
/// Check if stderr is a terminal.
119+
pub fn is_terminal(&self) -> bool {
120+
LazyCell::force(&self.termoutput).is_some()
121+
}
122+
123+
/// Get the `AsyncOutputStream` used to implement `Stderr`
124+
pub fn into_inner(self) -> AsyncOutputStream {
125+
self.stream
126+
}
127+
}
128+
129+
impl AsyncWrite for Stderr {
130+
#[inline]
131+
async fn write(&mut self, buf: &[u8]) -> Result<usize> {
132+
self.stream.write(buf).await
133+
}
134+
135+
#[inline]
136+
async fn flush(&mut self) -> Result<()> {
137+
self.stream.flush().await
138+
}
139+
140+
#[inline]
141+
async fn write_all(&mut self, buf: &[u8]) -> Result<()> {
142+
self.stream.write_all(buf).await
143+
}
144+
145+
#[inline]
146+
fn as_async_output_stream(&self) -> Option<&AsyncOutputStream> {
147+
self.stream.as_async_output_stream()
148+
}
149+
}
150+
151+
#[cfg(test)]
152+
mod test {
153+
use crate::io::AsyncWrite;
154+
use crate::runtime::block_on;
155+
#[test]
156+
// No internal predicate. Run test with --nocapture and inspect output manually.
157+
fn stdout_println_hello_world() {
158+
block_on(async {
159+
let mut stdout = super::stdout();
160+
let term = if stdout.is_terminal() { "is" } else { "is not" };
161+
stdout
162+
.write_all(format!("hello, world! stdout {term} a terminal\n",).as_bytes())
163+
.await
164+
.unwrap();
165+
})
166+
}
167+
#[test]
168+
// No internal predicate. Run test with --nocapture and inspect output manually.
169+
fn stderr_println_hello_world() {
170+
block_on(async {
171+
let mut stdout = super::stdout();
172+
let term = if stdout.is_terminal() { "is" } else { "is not" };
173+
stdout
174+
.write_all(format!("hello, world! stderr {term} a terminal\n",).as_bytes())
175+
.await
176+
.unwrap();
177+
})
178+
}
179+
}

0 commit comments

Comments
 (0)