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

no_std support #336

Closed
quodlibetor opened this issue Sep 2, 2019 · 11 comments · Fixed by #341
Closed

no_std support #336

quodlibetor opened this issue Sep 2, 2019 · 11 comments · Fixed by #341

Comments

@quodlibetor
Copy link
Contributor

mentioned in 195, we need a good story around no_std/alloc support.

The parts of this that jump right to mind:

  • Breaking up the core mathy parts of chrono into their own crates/features
  • Refactoring various stringy bits to be in terms of Write
  • parts of chrono around parsing allocate, too, I believe.
@quodlibetor quodlibetor added this to the Chrono 1.0 milestone Sep 2, 2019
@quodlibetor
Copy link
Contributor Author

Honestly I'm not sure how far Chrono is from supporting no_std when the default features are turned off. I think some people might already be using it semi-successfully? Code that people would like to work, but does not, would be welcome.

For example, this seems to work:

#![no_std]

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        use chrono::TimeZone;
        let _ = chrono::Utc.ymd(1999, 1,1).and_hms(1, 2, 3);
    }
}

@alex
Copy link
Contributor

alex commented Sep 2, 2019

My understanding is that testing #![no_std] with cargo test doesn't necessarily prove what you expect, because libtest links std.

@quodlibetor
Copy link
Contributor Author

that makes sense, this also works, though:

# Cargo.toml
[package]
name = "nostd"
version = "0.1.0"
authors = ["Brandon W Maister <quodlibetor@gmail.com>"]
edition = "2018"

[dependencies]
chrono = { version = "0.4", default-features = false }
// src/lib.rs
#![no_std]

use chrono::TimeZone;

pub fn dt() -> chrono::DateTime<chrono::Utc> {
    chrono::Utc.ymd(1999, 1,1).and_hms(1, 2, 3)
}
$ cargo build
   Compiling nostd v0.1.0 (/Users/bwm/github/chrono/examples/nostd)
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s

@quodlibetor
Copy link
Contributor Author

I'm pretty sure that chrono doesn't work well in no-std environments, but I don't know what people would expect to work, or how folks would like to be able to interact with it. Examples of code that doesn't work that anyone would expect to would be great.

@alex
Copy link
Contributor

alex commented Sep 2, 2019

I haven't explored too deeply on what does or does not work, but the code I hope would be possible to make work is: https://github.com/alex/rust-asn1/blob/0fe97f6cdddc7ba718e12b3f0880dc2f924915b5/src/parser.rs#L281-L324

@quodlibetor
Copy link
Contributor Author

quodlibetor commented Sep 2, 2019

Do you have an example of the exact error that you're getting? Most of the code in there seems like it should either already work or be trivial to make work.

edit: oh no I said should be trivial.

@alex
Copy link
Contributor

alex commented Sep 2, 2019

I don't, it's entirely possible this works fine! I generally assume crates aren't no_std friendly unless they explicitly document it :-)

@quodlibetor
Copy link
Contributor Author

haha lmk how it goes and I'll document it 😛

@CryZe
Copy link
Contributor

CryZe commented Sep 6, 2019

Considering my crate makes heavy use of chrono, I'll take a shot at this. Atm I've polyfilled chrono, but that shouldn't be necessary.

@quodlibetor
Copy link
Contributor Author

thanks!

@CryZe
Copy link
Contributor

CryZe commented Sep 7, 2019

Alright, I have a working branch now. The only remaining problem is that I needed to get rid of all the dev-dependencies

CryZe added a commit to CryZe/chrono that referenced this issue Sep 7, 2019
This adds a new `std` feature to chrono that is enabled by default. By
deactivating this feature via `default-features = false` you can now use
chrono in applications that don't use the standard library. The `serde`
feature is supported as well.

Resolves chronotope#336
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 a pull request may close this issue.

3 participants