@@ -428,6 +428,44 @@ impl Build {
428
428
configure. arg ( "-D__STDC_NO_ATOMICS__" ) ;
429
429
}
430
430
431
+ if target. contains ( "wasi" ) {
432
+ configure. args ( [
433
+ // Termios isn't available whatsoever on WASM/WASI so we disable that
434
+ "no-ui-console" ,
435
+ // WASI doesn't support UNIX sockets so we preemptively disable it
436
+ "no-sock" ,
437
+ // WASI doesn't have a concept of syslog, so we disable it
438
+ "-DNO_SYSLOG" ,
439
+ // WASI doesn't support (p)threads. Disabling preemptively.
440
+ "no-threads" ,
441
+ // WASI/WASM aren't really friends with ASM, so we disable it as well.
442
+ "no-asm" ,
443
+ // Disables the AFALG engine (AFALG-ENGine)
444
+ // Since AFALG depends on `AF_ALG` support on the linux kernel side
445
+ // it makes sense that we can't use it.
446
+ "no-afalgeng" ,
447
+ "-DOPENSSL_NO_AFALGENG=1" ,
448
+ // wasm lacks signal support; to enable minimal signal emulation, compile with
449
+ // -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal
450
+ // The link argument is output in the `Artifacts::print_cargo_metadata` method
451
+ "-D_WASI_EMULATED_SIGNAL" ,
452
+ // WASI lacks process-associated clocks; to enable emulation of the `times` function using the wall
453
+ // clock, which isn't sensitive to whether the program is running or suspended, compile with
454
+ // -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks
455
+ // The link argument is output in the `Artifacts::print_cargo_metadata` method
456
+ "-D_WASI_EMULATED_PROCESS_CLOCKS" ,
457
+ // WASI lacks a true mmap; to enable minimal mmap emulation, compile
458
+ // with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman
459
+ // The link argument is output in the `Artifacts::print_cargo_metadata` method
460
+ "-D_WASI_EMULATED_MMAN" ,
461
+ // WASI lacks process identifiers; to enable emulation of the `getpid` function using a
462
+ // placeholder value, which doesn't reflect the host PID of the program, compile with
463
+ // -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid
464
+ // The link argument is output in the `Artifacts::print_cargo_metadata` method
465
+ "-D_WASI_EMULATED_GETPID" ,
466
+ ] ) ;
467
+ }
468
+
431
469
if target. contains ( "musl" ) {
432
470
// Hack around openssl/openssl#7207 for now
433
471
configure. arg ( "-DOPENSSL_NO_SECURE_MEMORY" ) ;
@@ -578,6 +616,11 @@ impl Artifacts {
578
616
println ! ( "cargo:lib={}" , self . lib_dir. display( ) ) ;
579
617
if self . target . contains ( "msvc" ) {
580
618
println ! ( "cargo:rustc-link-lib=user32" ) ;
619
+ } else if self . target == "wasm32-wasi" {
620
+ println ! ( "cargo:rustc-link-lib=wasi-emulated-signal" ) ;
621
+ println ! ( "cargo:rustc-link-lib=wasi-emulated-process-clocks" ) ;
622
+ println ! ( "cargo:rustc-link-lib=wasi-emulated-mman" ) ;
623
+ println ! ( "cargo:rustc-link-lib=wasi-emulated-getpid" ) ;
581
624
}
582
625
}
583
626
}
0 commit comments