Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ prettyplease = "0.2.20"
syn = { version = "2.0.89", features = ["printing"] }
futures = "0.3.31"

wat = "1.238.0"
wasmparser = "0.238.0"
wasm-encoder = "0.238.0"
wasm-metadata = { version = "0.238.0", default-features = false }
wit-parser = "0.238.0"
wit-component = "0.238.0"
wasm-compose = "0.238.0"
wat = "1.239.0"
wasmparser = "0.239.0"
wasm-encoder = "0.239.0"
wasm-metadata = { version = "0.239.0", default-features = false }
wit-parser = "0.239.0"
wit-component = "0.239.0"
wasm-compose = "0.239.0"

wit-bindgen-core = { path = 'crates/core', version = '0.45.1' }
wit-bindgen-c = { path = 'crates/c', version = '0.45.1' }
Expand Down Expand Up @@ -89,3 +89,4 @@ csharp = ['dep:wit-bindgen-csharp']
csharp-mono = ['csharp']
moonbit = ['dep:wit-bindgen-moonbit']
async = []

16 changes: 16 additions & 0 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ typedef enum {snake}_waitable_state {{
}} {snake}_waitable_state_t;

void {snake}_backpressure_set(bool enable);
void {snake}_backpressure_inc(void);
void {snake}_backpressure_dec(void);
void* {snake}_context_get(void);
void {snake}_context_set(void*);
"
Expand Down Expand Up @@ -826,6 +828,20 @@ void {snake}_backpressure_set(bool enable) {{
__backpressure_set(enable);
}}

__attribute__((__import_module__("$root"), __import_name__("[backpressure-inc]")))
extern void __backpressure_inc(void);

void {snake}_backpressure_inc(void) {{
__backpressure_inc();
}}

__attribute__((__import_module__("$root"), __import_name__("[backpressure-dec]")))
extern void __backpressure_dec(void);

void {snake}_backpressure_dec(void) {{
__backpressure_dec();
}}

__attribute__((__import_module__("$root"), __import_name__("[context-get-0]")))
extern void* __context_get(void);

Expand Down
7 changes: 4 additions & 3 deletions crates/guest-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@ pub mod rt;

#[cfg(feature = "async")]
pub use rt::async_support::{
backpressure_set, block_on, spawn, yield_async, yield_blocking, AbiBuffer, FutureRead,
FutureReader, FutureWrite, FutureWriteCancel, FutureWriteError, FutureWriter, StreamRead,
StreamReader, StreamResult, StreamWrite, StreamWriter,
backpressure_dec, backpressure_inc, backpressure_set, block_on, spawn, yield_async,
yield_blocking, AbiBuffer, FutureRead, FutureReader, FutureWrite, FutureWriteCancel,
FutureWriteError, FutureWriter, StreamRead, StreamReader, StreamResult, StreamWrite,
StreamWriter,
};
35 changes: 35 additions & 0 deletions crates/guest-rust/src/rt/async_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ pub async fn yield_async() {
/// When `enabled` is `true`, this tells the host to defer any new calls to this
/// component instance until further notice (i.e. until `backpressure.set` is
/// called again with `enabled` set to `false`).
#[deprecated = "use backpressure_{inc,dec} instead"]
pub fn backpressure_set(enabled: bool) {
#[cfg(not(target_arch = "wasm32"))]
unsafe fn backpressure_set(_: i32) {
Expand All @@ -531,6 +532,40 @@ pub fn backpressure_set(enabled: bool) {
unsafe { backpressure_set(if enabled { 1 } else { 0 }) }
}

/// Call the `backpressure.inc` canonical built-in function.
pub fn backpressure_inc() {
#[cfg(not(target_arch = "wasm32"))]
unsafe fn backpressure_inc() {
unreachable!();
}

#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "$root")]
extern "C" {
#[link_name = "[backpressure-inc]"]
fn backpressure_inc();
}

unsafe { backpressure_inc() }
}

/// Call the `backpressure.dec` canonical built-in function.
pub fn backpressure_dec() {
#[cfg(not(target_arch = "wasm32"))]
unsafe fn backpressure_dec() {
unreachable!();
}

#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "$root")]
extern "C" {
#[link_name = "[backpressure-dec]"]
fn backpressure_dec();
}

unsafe { backpressure_dec() }
}

fn context_get() -> *mut u8 {
#[cfg(not(target_arch = "wasm32"))]
unsafe fn get() -> *mut u8 {
Expand Down
3 changes: 2 additions & 1 deletion tests/runtime-async/async/cancel-import/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl crate::exports::my::test::i::Guest for Component {
}

fn backpressure_set(x: bool) {
wit_bindgen::backpressure_set(x)
#[expect(deprecated)]
return wit_bindgen::backpressure_set(x);
}
}
Loading