Skip to content

Commit

Permalink
more stream prototype implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Dec 9, 2024
1 parent 9924843 commit 289d2f8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 15 deletions.
4 changes: 4 additions & 0 deletions crates/cpp/tests/symmetric_stream/Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cpp/tests/symmetric_stream/main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
stream = { version = "0.1.0", path = "../stream" }
9 changes: 9 additions & 0 deletions crates/cpp/tests/symmetric_stream/main/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::env;

fn main() {
let out = env::var_os("OUT_DIR").unwrap();
println!(
r"cargo:rustc-link-search={}/../../../deps",
out.into_string().unwrap()
);
}
14 changes: 13 additions & 1 deletion crates/cpp/tests/symmetric_stream/main/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// use wit_bindgen_symmetric_rt::{CallbackState, EventSubscription};

#[link(name = "stream")]
extern "C" {
pub fn testX3AtestX2Fstream_testX00X5BasyncX5Dcreate(
args: *const (),
results: *mut (),
) -> *mut ();
}

fn main() {
println!("Hello, world!");
let mut result_stream: *mut () = core::ptr::null_mut();
let handle = unsafe { testX3AtestX2Fstream_testX00X5BasyncX5Dcreate(core::ptr::null_mut(), (&mut result_stream as *mut *mut ()).cast()) };
assert!(handle.is_null());
}
3 changes: 3 additions & 0 deletions crates/cpp/tests/symmetric_stream/source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]

[lib]
crate-type = ["cdylib"]
16 changes: 4 additions & 12 deletions crates/cpp/tests/symmetric_stream/source/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;
#[allow(non_snake_case)]

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
#[no_mangle]
pub fn testX3AtestX2Fstream_sourceX00X5BasyncX5Dcreate(_args:*mut u8, _results:*mut u8) -> *mut u8 {
todo!()
}
4 changes: 4 additions & 0 deletions crates/cpp/tests/symmetric_stream/stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ edition = "2021"

[dependencies]
futures = "0.3.31"
source = { version = "0.1.0", path = "../source" }
wit-bindgen = { version = "0.36.0", path = "../../../../guest-rust" }
wit-bindgen-rt = { version = "0.36.0", path = "../../../../guest-rust/rt" }

[lib]
crate-type = ["cdylib"]
9 changes: 9 additions & 0 deletions crates/cpp/tests/symmetric_stream/stream/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::env;

fn main() {
let out = env::var_os("OUT_DIR").unwrap();
println!(
r"cargo:rustc-link-search={}/../../../deps",
out.into_string().unwrap()
);
}
5 changes: 3 additions & 2 deletions crates/cpp/tests/symmetric_stream/stream/src/stream_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub mod test {
let ptr1 = _rt::alloc::alloc(layout1);

#[link(wasm_import_module = "test:test/stream-source")]
#[link(name="source")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[async]create")]
fn testX3AtestX2Fstream_sourceX00X5BasyncX5Dcreate(_: *mut u8, _: *mut u8, ) -> i32;
Expand Down Expand Up @@ -200,7 +201,7 @@ pub mod exports {
#[cfg_attr(target_arch = "wasm32", link_name = "[task-return]create")]
fn X5BexportX5DtestX3AtestX2Fstream_testX00X5Btask_returnX5Dcreate(_: i32, );
}
X5BexportX5DtestX3AtestX2Fstream_testX00X5Btask_returnX5Dcreate((result1).into_handle() as i32);
// X5BexportX5DtestX3AtestX2Fstream_testX00X5Btask_returnX5Dcreate((result1).into_handle() as i32);
});

result
Expand All @@ -220,7 +221,7 @@ pub mod exports {

#[cfg_attr(target_arch = "wasm32", export_name = "create")]
#[cfg_attr(not(target_arch = "wasm32"), no_mangle)]
unsafe extern "C" fn testX3AtestX2Fstream_testX00create() -> *mut u8 {
unsafe extern "C" fn testX3AtestX2Fstream_testX00X5BasyncX5Dcreate(args: *mut u8, results: *mut u8) -> *mut u8 {
$($path_to_types)*::_export_create_cabi::<$ty>()
}
#[export_name = "[callback]create"]
Expand Down

0 comments on commit 289d2f8

Please sign in to comment.