Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd macros to get the values of configuration flags #1258
Conversation
alexcrichton
added
T-lang
T-libs
labels
Aug 16, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks @dylanmckay! Would it be possible to scale this back to solve the problem at hand? This is adding quite a bit of surface area which looks like it may not all be necessary to solve the motivation at hand. For example, is I also think that the |
This comment has been minimized.
This comment has been minimized.
|
Guh sorry for the early comment: your example of: pub mod cfg_ident!(target_os);Have you tested this? We can't, for example, do This may also want to consider what to do with the case that a Finally, the naming of |
This comment has been minimized.
This comment has been minimized.
|
Hello @alexcrichton! Thanks the the feedback - you raise very valid points. I originally planned on adding a single
With regards to
I would prefer the caller of the macro to be able to use the macro and have it expand into an unsuffixed integer literal - that way the type of the integer can be inferred automatically. This has several benefits:
On that note, perhaps
This is a good idea. We could add a |
This comment has been minimized.
This comment has been minimized.
|
I am very much for the alternative about Wild suggestion: |
This comment has been minimized.
This comment has been minimized.
|
There's an unfortunate hitch here: #[cfg(feature = "foo")]
fn foo() {}
#[cfg(feature = "bar")]
fn bar() {}
#[cfg(feature = "baz")]
fn baz() {} |
nikomatsakis
assigned
pnkfelix
Aug 20, 2015
This comment has been minimized.
This comment has been minimized.
|
Is there any way to have fewer macros here? |
This comment has been minimized.
This comment has been minimized.
|
to expand upon @nikomatsakis 's note, there was some informal discussion of maybe employing some sort of duck-typing in order to reduce the number of macros. |
alexcrichton
referenced this pull request
Nov 11, 2015
Merged
RFC: Improve Cargo target-specific dependencies #1361
This comment has been minimized.
This comment has been minimized.
|
@dylanmckay have you given any further thought on ways to reduce the number of macros here? I did see the suggestion in the alternatives section; but I'm curious if you've had further thoughts on whether we can do something more aggressive... |
This comment has been minimized.
This comment has been minimized.
|
Ideally, I think it would be best to expand the macro into a special type which can be coerced into either an integer or a string, depending on whatever type inference decides, and the value of the flag. This would allow us to have a Anything other than that is simply working around the fact that macros aren't typed. You should be able to do if cfg_value!(target_os) == "windows" ||
cfg_value!(custom_feature) == 12 { .. }I'm not sure how well this would play with the inference engine. @pnkfelix What are your thoughts? Have a single macro for several types, or have both |
aturon
added
the
I-nominated
label
Feb 10, 2016
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
My own personal opinion here is that it may be a bit premature to add these macros just yet, but we may want something along these lines eventually! The design here I think may need some improvement in terms of ergonomics and returned types. |
This comment has been minimized.
This comment has been minimized.
poelzi
commented
Feb 16, 2016
This would look much better, +1 for cfg_value!(foo, Option) |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and the conclusion was to close this RFC for now. We're specifically still worried about what these macros would do in the face of a cfg being defined multiple times (as @huonw mentioned), and it seems like the names/semantics of the macros here may want to have more consensus before moving forward. The next steps here would probably be to start a thread on the internals or users forums to see what others' use cases might look like and get feedback on the design here. There's unfortunately a number of downsides to Thanks again for the RFC though @dylanmckay! |
dylanmckay commentedAug 16, 2015
This RFC adds four macros which take a compile-time configuration flag (e.g.
target_os) and evaluate to either a compile time integer literal, float literal, string literal, or an identifier.There is an implementation of it in Rust
PR 27855(although it is missingcfg_ident!).Rendered