René's URL Explorer Experiment


Title: Provide `os` module for `wasm32-unknown-unknown` target · Issue #7363 · RustPython/RustPython · GitHub

Open Graph Title: Provide `os` module for `wasm32-unknown-unknown` target · Issue #7363 · RustPython/RustPython

X Title: Provide `os` module for `wasm32-unknown-unknown` target · Issue #7363 · RustPython/RustPython

Description: Summary Currently, RustPython does not provide the os module for wasm32-unknown-unknown. The module is gated behind the host_env feature, and the wasm32 example project disables it (default-features = false, features = ["compiler"]). How...

Open Graph Description: Summary Currently, RustPython does not provide the os module for wasm32-unknown-unknown. The module is gated behind the host_env feature, and the wasm32 example project disables it (default-feature...

X Description: Summary Currently, RustPython does not provide the os module for wasm32-unknown-unknown. The module is gated behind the host_env feature, and the wasm32 example project disables it (default-feature...

Opengraph URL: https://github.com/RustPython/RustPython/issues/7363

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Provide `os` module for `wasm32-unknown-unknown` target","articleBody":"## Summary\n\nCurrently, RustPython does not provide the `os` module for `wasm32-unknown-unknown`. The module is gated behind the `host_env` feature, and the wasm32 example project disables it (`default-features = false, features = [\"compiler\"]`). However, CPython's Emscripten build provides an `os` module with a reduced function set, and many Python packages do `import os` at the top level. Without the `os` module, even `os.path.join()` (pure Python) fails with `ImportError`.\n\n## Motivation\n\n- Many Python packages unconditionally `import os` at the top level — they currently fail entirely on wasm32-unknown-unknown\n- `os.path` functions (`join`, `dirname`, `basename`, etc.) are pure Python and would work fine if the module existed\n- Constants like `os.sep`, `os.name`, `os.O_RDONLY` are useful even without real I/O\n- Functions like `os.fspath()`, `os.getpid()`, `os.strerror()` can return sensible values\n- CPython's Emscripten build takes this approach — provide the module, let unsupported operations raise `OSError` at runtime\n\n## Problem Analysis\n\nThe `os` module (specifically `_os` in `os.rs`) fails to compile on `wasm32-unknown-unknown` due to several dependencies:\n\n### 1. `crt_fd.rs` depends on `libc`\n- `mod c { pub(super) use libc::*; }` — `libc` exports nothing for `wasm32-unknown-unknown`\n- Functions like `c::open()`, `c::close()`, `c::read()`, `c::write()`, `c::fsync()`, `c::ftruncate()` don't exist\n- Constants like `c::EBADF`, `c::off_t` don't exist\n- Currently gated: `#[cfg(all(feature = \"std\", any(unix, windows, target_os = \"wasi\")))]` in `lib.rs`\n\n### 2. `fileutils.rs` depends on `libc::stat`\n- `pub use libc::stat as StatStruct` on non-windows — no `libc::stat` on wasm32\n- `fstat()` uses `libc::fstat()` — doesn't exist\n- Currently gated: `#[cfg(all(feature = \"std\", any(not(target_arch = \"wasm32\"), target_os = \"wasi\")))]`\n\n### 3. `os.rs` uses `libc` directly\n- `#[pyattr] use libc::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}` — empty on wasm32\n- `libc::EINTR` in read/write retry loops\n- `libc::isatty()` in `isatty()`\n- `libc::strerror()` in `strerror()`\n- `libc::lseek()` in `lseek()`\n- `libc::nl_langinfo()` in `device_encoding()`\n- `libc::stat/lstat/fstat/fstatat` in `stat_inner()`\n\n### 4. `num_cpus` crate — not available for `wasm32-unknown-unknown`\n- Used in `cpu_count()`\n\n### 5. `os_open()` is gated behind `cfg(any(unix, windows, target_os = \"wasi\"))`\n\n## Proposed Solution\n\n**Approach**: Compile-only support — the `os` module compiles and is importable on wasm32-unknown-unknown. Functions that can't work on wasm32 will raise `OSError` at runtime (since `std::fs` returns errors). Constants and path functions work normally.\n\n### Files to Modify\n\n#### `crates/common/src/lib.rs`\nExpand cfg gates to include wasm32-unknown-unknown:\n```rust\n// crt_fd: include wasm32\n#[cfg(all(feature = \"std\", any(unix, windows, target_os = \"wasi\", target_arch = \"wasm32\")))]\npub mod crt_fd;\n\n// fileutils: remove wasm32 exclusion\n#[cfg(feature = \"std\")]\npub mod fileutils;\n```\n\n#### `crates/common/src/crt_fd.rs`\nAdd a wasm32-specific `mod c` block (similar to the existing Windows-specific sections):\n```rust\n#[cfg(all(target_arch = \"wasm32\", not(any(unix, windows, target_os = \"wasi\"))))]\nmod c {\n    pub type off_t = i64;\n    pub type c_int = i32;\n    pub type c_char = i8;\n    pub const EBADF: c_int = 9;\n\n    // Stub functions that always return -1\n    pub unsafe fn open(_: *const c_char, _: c_int, _: c_int) -\u003e c_int { -1 }\n    pub unsafe fn close(_: c_int) -\u003e c_int { -1 }\n    pub unsafe fn read(_: c_int, _: *mut u8, _: usize) -\u003e isize { -1 }\n    pub unsafe fn write(_: c_int, _: *const u8, _: usize) -\u003e isize { -1 }\n    pub unsafe fn fsync(_: c_int) -\u003e c_int { -1 }\n    pub unsafe fn ftruncate(_: c_int, _: off_t) -\u003e c_int { -1 }\n}\n```\n\n`std::os::fd` types (`OwnedFd`, `BorrowedFd`, `RawFd`) are available on wasm32 since Rust 1.84, so the existing `#[cfg(not(windows))]` imports work.\n\n#### `crates/common/src/fileutils.rs`\nAdd wasm32-specific `StatStruct` and `fstat` stub:\n```rust\n#[cfg(not(any(unix, windows, target_os = \"wasi\")))]\npub struct StatStruct { /* minimal fields matching libc::stat layout */ }\n\n#[cfg(not(any(unix, windows, target_os = \"wasi\")))]\npub fn fstat(_: crate::crt_fd::Borrowed\u003c'_\u003e) -\u003e std::io::Result\u003cStatStruct\u003e {\n    Err(std::io::Error::new(std::io::ErrorKind::Unsupported, \"fstat not supported\"))\n}\n```\n\n#### `crates/vm/src/stdlib/os.rs`\n~10 changes needed:\n- **O_\\* constants**: Define manually for wasm32 (`O_RDONLY=0`, `O_WRONLY=1`, `O_RDWR=2`, etc.)\n- **`open`/`os_open`**: Add wasm32 path returning error\n- **`read`/`write`**: Replace `libc::EINTR` with cfg-gated constant\n- **`isatty`**: Return `false` on wasm32\n- **`strerror`**: Basic error-number-to-string mapping\n- **`lseek`**: Return error on wasm32\n- **`stat_inner`**: Use `std::fs::metadata` or return error\n- **`StatResultData::from_stat`**: Handle wasm32 StatStruct fields\n- **`cpu_count`**: Return 1 on wasm32\n- **`device_encoding`**: Return \"UTF-8\" on wasm32\n- **`utime_impl`**: Return \"not supported\" error on wasm32\n\n#### `crates/vm/src/stdlib/posix_compat.rs`\nAdd `environ` for wasm32 (currently only defined for `target_os = \"wasi\"`):\n```rust\n#[cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))]\n#[pyattr]\nfn environ(vm: \u0026VirtualMachine) -\u003e crate::builtins::PyDictRef {\n    vm.ctx.new_dict()  // Empty dict — no env vars on bare wasm32\n}\n```\n\n### Cfg Pattern\n\nThe recurring condition is:\n```rust\n#[cfg(all(target_arch = \"wasm32\", not(any(unix, windows, target_os = \"wasi\"))))]\n```\nThis matches `wasm32-unknown-unknown` specifically (not emscripten, not wasi, not windows).\n\n## Verification Plan\n\n1. `cargo check --target wasm32-unknown-unknown -p rustpython-vm --features \"compiler,host_env\"` — must compile\n2. `cargo test -p rustpython-vm` on host — no regressions\n3. Update `example_projects/wasm32_without_js/` to optionally enable `host_env`\n4. Runtime: build wasm32 binary with `import os; print(os.name)` — should print `\"posix\"` without error\n\n## References\n\n- CPython Emscripten support: https://docs.python.org/3/using/wasm.html\n- `std::os::fd` portable stabilization (Rust 1.84): https://github.com/rust-lang/rust/issues/126198\n- `libc` crate wasm32-unknown-unknown: exports nothing — https://docs.rs/libc/latest/libc/","author":{"url":"https://github.com/youknowone","@type":"Person","name":"youknowone"},"datePublished":"2026-03-05T20:08:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/7363/RustPython/issues/7363"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b618a351-f6e5-10bf-8d7d-d82c8af25d65
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8F50:1A68FF:C92505:106AEA4:6A5C2F4B
html-safe-nonceb3586e9f8a5b68263890d60c917f9cc73f2f4ac5bacfff3f352af864635045ab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjUwOjFBNjhGRjpDOTI1MDU6MTA2QUVBNDo2QTVDMkY0QiIsInZpc2l0b3JfaWQiOiI1MzM2NDQxNDI3NjI2NTY5NTQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac76cef9949f91458bc3b9f5a90897678af9d8457b104fc80cf08644545faf7c75
hovercard-subject-tagissue:4030331145
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/RustPython/RustPython/7363/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b0a902e6475ea6d4a14e42ba2c7cded5e80679dffa724dac7249a585e10891a7/RustPython/RustPython/issues/7363
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b0a902e6475ea6d4a14e42ba2c7cded5e80679dffa724dac7249a585e10891a7/RustPython/RustPython/issues/7363
og:image:altSummary Currently, RustPython does not provide the os module for wasm32-unknown-unknown. The module is gated behind the host_env feature, and the wasm32 example project disables it (default-feature...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameyouknowone
hostnamegithub.com
expected-hostnamegithub.com
None5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b
turbo-cache-controlno-preview
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c975978430e9ad293956f2bbdaf153b1bd84a99
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/issues/7363#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F7363
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F7363
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/issues/7363
Reloadhttps://github.com/RustPython/RustPython/issues/7363
Reloadhttps://github.com/RustPython/RustPython/issues/7363
Please reload this pagehttps://github.com/RustPython/RustPython/issues/7363
RustPython https://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Notifications https://github.com/login?return_to=%2FRustPython%2FRustPython
Fork 1.5k https://github.com/login?return_to=%2FRustPython%2FRustPython
Star 22.2k https://github.com/login?return_to=%2FRustPython%2FRustPython
Code https://github.com/RustPython/RustPython
Issues 291 https://github.com/RustPython/RustPython/issues
Pull requests 106 https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality 0 https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Code https://github.com/RustPython/RustPython
Issues https://github.com/RustPython/RustPython/issues
Pull requests https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Provide os module for wasm32-unknown-unknown targethttps://github.com/RustPython/RustPython/issues/7363#top
https://github.com/youknowone
youknowonehttps://github.com/youknowone
on Mar 5, 2026https://github.com/RustPython/RustPython/issues/7363#issue-4030331145
https://docs.python.org/3/using/wasm.htmlhttps://docs.python.org/3/using/wasm.html
std::os::fd module missing on Hermit rust-lang/rust#126198https://github.com/rust-lang/rust/issues/126198
https://docs.rs/libc/latest/libc/https://docs.rs/libc/latest/libc/
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.