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

Add support for no_std #70

Merged
merged 1 commit into from
Jan 16, 2016
Merged

Add support for no_std #70

merged 1 commit into from
Jan 16, 2016

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Jan 12, 2016

Second attempt at support no_std, this time without splitting the crate into two. Instead, a use_std feature is used, which is enabled by default.

Fixes #13

@@ -150,10 +190,17 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "nightly", feature(panic_handler))]

#![cfg_attr(all(not(feature = "use_std"), not(test)), no_std)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that no_std should be usable even during --test, so the not(test) clause shouldn't be necessary here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests actually depend on libstd since they make use of .to_string().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you can have an explicit extern crate std in the mod test and use the libstd prelude

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it and it doesn't work because of the extern crate core as std; line just below. I think it's fine to just leave the this line as it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean putting the crate in the module it's needed, not up here. This is a core crate of the Rust ecosystem and is likely to be used as an example for downstream code (e.g. idioms and such), so I'd prefer to have it as idiomatic as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was being stupid with namespaces. I've moved the extern crate std into the tests module.

On Thu, Jan 14, 2016 at 10:21 PM, Alex Crichton notifications@github.com
wrote:

In src/lib.rs
#70 (comment):

@@ -150,10 +190,17 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "nightly", feature(panic_handler))]

+#![cfg_attr(all(not(feature = "use_std"), not(test)), no_std)]

I mean putting the crate in the module it's needed, not up here. This is a
core crate of the Rust ecosystem and is likely to be used as an example for
downstream code (e.g. idioms and such), so I'd prefer to have it as
idiomatic as possible.


Reply to this email directly or view it on GitHub
https://github.com/rust-lang-nursery/log/pull/70/files#r49794509.

@Amanieu
Copy link
Member Author

Amanieu commented Jan 12, 2016

Updated with given feedback.

@@ -1,14 +1,15 @@
language: rust
sudo: false
rust:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we continue testing against our minimum supported Rust version, which'll be 1.4.0 I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm which part requires 1.4.0? Ideally this would continue to compile on 1.0.0 as long as possible, but if it's too hard it may not be worth it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code depends on these feature:

  • Box::into_raw
  • Box::from_raw
  • (*const Trait) as *const Struct (used in one of the doc tests)

The first two can easily be changed into mem::transmute, but I'm not sure about the last one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, would it be possible to leverage mem::transmute for now then? It's fine to just build the library on 1.0.0 instead of running the full test suite which may require more features.

@Amanieu Amanieu force-pushed the no_std2 branch 2 times, most recently from 3c3f89d to de132b7 Compare January 14, 2016 05:24

unsafe {
assert_eq!(libc::atexit(shutdown), 0);
/// Sets the global logger from a raw pointer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably note here and in shutdown_logger that they should only be used in a no_std setup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added, shutdown_logger already has a note saying that it shouldn't be used with set_logger.

/// This function should not be called when the global logger was registered
/// using `set_logger`, since in that case the logger will automatically be shut
/// down when the program exits
pub fn shutdown_logger() -> Result<*const Log, ShutdownLoggerError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and set_logger_raw may want to be paired up in terms of naming or organization to set them apart from set_logger a bit more (and to make it clear that shutdown_logger isn't necessary most of the time)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what exactly are you suggesting? shutdown_logger_raw? Or something like log::raw::{set_logger, shutdown_logger}?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a module perhaps, but it seems kinda arbitrary. Including raw in the name seems prudent though.

@alexcrichton
Copy link
Member

@sfackler I'm happy with this modulo a bit of bikeshedding, and I'll leave it up to you to merge

@alexcrichton
Copy link
Member

Also thanks @Amanieu, I'm excited to see more libs start picking up the no_std standard!

@Amanieu
Copy link
Member Author

Amanieu commented Jan 14, 2016

Updated again, it should work on 1.0.0 now. I also renamed shutdown_logger to shutdown_logger_raw.


// The Error trait is not available in libcore
#[cfg(feature = "use_std")]
impl error::Error for ShutdownLoggerError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton there's nothing blocking us from adding Error to libcore right?

Doesn't affect this PR of course.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it should be easy enough to add

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment explains why Error is in libstd: https://github.com/rust-lang/rust/blob/master/src/libstd/error.rs#L39

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, forgot about that.

@sfackler
Copy link
Member

Looks good to me, thanks!

sfackler added a commit that referenced this pull request Jan 16, 2016
@sfackler sfackler merged commit cb09c6e into rust-lang:master Jan 16, 2016
@sfackler
Copy link
Member

I'm going to take a pass over the docs to make sure everything looks right and then push a release.

@sfackler
Copy link
Member

Made a couple minor tweaks: #71

EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
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.

3 participants