@@ -86,16 +86,33 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
8686 }
8787 }
8888
89- // Android NDK: the cross-compiler binary knows its own sysroot
90- // implicitly, but bindgen's libclang does not. The NDK sysroot is
91- // at .../toolchains/llvm/prebuilt/<host>/sysroot, which is a sibling
92- // of the bin/ directory containing the compiler.
89+ // WASI SDK: WASI_SDK_PATH is set by Tools/wasm/wasi/__main__.py.
90+ // The sysroot is at $WASI_SDK_PATH/share/wasi-sysroot.
91+ if !have_sysroot && target. contains ( "wasi" ) {
92+ if let Ok ( sdk_path) = env:: var ( "WASI_SDK_PATH" ) {
93+ let sysroot = PathBuf :: from ( & sdk_path)
94+ . join ( "share" )
95+ . join ( "wasi-sysroot" ) ;
96+ if sysroot. is_dir ( ) {
97+ builder = builder. clang_arg ( format ! (
98+ "--sysroot={}" ,
99+ sysroot. display( )
100+ ) ) ;
101+ have_sysroot = true ;
102+ }
103+ }
104+ }
105+
106+ // Android NDK: ANDROID_HOME is set by the CI/user environment, and
107+ // Android/android-env.sh sets CC to the NDK clang binary at:
108+ // $ANDROID_HOME/ndk/<ver>/toolchains/llvm/prebuilt/<host>/bin/<triple>-clang
109+ // The sysroot is a sibling of bin/:
110+ // .../toolchains/llvm/prebuilt/<host>/sysroot
93111 if !have_sysroot && target. contains ( "android" ) {
94112 if let Ok ( cc) = env:: var ( "PY_CC" ) {
95113 if let Some ( parts) = shlex:: split ( & cc) {
96114 if let Some ( binary) = parts. first ( ) {
97- let cc_path = Path :: new ( binary) ;
98- if let Some ( bin_dir) = cc_path. parent ( ) {
115+ if let Some ( bin_dir) = Path :: new ( binary) . parent ( ) {
99116 let sysroot = bin_dir. with_file_name ( "sysroot" ) ;
100117 if sysroot. is_dir ( ) {
101118 builder = builder. clang_arg ( format ! (
0 commit comments