-
Notifications
You must be signed in to change notification settings - Fork 259
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
Conversation
@@ -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)] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
99e066f
to
6c8e548
Compare
Updated with given feedback. |
@@ -1,14 +1,15 @@ | |||
language: rust | |||
sudo: false | |||
rust: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3c3f89d
to
de132b7
Compare
|
||
unsafe { | ||
assert_eq!(libc::atexit(shutdown), 0); | ||
/// Sets the global logger from a raw pointer. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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}
?
There was a problem hiding this comment.
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.
@sfackler I'm happy with this modulo a bit of bikeshedding, and I'll leave it up to you to merge |
Also thanks @Amanieu, I'm excited to see more libs start picking up the |
Updated again, it should work on 1.0.0 now. I also renamed |
|
||
// The Error trait is not available in libcore | ||
#[cfg(feature = "use_std")] | ||
impl error::Error for ShutdownLoggerError { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Looks good to me, thanks! |
I'm going to take a pass over the docs to make sure everything looks right and then push a release. |
Made a couple minor tweaks: #71 |
Second attempt at support
no_std
, this time without splitting the crate into two. Instead, ause_std
feature is used, which is enabled by default.Fixes #13