Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: add support for xous #12

Merged
merged 1 commit into from
Oct 28, 2022
Merged

os: add support for xous #12

merged 1 commit into from
Oct 28, 2022

Conversation

xobs
Copy link
Contributor

@xobs xobs commented Oct 25, 2022

Add support for riscv32imac-unknown-xous-elf.

The entire system is based on UTF-8. The OsStrExt and OsStringExt modules provide identical implementations to unix and wasi.

Add support for riscv32imac-unknown-xous-elf.

The entire system is based on UTF-8. The `OsStrExt` and `OsStringExt`
modules provide identical implementations to unix and wasi.

Signed-off-by: Sean Cross <sean@xobs.io>
@dylni
Copy link
Owner

dylni commented Oct 27, 2022

Do you have a link to where std::os::xous is defined? I don't see it in this file:
https://github.com/rust-lang/rust/blob/1898c34e923bad763e723c68dd9f23a09f9eb0fc/library/std/src/os/mod.rs

However, if OsStrExt and OsStringExt will not be defined for this target and only UTF-8 will be supported, it could be treated similarly to WebAssembly.

@xobs
Copy link
Contributor Author

xobs commented Oct 27, 2022

Thank you for taking a look at this.

I'm still upstreaming parts, and am working on 3rd party libraries before I get libstd upstreamed. However, since we're only using UTF-8, and OS strings should only ever be UTF-8, perhaps you're right and I just misunderstood how to use this.

If we do duplicate wasm, which approach would you prefer?

  1. Just use wasm on xous
  2. Rename wasm to something like utf8native and use that

For example, this does appear to work and build. I can take this approach if you prefer:

diff --git a/src/lib.rs b/src/lib.rs
index ff24d5b..70986ea 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -236,12 +236,19 @@ macro_rules! if_raw_str {
 }

 #[cfg_attr(
-    all(target_family = "wasm", target_os = "unknown"),
+    any(
+        all(target_family = "wasm", target_os = "unknown"),
+        target_os = "xous"
+    ),
     path = "wasm/mod.rs"
 )]
 #[cfg_attr(windows, path = "windows/mod.rs")]
 #[cfg_attr(
-    not(any(all(target_family = "wasm", target_os = "unknown"), windows)),
+    not(any(
+        all(target_family = "wasm", target_os = "unknown"),
+        windows,
+        target_os = "xous"
+    )),
     path = "common/mod.rs"
 )]
 mod imp;
@@ -252,6 +259,7 @@ mod imp;
         target_family = "wasm",
         target_os = "unknown",
     ),
+    target_os = "xous",
     windows,
 ))]
 mod util;

@dylni
Copy link
Owner

dylni commented Oct 28, 2022

Thanks for the detailed information and sorry for the late replies! As long as the traits are planned to be added to libstd and only return UTF-8 bytes, the current approach would be better. The wasm module is a hack I'd rather avoid for new targets unless needed.

However, support for this platform would need to be soft-unstable until the traits are stabilized by libstd. If that works for you, I can merge this and release a new version with the change.

@xobs
Copy link
Contributor Author

xobs commented Oct 28, 2022

That'd be perfect, thanks!

We keep a parallel fork of libstd that everyone uses, and we're working on getting things upstream. As long as they're okay with the same implementation of OsStrExt that Unix has, we'll keep that approach.

@dylni dylni merged commit 1131084 into dylni:master Oct 28, 2022
@dylni
Copy link
Owner

dylni commented Oct 28, 2022

Thanks for the PR! I'll release this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants