@@ -294,7 +294,10 @@ 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. to_str( ) . ok_or_else( || anyhow!(
298+ "non-UTF8 path: {}" ,
299+ cpython_native_dir. display( )
300+ ) ) ?
298301 ) ) ) ?;
299302
300303 run ( Command :: new ( "make" ) . current_dir ( cpython_native_dir) ) ?;
@@ -310,7 +313,7 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
310313
311314 let dir = cpython_wasi_dir
312315 . to_str ( )
313- . ok_or_else ( || anyhow ! ( "non-utf8 path: {}" , cpython_wasi_dir. display( ) ) ) ?;
316+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , cpython_wasi_dir. display( ) ) ) ?;
314317
315318 // Configure CPython with SQLite support
316319 // The CFLAGS and LDFLAGS now include paths to both zlib AND sqlite
@@ -321,24 +324,21 @@ fn maybe_make_cpython(repo_dir: &Path, wasi_sdk: &Path) -> Result<()> {
321324 )
322325 . env (
323326 "CFLAGS" ,
324- format ! ( "--target=wasm32-wasip2 -fPIC -I{dir}/deps/include" , ) ,
327+ format ! ( "--target=wasm32-wasip2 -fPIC -I{dir}/deps/include" ) ,
325328 )
326329 . env ( "WASI_SDK_PATH" , wasi_sdk)
327330 . env (
328331 "LDFLAGS" ,
329- format ! ( "--target=wasm32-wasip2 -L{dir}/deps/lib" , ) ,
332+ format ! ( "--target=wasm32-wasip2 -L{dir}/deps/lib" ) ,
330333 )
331334 . current_dir ( & cpython_wasi_dir)
332335 . args ( [
333336 "../../configure" ,
334337 "-C" ,
335338 "--host=wasm32-unknown-wasip2" ,
336339 & format ! ( "--build={}" , String :: from_utf8( config_guess) ?) ,
337- & format ! (
338- "--with-build-python={}/../build/{PYTHON_EXECUTABLE}" ,
339- cpython_wasi_dir. to_str( ) . unwrap( )
340- ) ,
341- & format ! ( "--prefix={}/install" , cpython_wasi_dir. to_str( ) . unwrap( ) ) ,
340+ & format ! ( "--with-build-python={dir}/../build/{PYTHON_EXECUTABLE}" , ) ,
341+ & format ! ( "--prefix={dir}/install" ) ,
342342 "--disable-test-modules" ,
343343 "--enable-ipv6" ,
344344 ] ) ) ?;
@@ -578,7 +578,7 @@ fn build_zlib(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
578578
579579 let prefix = install_dir
580580 . to_str ( )
581- . ok_or_else ( || anyhow ! ( "non-utf8 path: {}" , install_dir. display( ) ) ) ?;
581+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , install_dir. display( ) ) ) ?;
582582
583583 let mut configure = Command :: new ( "./configure" ) ;
584584 add_compile_envs ( wasi_sdk, & mut configure) ;
@@ -591,12 +591,12 @@ fn build_zlib(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
591591 let ar_dir = wasi_sdk. join ( "bin/ar" ) ;
592592 let ar_dir = ar_dir
593593 . to_str ( )
594- . ok_or_else ( || anyhow ! ( "non-utf8 path: {}" , ar_dir. display( ) ) ) ?;
594+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , ar_dir. display( ) ) ) ?;
595595
596596 let clang_dir = wasi_sdk. join ( "bin/clang" ) ;
597597 let clang_dir = clang_dir
598598 . to_str ( )
599- . ok_or_else ( || anyhow ! ( "non-utf8 path: {}" , clang_dir. display( ) ) ) ?;
599+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , clang_dir. display( ) ) ) ?;
600600
601601 let mut make = Command :: new ( "make" ) ;
602602 add_compile_envs ( wasi_sdk, & mut make) ;
@@ -640,15 +640,24 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
640640 fs:: create_dir_all ( install_dir. join ( "include" ) ) ?;
641641
642642 let sysroot = wasi_sdk. join ( "share/wasi-sysroot" ) ;
643- let sysroot_str = sysroot. to_string_lossy ( ) ;
643+ let sysroot_str = sysroot
644+ . to_str ( )
645+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , sysroot. display( ) ) ) ?;
646+ let install_dir_str = install_dir
647+ . to_str ( )
648+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , install_dir. display( ) ) ) ?;
649+ let ar_path = wasi_sdk. join ( "bin/ar" ) ;
650+ let ar_str = ar_path
651+ . to_str ( )
652+ . ok_or_else ( || anyhow ! ( "non-UTF8 path: {}" , ar_path. display( ) ) ) ?;
644653
645654 // SQLite-specific CFLAGS for WASI compatibility
646655 // Note: Don't set SQLITE_THREADSAFE here - let --disable-threadsafe handle it
647656 // to avoid macro redefinition warnings
648657 let sqlite_cflags = format ! (
649658 "--target=wasm32-wasi \
650- --sysroot={sysroot } \
651- -I{sysroot }/include/wasm32-wasip1 \
659+ --sysroot={sysroot_str } \
660+ -I{sysroot_str }/include/wasm32-wasip1 \
652661 -D_WASI_EMULATED_SIGNAL \
653662 -D_WASI_EMULATED_PROCESS_CLOCKS \
654663 -fPIC \
@@ -658,7 +667,6 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
658667 -DSQLITE_OMIT_LOCALTIME \
659668 -DSQLITE_OMIT_RANDOMNESS \
660669 -DSQLITE_OMIT_SHARED_CACHE",
661- sysroot = sysroot_str
662670 ) ;
663671
664672 // Configure SQLite
@@ -671,13 +679,10 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
671679 . env ( "CFLAGS" , & sqlite_cflags)
672680 . env (
673681 "LDFLAGS" ,
674- format ! (
675- "--target=wasm32-wasip2 --sysroot={sysroot} -L{sysroot}/lib" ,
676- sysroot = sysroot_str
677- ) ,
682+ format ! ( "--target=wasm32-wasip2 --sysroot={sysroot_str} -L{sysroot_str}/lib" , ) ,
678683 )
679684 . arg ( "--host=wasm32-wasi" )
680- . arg ( format ! ( "--prefix={}" , install_dir . display ( ) ) )
685+ . arg ( format ! ( "--prefix={install_dir_str}" ) )
681686 . arg ( "--disable-shared" )
682687 . arg ( "--enable-static" )
683688 . arg ( "--disable-readline" )
@@ -693,7 +698,7 @@ fn build_sqlite(wasi_sdk: &Path, install_dir: &Path) -> Result<()> {
693698 . env ( "CC" , wasi_sdk. join ( "bin/clang" ) )
694699 . env ( "RANLIB" , wasi_sdk. join ( "bin/ranlib" ) )
695700 . env ( "CFLAGS" , & sqlite_cflags)
696- . arg ( format ! ( "AR={}" , wasi_sdk . join ( "bin/ar" ) . display ( ) ) )
701+ . arg ( format ! ( "AR={ar_str}" ) )
697702 . arg ( "ARFLAGS=rcs" )
698703 . arg ( "libsqlite3.a" ) ; // Build only the static library
699704 run ( & mut make) ?;
0 commit comments