Skip to content

Commit cdfcd8a

Browse files
authored
Merge pull request RustPython#5288 from youknowone/enable-wasi-unittest
Enable wasi unittest
2 parents 621640c + 1bc1370 commit cdfcd8a

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,5 @@ jobs:
411411
run: cargo build --release --target wasm32-wasi --features freeze-stdlib,stdlib --verbose
412412
- name: run snippets
413413
run: wasmer run --dir `pwd` target/wasm32-wasi/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py
414+
- name: run cpython unittest
415+
run: wasmer run --dir `pwd` target/wasm32-wasi/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py

‎src/interpreter.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ pub fn init_stdlib(vm: &mut VirtualMachine) {
8484

8585
// if we're on freeze-stdlib, the core stdlib modules will be included anyway
8686
#[cfg(feature = "freeze-stdlib")]
87-
vm.add_frozen(rustpython_pylib::FROZEN_STDLIB);
87+
{
88+
vm.add_frozen(rustpython_pylib::FROZEN_STDLIB);
89+
90+
// FIXME: Remove this hack once sys._stdlib_dir is properly implemented or _frozen_importlib doesn't depend on it anymore.
91+
assert!(vm.sys_module.get_attr("_stdlib_dir", vm).is_err());
92+
vm.sys_module
93+
.set_attr(
94+
"_stdlib_dir",
95+
vm.new_pyobj(rustpython_pylib::LIB_PATH.to_owned()),
96+
vm,
97+
)
98+
.unwrap();
99+
}
88100

89101
#[cfg(not(feature = "freeze-stdlib"))]
90102
{

‎vm/src/stdlib/os.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,14 @@ pub(super) mod _os {
932932

933933
#[pyfunction]
934934
fn getpid(vm: &VirtualMachine) -> PyObjectRef {
935-
let pid = std::process::id();
935+
let pid = if cfg!(target_arch = "wasm32") {
936+
// Return an arbitrary value, greater than 1 which is special.
937+
// The value 42 is picked from wasi-libc
938+
// https://github.com/WebAssembly/wasi-libc/blob/wasi-sdk-21/libc-bottom-half/getpid/getpid.c
939+
42
940+
} else {
941+
std::process::id()
942+
};
936943
vm.ctx.new_int(pid).into()
937944
}
938945

0 commit comments

Comments
 (0)