1717
1818const ZSTD_COMPRESSION_LEVEL : i32 = 19 ;
1919
20- #[ cfg( any( target_os = "macos" , target_os = "windows" ) ) ]
21- const PYTHON_EXECUTABLE : & str = "python.exe" ;
22- #[ cfg( not( any( target_os = "macos" , target_os = "windows" ) ) ) ]
23- const PYTHON_EXECUTABLE : & str = "python" ;
24-
2520#[ cfg( target_os = "windows" ) ]
2621const CLANG_EXECUTABLE : & str = "clang.exe" ;
2722#[ cfg( not( target_os = "windows" ) ) ]
@@ -265,24 +260,36 @@ fn add(builder: &mut Builder<impl Write>, root: &Path, path: &Path) -> Result<()
265260 Ok ( ( ) )
266261}
267262
263+ fn find_python_binary ( cpython_dir : & Path ) -> Option < & ' static str > {
264+ for name in [ "python" , "python.exe" ] {
265+ if cpython_dir. join ( name) . is_file ( ) {
266+ return Some ( name) ;
267+ }
268+ }
269+ None
270+ }
271+
268272fn maybe_make_cpython ( repo_dir : & Path , wasi_sdk : & Path ) -> Result < ( ) > {
269273 let cpython_wasi_dir = repo_dir. join ( "cpython/builddir/wasi" ) ;
270274 if !cpython_wasi_dir. join ( "libpython3.14.so" ) . exists ( ) {
271275 if !cpython_wasi_dir. join ( "libpython3.14.a" ) . exists ( ) {
272276 let cpython_native_dir = repo_dir. join ( "cpython/builddir/build" ) ;
273- if !cpython_native_dir . join ( PYTHON_EXECUTABLE ) . exists ( ) {
277+ if let None = find_python_binary ( & cpython_native_dir ) {
274278 fs:: create_dir_all ( & cpython_native_dir) ?;
275279 fs:: create_dir_all ( & cpython_wasi_dir) ?;
276280
277281 run ( Command :: new ( "../../configure" )
278282 . current_dir ( & cpython_native_dir)
279283 . arg ( format ! (
280284 "--prefix={}/install" ,
281- cpython_native_dir. to_str( ) . unwrap( )
285+ & cpython_native_dir. to_str( ) . unwrap( )
282286 ) ) ) ?;
283287
284- run ( Command :: new ( "make" ) . current_dir ( cpython_native_dir) ) ?;
288+ run ( Command :: new ( "make" ) . current_dir ( & cpython_native_dir) ) ?;
285289 }
290+ let Some ( python_executable) = find_python_binary ( & cpython_native_dir) else {
291+ bail ! ( "python binary not found" ) ;
292+ } ;
286293
287294 let config_guess =
288295 run ( Command :: new ( "../../config.guess" ) . current_dir ( & cpython_wasi_dir) ) ?;
@@ -300,7 +307,7 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
300307 "--host=wasm32-unknown-wasip2" ,
301308 & format ! ( "--build={}" , String :: from_utf8( config_guess) ?) ,
302309 & format ! (
303- "--with-build-python={}/../build/{PYTHON_EXECUTABLE }" ,
310+ "--with-build-python={}/../build/{python_executable }" ,
304311 cpython_wasi_dir. to_str( ) . unwrap( )
305312 ) ,
306313 & format ! ( "--prefix={}/install" , cpython_wasi_dir. to_str( ) . unwrap( ) ) ,
0 commit comments