File tree Expand file tree Collapse file tree 5 files changed +72
-1
lines changed
crates/cpp/tests/symmetric_async Expand file tree Collapse file tree 5 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 11[workspace ]
2- members = [ " async_module" ," sleep" ]
2+ members = [ " async_module" , " main " , " sleep" ]
33resolver = " 2"
Original file line number Diff line number Diff line change 11mod async_module;
2+
3+ async_module:: export!( Guest with_types_in async_module) ;
4+
5+ struct Guest ;
6+
7+ impl async_module:: exports:: test:: test:: string_delay:: Guest for Guest {
8+ async fn forward (
9+ s : String ,
10+ ) -> String {
11+ match s. as_str ( ) {
12+ "A" => "directly returned" . into ( ) ,
13+ "B" => { async_module:: test:: test:: wait:: sleep ( 5_000_000_000 ) . await ;
14+ "after five seconds" . into ( )
15+ }
16+ _ => { async_module:: test:: test:: wait:: sleep ( 1_000_000_000 ) . await ;
17+ "after one second" . into ( )
18+ }
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " main"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ [dependencies ]
7+ async_module = { version = " 0.1.0" , path = " ../async_module" }
8+ symmetric_executor = { version = " 0.1.0" , path = " ../../../../symmetric_executor" }
Original file line number Diff line number Diff line change 1+ use std:: env;
2+
3+ fn main ( ) {
4+ let out = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
5+ println ! (
6+ r"cargo:rustc-link-search={}/../../../deps" ,
7+ out. into_string( ) . unwrap( )
8+ ) ;
9+ }
Original file line number Diff line number Diff line change 1+ #[ link( name = "async_module" ) ]
2+ extern "C" {
3+ pub fn X5BasyncX5DtestX3AtestX2Fstring_delayX00forward ( args : * const ( ) , results : * mut ( ) , ) -> * mut ( ) ;
4+ }
5+
6+ fn main ( ) {
7+ let argument1: [ usize ; 2 ] = [ "A" . as_ptr ( ) as usize , 1 ] ;
8+ let mut result1: [ usize ; 2 ] = [ 0 , 0 ] ;
9+ let handle1 = unsafe {
10+ X5BasyncX5DtestX3AtestX2Fstring_delayX00forward ( ( & argument1 as * const usize ) . cast ( ) , result1. as_mut_ptr ( ) . cast ( ) )
11+ } ;
12+ assert_eq ! ( handle1, core:: ptr:: null_mut( ) ) ;
13+ let vec = unsafe { Vec :: from_raw_parts ( result1[ 0 ] as * mut u8 , result1[ 1 ] , result1[ 1 ] ) } ;
14+ let string = std:: str:: from_utf8 ( & vec) . unwrap ( ) ;
15+ println ! ( "Result {string}" ) ;
16+
17+ let argument2: [ usize ; 2 ] = [ "B" . as_ptr ( ) as usize , 1 ] ;
18+ let mut result2: [ usize ; 2 ] = [ 0 , 0 ] ;
19+ let handle2 = unsafe {
20+ X5BasyncX5DtestX3AtestX2Fstring_delayX00forward ( ( & argument2 as * const usize ) . cast ( ) , result2. as_mut_ptr ( ) . cast ( ) )
21+ } ;
22+ assert_ne ! ( handle2, core:: ptr:: null_mut( ) ) ;
23+ // register cb
24+
25+ let argument3: [ usize ; 2 ] = [ "C" . as_ptr ( ) as usize , 1 ] ;
26+ let mut result3: [ usize ; 2 ] = [ 0 , 0 ] ;
27+ let handle3 = unsafe {
28+ X5BasyncX5DtestX3AtestX2Fstring_delayX00forward ( ( & argument3 as * const usize ) . cast ( ) , result3. as_mut_ptr ( ) . cast ( ) )
29+ } ;
30+ assert_ne ! ( handle3, core:: ptr:: null_mut( ) ) ;
31+ // register cb
32+
33+ // run
34+ }
You can’t perform that action at this time.
0 commit comments