Skip to content

Broken build of RustPython on wasip2 #6891

@sammyne

Description

@sammyne

Summary

Try to embed RustPython as a wasm component, but fail to build it on wasm32-wasip2 target.

Details

Environment

  • rust: 1.95.0-nightly (85eff7c80 2026-01-15)
  • RustPython: 2025-11-10-main-55
  • OS: Debian GNU/Linux 12

Reproduction

cargo build -r

Error goes as

error[E0425]: cannot find value `CLOCK_PROCESS_CPUTIME_ID` in crate `libc`
   --> /root/.cargo/git/checkouts/rustpython-63090cdce5e18442/9792001/vm/src/stdlib/time.rs:432:42
    |
432 |             if libc::clock_gettime(libc::CLOCK_PROCESS_CPUTIME_ID, time.as_mut_ptr()) == -1 {
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `rustpython-vm` (lib) due to 1 previous error

Related Code

lib.rs

#[cfg(target_arch = "wasm32")]
mod wasm;

#[cfg(target_arch = "wasm32")]
pub use wasm::*;

use anyhow::Result;
use rustpython_vm::{Interpreter, PyResult, VirtualMachine};

/// Run Python code and return the result
///
/// # Arguments
/// * `code` - The Python code to execute
///
/// # Returns
/// The result of the Python code execution as a string
///
/// # Errors
/// Returns an error if the Python code execution fails
pub fn run(code: &str) -> Result<String> {
    let interpreter = Interpreter::new_without_stdlib(None);
    let vm = &interpreter.vm;

    // Execute the Python code and get the result
    let result: PyResult = vm.run_code_string(code, "<embedded>".to_owned(), None);

    match result {
        Ok(value) => {
            // Convert the result to string representation
            let str_value = value.to_repr(vm);
            Ok(str_value.to_string())
        }
        Err(e) => Err(anyhow::anyhow!("Python execution error: {}", e.to_string(vm))),
    }
}

wasm.rs

mod bindgen {
    wit_bindgen::generate!();

    use crate::App;

    export!(App);
}

use bindgen::exports::sammyne::rust_python::api::Guest;

pub struct App;

impl Guest for App {
    fn run(code: String) -> Result<String, String> {
        crate::run(&code).map_err(|err| err.to_string())
    }
}

I made github repository https://github.com/sammyne/rust-python-broken-build-on-wasip2 to ease reproduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions