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

officially support #![no_std] #41 #45

Merged
merged 3 commits into from
Mar 25, 2017
Merged

officially support #![no_std] #41 #45

merged 3 commits into from
Mar 25, 2017

Conversation

colin-kiegel
Copy link
Owner

cc @cramertj

This is work in progress and does not work yet.

open questions

  • how do we tell cargo or travis that a certain test should only run on nightly rust? (#![feature(collections)] requires nightly)
  • something strange happens with this code.
quote!(
    #[cfg(not(no_std))]
    #builder_vis fn build(#ref_self) -> ::std::result::Result<#struct_name #ty_generics, ::std::string::String> {
        /* ... */
    }
    #[cfg(no_std)]
    #builder_vis fn build(#ref_self) -> ::core::result::Result<#struct_name #ty_generics, ::collections::string::String> {
        /* ... */
    }
)

The expanded code only contains the first part

#[cfg(not(no_std))]
#builder_vis fn build(#ref_self) -> ::std::result::Result<#struct_name #ty_generics, ::std::string::String> {
    /* ... */
}

It's like the cfg-attributes always evaluate to #[cfg(not(no_std))]==true and #[cfg(no_std)]==false -- independently of the testcase. I would not be surprised if this was a rust or cargo bug evaluating the cfg-attribute in the wrong context - otherwise I don't understand it.

@colin-kiegel
Copy link
Owner Author

colin-kiegel commented Feb 20, 2017

A workaround would be having an explicit #[builder(no_std)] attribute - but I feel like we should try to get the conditional compilation approach working.

Suggestions are welcome - I am kind of stuck right now. :-)

This is what I mean: cargo expand --test no_std

Where this is the original: tests/no_std.rs

And this is the code that should be emitted: src/lib.rs

PS: It's no different if I move the test to the examples folder.

The test requires nightly. Since it is a compiletest, this requirement is met.
@colin-kiegel
Copy link
Owner Author

Ok, I have now worked around the strange issues with emitting #[cfg(this)] ... #[cfg(that)] ... code.
The new approach requires to annotate the struct with #[builder(no_std)].

cc @killercup in case you want to give feedback. :-)

@colin-kiegel
Copy link
Owner Author

Oh, interesting - compiletest seems to not support #[no_std] that easily... Let's see.

Copy link
Collaborator

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Seems good, I have left one inline comment about String though.

if self.enabled {
trace!("Deriving build method `{}`.", self.ident.as_ref());
tokens.append(quote!(
#doc_comment
#vis fn #ident(#self_param)
-> ::std::result::Result<#target_ty #target_ty_generics, ::std::string::String>
-> #result<#target_ty #target_ty_generics, #string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the reason extern crate collections is required, right? Can we work around that? E.g., not give string error messages when using no_std but more simple ones?

Copy link
Owner Author

@colin-kiegel colin-kiegel Mar 25, 2017

Choose a reason for hiding this comment

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

Yep, I was thinking about that too.

I would say, that we could implement that as a separate feature. In fact this could just mean to provide more structured errors. I just opened issue #60 for that. How does that sound? :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@colin-kiegel colin-kiegel changed the title officially support #![no_std] #41 -- WIP officially support #![no_std] #41 Mar 25, 2017
@colin-kiegel colin-kiegel merged commit 7950525 into master Mar 25, 2017
@colin-kiegel colin-kiegel deleted the feature/no_std branch March 25, 2017 20:08
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.

2 participants