@@ -294,7 +294,9 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
294294 . current_dir ( & cpython_native_dir)
295295 . arg ( format ! (
296296 "--prefix={}/install" ,
297- cpython_native_dir. to_str( ) . unwrap( )
297+ cpython_native_dir
298+ . to_str( )
299+ . ok_or_else( || anyhow!( "non-UTF8 path: {}" , cpython_native_dir. display( ) ) ) ?
298300 ) ) ) ?;
299301
300302 run ( Command :: new ( "make" ) . current_dir ( cpython_native_dir) ) ?;
@@ -310,6 +312,9 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
310312
311313 // Configure CPython with SQLite support
312314 // The CFLAGS and LDFLAGS now include paths to both zlib AND sqlite
315+ let cpython_wasi_dir_str = cpython_wasi_dir
316+ . to_str ( )
317+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , cpython_wasi_dir. display( ) ) ) ?;
313318 run ( Command :: new ( "../../Tools/wasm/wasi-env" )
314319 . env (
315320 "CONFIG_SITE" ,
@@ -318,16 +323,14 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
318323 . env (
319324 "CFLAGS" ,
320325 format ! (
321- "--target=wasm32-wasip2 -fPIC -I{}/deps/include" ,
322- cpython_wasi_dir. display( )
326+ "--target=wasm32-wasip2 -fPIC -I{cpython_wasi_dir_str}/deps/include" ,
323327 ) ,
324328 )
325329 . env ( "WASI_SDK_PATH" , wasi_sdk)
326330 . env (
327331 "LDFLAGS" ,
328332 format ! (
329- "--target=wasm32-wasip2 -L{}/deps/lib" ,
330- cpython_wasi_dir. display( )
333+ "--target=wasm32-wasip2 -L{cpython_wasi_dir_str}/deps/lib" ,
331334 ) ,
332335 )
333336 . current_dir ( & cpython_wasi_dir)
@@ -337,10 +340,9 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
337340 "--host=wasm32-unknown-wasip2" ,
338341 & format ! ( "--build={}" , String :: from_utf8( config_guess) ?) ,
339342 & format ! (
340- "--with-build-python={}/../build/{PYTHON_EXECUTABLE}" ,
341- cpython_wasi_dir. to_str( ) . unwrap( )
343+ "--with-build-python={cpython_wasi_dir_str}/../build/{PYTHON_EXECUTABLE}" ,
342344 ) ,
343- & format ! ( "--prefix={}/install" , cpython_wasi_dir . to_str ( ) . unwrap ( ) ) ,
345+ & format ! ( "--prefix={cpython_wasi_dir_str }/install" ) ,
344346 "--disable-test-modules" ,
345347 "--enable-ipv6" ,
346348 ] ) ) ?;
@@ -577,19 +579,30 @@ fn build_zlib(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
577579 & out_dir,
578580 ) ?;
579581 let src_dir = out_dir. join ( "zlib-1.3.1" ) ;
582+ let install_dir_str = install_dir
583+ . to_str ( )
584+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , install_dir. display( ) ) ) ?;
585+ let ar_path = wasi_sdk. join ( "bin/ar" ) ;
586+ let ar_str = ar_path
587+ . to_str ( )
588+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , ar_path. display( ) ) ) ?;
589+ let cc_path = wasi_sdk. join ( "bin/clang" ) ;
590+ let cc_str = cc_path
591+ . to_str ( )
592+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , cc_path. display( ) ) ) ?;
580593 let mut configure = Command :: new ( "./configure" ) ;
581594 add_compile_envs ( wasi_sdk, & mut configure) ;
582595 configure
583596 . current_dir ( & src_dir)
584597 . arg ( "--static" )
585- . arg ( format ! ( "--prefix={}" , install_dir . display ( ) ) ) ;
598+ . arg ( format ! ( "--prefix={install_dir_str}" ) ) ;
586599 run ( & mut configure) ?;
587600 let mut make = Command :: new ( "make" ) ;
588601 add_compile_envs ( wasi_sdk, & mut make) ;
589602 make. current_dir ( src_dir)
590- . arg ( format ! ( "AR={}" , wasi_sdk . join ( "bin/ar" ) . display ( ) ) )
603+ . arg ( format ! ( "AR={ar_str}" ) )
591604 . arg ( "ARFLAGS=rcs" )
592- . arg ( format ! ( "CC={}" , wasi_sdk . join ( "bin/clang" ) . display ( ) ) )
605+ . arg ( format ! ( "CC={cc_str}" ) )
593606 . arg ( "static" )
594607 . arg ( "install" ) ;
595608 run ( & mut make) ?;
@@ -625,15 +638,24 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
625638 fs:: create_dir_all ( install_dir. join ( "include" ) ) ?;
626639
627640 let sysroot = wasi_sdk. join ( "share/wasi-sysroot" ) ;
628- let sysroot_str = sysroot. to_string_lossy ( ) ;
641+ let sysroot_str = sysroot
642+ . to_str ( )
643+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , sysroot. display( ) ) ) ?;
644+ let install_dir_str = install_dir
645+ . to_str ( )
646+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , install_dir. display( ) ) ) ?;
647+ let ar_path = wasi_sdk. join ( "bin/ar" ) ;
648+ let ar_str = ar_path
649+ . to_str ( )
650+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , ar_path. display( ) ) ) ?;
629651
630652 // SQLite-specific CFLAGS for WASI compatibility
631653 // Note: Don't set SQLITE_THREADSAFE here - let --disable-threadsafe handle it
632654 // to avoid macro redefinition warnings
633655 let sqlite_cflags = format ! (
634656 "--target=wasm32-wasi \
635- --sysroot={sysroot } \
636- -I{sysroot }/include/wasm32-wasip1 \
657+ --sysroot={sysroot_str } \
658+ -I{sysroot_str }/include/wasm32-wasip1 \
637659 -D_WASI_EMULATED_SIGNAL \
638660 -D_WASI_EMULATED_PROCESS_CLOCKS \
639661 -fPIC \
@@ -643,7 +665,6 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
643665 -DSQLITE_OMIT_LOCALTIME \
644666 -DSQLITE_OMIT_RANDOMNESS \
645667 -DSQLITE_OMIT_SHARED_CACHE",
646- sysroot = sysroot_str
647668 ) ;
648669
649670 // Configure SQLite
@@ -657,12 +678,11 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
657678 . env (
658679 "LDFLAGS" ,
659680 format ! (
660- "--target=wasm32-wasip2 --sysroot={sysroot} -L{sysroot}/lib" ,
661- sysroot = sysroot_str
681+ "--target=wasm32-wasip2 --sysroot={sysroot_str} -L{sysroot_str}/lib" ,
662682 ) ,
663683 )
664684 . arg ( "--host=wasm32-wasi" )
665- . arg ( format ! ( "--prefix={}" , install_dir . display ( ) ) )
685+ . arg ( format ! ( "--prefix={install_dir_str}" ) )
666686 . arg ( "--disable-shared" )
667687 . arg ( "--enable-static" )
668688 . arg ( "--disable-readline" )
@@ -678,7 +698,7 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
678698 . env ( "CC" , wasi_sdk. join ( "bin/clang" ) )
679699 . env ( "RANLIB" , wasi_sdk. join ( "bin/ranlib" ) )
680700 . env ( "CFLAGS" , & sqlite_cflags)
681- . arg ( format ! ( "AR={}" , wasi_sdk . join ( "bin/ar" ) . display ( ) ) )
701+ . arg ( format ! ( "AR={ar_str}" ) )
682702 . arg ( "ARFLAGS=rcs" )
683703 . arg ( "libsqlite3.a" ) ; // Build only the static library
684704 run ( & mut make) ?;
0 commit comments