File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 55 clap:: Parser ,
66 std:: {
77 env, fs,
8- io:: Cursor ,
8+ io:: { self , Cursor , Seek } ,
99 path:: { Path , PathBuf } ,
1010 process:: Command ,
1111 str,
@@ -105,6 +105,17 @@ fn main() -> Result<()> {
105105 )
106106 }
107107
108+ // Spawn a subcommand to do the real work. This gives us an opportunity to clear the environment so that
109+ // build-time environment variables don't end up in the Wasm module we're building.
110+ //
111+ // Note that we need to use temporary files for stdio instead of the default inheriting behavior since (as
112+ // of this writing) CPython interacts poorly with Wasmtime's WASI implementation if any of the stdio
113+ // descriptors point to non-files on Windows. Specifically, the WASI implementation will trap when CPython
114+ // calls `fd_filestat_get` on non-files.
115+
116+ let mut stdout = tempfile:: tempfile ( ) ?;
117+ let mut stderr = tempfile:: tempfile ( ) ?;
118+
108119 let status = Command :: new ( env:: args ( ) . next ( ) . unwrap ( ) )
109120 . env_clear ( )
110121 . env ( "SPIN_PYTHON_WIZEN" , "1" )
@@ -116,9 +127,18 @@ fn main() -> Result<()> {
116127 )
117128 . arg ( & python_path)
118129 . arg ( & options. output )
130+ . stdin ( tempfile:: tempfile ( ) ?)
131+ . stdout ( stdout. try_clone ( ) ?)
132+ . stderr ( stderr. try_clone ( ) ?)
119133 . status ( ) ?;
120134
121135 if !status. success ( ) {
136+ stdout. rewind ( ) ?;
137+ io:: copy ( & mut stdout, & mut io:: stdout ( ) . lock ( ) ) ?;
138+
139+ stderr. rewind ( ) ?;
140+ io:: copy ( & mut stderr, & mut io:: stderr ( ) . lock ( ) ) ?;
141+
122142 bail ! ( "Couldn't create wasm from input" ) ;
123143 }
124144
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ crate-type = [ "cdylib" ]
1111anyhow = " 1"
1212bytes = { version = " 1.2.1" , features = [" serde" ] }
1313http = " 0.2"
14- spin-sdk = { git = " https://github.com/fermyon/spin" }
14+ spin-sdk = { git = " https://github.com/fermyon/spin" , default-features = false }
1515wit-bindgen-rust = { git = " https://github.com/bytecodealliance/wit-bindgen" , rev = " dde4694aaa6acf9370206527a798ac4ba6a8c5b8" }
1616pyo3 = { version = " 0.17.3" , features = [ " abi3-py310" ] }
1717once_cell = " 1.16.0"
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ thread_local! {
2424 static ENVIRON : OnceCell <Py <PyMapping >> = OnceCell :: new( ) ;
2525}
2626
27+ #[ export_name = "spin-sdk-language-python" ]
28+ extern "C" fn __spin_sdk_language ( ) { }
29+
2730fn bytes ( py : Python < ' _ > , src : & [ u8 ] ) -> PyResult < Py < PyBytes > > {
2831 Ok ( PyBytes :: new_with ( py, src. len ( ) , |dst| {
2932 dst. copy_from_slice ( src) ;
You can’t perform that action at this time.
0 commit comments