-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Allow CStr and CString types to be used with no_std #46736
Comments
Including |
@kennytm in that case, it would make sense to just move the entire |
@clarcharr |
Can we not make a pragmatic compromise of moving the meat of Cf. https://stackoverflow.com/questions/40575116/ C's |
Inconsistency I noticed: |
Why is that a problem? |
|
In the meantime, is anyone aware of a crate which would do this (provide cstr/cstring for no_std situation) ? |
Personally I think that the methods involving |
We can't expose What we could do is move The main reason not to move |
I don't see how this is true-- as pointed out above, libcore contains |
To be more specific, they vary by |
@gnzlbg Different question -- considering the way Rust is currently packaged, it's impossible to get libcore separately from libstd; when you download for a target, you download both. Is there a plan to separate out the current notion of "target" to just the underlying CPU architecture and not the operating/build environment? This basically affects whether this discussion is meaningful in any way. |
Some targets only ship libcore, and some targets do not even ship libcore.
There are targets that are independent of that, e.g., |
I guess that I'm asking the wrong question-- the point I'm making is that, although there are targets without libstd, there isn't any notion in Rust of compiled code that's independent from its operating environment. Sure, you can specify the environment to be "none" and the resulting bytecode will be environment-agnostic, but there's never the opportunity to link code between different "targets" regardless of whether they share the same architecture. So, yes, while there are targets that ship without libstd, these targets can still have a "different" libcore than the ones that do, regardless of whether the actual contents of these are the same. I honestly don't see this changing. Sure, I agree that using libcore shouldn't require linking against libc. But, on targets that want to link with libc, I don't think it's bad that libcore has code to help with that, because the libcore they're using will always match the environment they're in. The only way that would change if we offered, say, one compiled version of libcore for all of |
I'm not sure I follow. You can build a static lib of a
If you have a program that needs to link against libc, you can just link the I feel like moving The reason It is probably too late to fix this for |
Hello, any news on this? std::ffi:CString still cannot be used in no_std code. Which is kind of funny considering you can make a null terminated string using format!("{}\x00", str), which is arguably alot more complex. |
I think at this point target-specific stuff is used in libcore prominently enough to close the debate and choose the alternative that is useful in practice (i.e. moving at least |
Branch in progress - https://github.com/petrochenkov/rust/tree/cstr. |
Draft PR: #94079. |
library: Move `CStr` to libcore, and `CString` to liballoc Closes rust-lang/rust#46736 Interesting points: - Stability: - To make `CStr(ing)` from libcore/liballoc unusable without enabling features I had to make these structures unstable, and reexport them from libstd using stable type aliases instead of `pub use` reexports. (Because stability of `use` items is not checked.) - Relying on target ABI in libcore is ok: - rust-lang/rust#94079 (comment) - `trait CStrExt` (UPDATE: used only in `cfg(bootstrap)` mode, otherwise lang items are used instead) - rust-lang/rust#94079 (comment) - `strlen` - rust-lang/rust#94079 (comment) Otherwise it's just a code move + some minor hackery usual for liballoc in `cfg(test)` mode.
Embedded code may interact with C and thus may find these types useful. It'd make sense to allow usage of
CStr
in libcore andCString
in liballoc.Of course, right now due to the way implementations work in the standard library it may not be possible to include
CStr
in libcore. However, moving it to liballoc is still a step up.The text was updated successfully, but these errors were encountered: