-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
This allows making the whole module conditional on proc_macro during no_std conversion, rather than cfg'ing every single line of code.
None of that code needs to be available in source form at build time (and it would inhibit no_std operation).
This is the same type (exported with two names), and expected to be available in this place for no_std use starting with Rust 1.64.
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 but I don't quite understand this PR.
Could you explain why do we need all the things around cfg(proc_macro)
? The only purpose of this crate is to provide a proc macro. I don't quite see why it needs any conditional compilation guarding that.
The general reason of `cfg(proc_maro)` is that the compiler doesn't know
that this is all only for the proc macro -- and would try building it
not only for the host (where the progam is being built and the proc
macro executed) but also for the target (on which it would eventually be
run). Normally, that's no big issue -- at link time, the functions that
were built only for the proc macro will just be stripped because they
are unused at run time.
For no_std targets, the proc macro can not be built (because it has no
std, and generally the compiler wouldn't work on it), and telling that
to the compiler allows building the crate for these targets.
(Rethinking your comment I did find that even the crate itself, or
probably more its root module, can be made conditional; I'm rewriting
the more intrusive parts of the PR to that respect. PR update coming
up).
|
I'm not very convinced. The compiler, or at least Cargo indeed knows that this is only for proc macro, since this is written in Line 13 in 8357a00
If the compiler / cargo builds it for the target, it should be a bug of rustc / cargo. If there is such a bug known, you can link it here and we can proceed with it, otherwise I'd be a bit hesitant. |
I believe it is not a problem nowadays. I tried to reference
You can see this crate (along with all its dependencies) is not built for the wasm32 target at all. |
The wasm32-unknown-unknown target is a bad test case because it does have a std library. It's a common issue with no_std libraries that they accidentally pull in some std components, and testing on a target with a standard library just passes. PR #14, which I've simplified significantly based on your comments (I had misunderstood how profound effects the Closing this as #14 is by all accounts the better fix. |
Closes: #12 (see previous discussion there).
This requires Rust 1.64 (or the version in which cstr_core gets stabilized if things do get reverted; it's already in current nightlies). I don't have any automated tests to offer for whether the result truly works without std -- I've tested it in my applications, but given how tests rely on std, it's not easy to prove no_std operation without building for a target that has no std library. Given that there are few dependencies and no
extern crate std
code, I don't think that this necessarily needs extra testing.