Add support for cross compilation for wasm/wasi

When using rust after this commit
1a491e2304
the target family for wasm targets is now set to "wasm". Also fix the
assumption that OsStrExt lives inside std::os::unix for all non-windows
targets.
This commit is contained in:
Simon Rainerson 2021-05-14 14:01:35 +02:00
parent 1ae3d87973
commit b0f7145f9c
2 changed files with 10 additions and 0 deletions

View File

@ -536,6 +536,8 @@ fn load_cross_compile_info(cross_compile_config: CrossCompileConfig) -> Result<I
Some(os) if os == "unix" => load_cross_compile_from_sysconfigdata(cross_compile_config), Some(os) if os == "unix" => load_cross_compile_from_sysconfigdata(cross_compile_config),
// Use hardcoded interpreter config when targeting Windows // Use hardcoded interpreter config when targeting Windows
Some(os) if os == "windows" => windows_hardcoded_cross_compile(cross_compile_config), Some(os) if os == "windows" => windows_hardcoded_cross_compile(cross_compile_config),
// sysconfigdata works fine on wasm/wasi
Some(os) if os == "wasm" => load_cross_compile_from_sysconfigdata(cross_compile_config),
// Waiting for users to tell us what they expect on their target platform // Waiting for users to tell us what they expect on their target platform
Some(os) => bail!( Some(os) => bail!(
"Unsupported target OS family for cross-compilation: {:?}", "Unsupported target OS family for cross-compilation: {:?}",

View File

@ -22,6 +22,9 @@ impl ToPyObject for OsStr {
// https://doc.rust-lang.org/src/std/sys_common/mod.rs.html#59 // https://doc.rust-lang.org/src/std/sys_common/mod.rs.html#59
#[cfg(not(windows))] #[cfg(not(windows))]
{ {
#[cfg(target_os = "wasi")]
let bytes = std::os::wasi::ffi::OsStrExt::as_bytes(self);
#[cfg(not(target_os = "wasi"))]
let bytes = std::os::unix::ffi::OsStrExt::as_bytes(self); let bytes = std::os::unix::ffi::OsStrExt::as_bytes(self);
let ptr = bytes.as_ptr() as *const c_char; let ptr = bytes.as_ptr() as *const c_char;
@ -68,6 +71,11 @@ impl FromPyObject<'_> for OsString {
}; };
// Create an OsStr view into the raw bytes from Python // Create an OsStr view into the raw bytes from Python
#[cfg(target_os = "wasi")]
let os_str: &OsStr = std::os::wasi::ffi::OsStrExt::from_bytes(
fs_encoded_bytes.as_ref(ob.py()).as_bytes(),
);
#[cfg(not(target_os = "wasi"))]
let os_str: &OsStr = std::os::unix::ffi::OsStrExt::from_bytes( let os_str: &OsStr = std::os::unix::ffi::OsStrExt::from_bytes(
fs_encoded_bytes.as_ref(ob.py()).as_bytes(), fs_encoded_bytes.as_ref(ob.py()).as_bytes(),
); );