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

Fix compile failure with non-cargo build systems #23

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{env, fs, path::PathBuf};

fn main() {
println!("cargo:rustc-cfg=const_fn_has_build_script");
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is like a marker that means "build-script was run". If the build-script was run, but the output of the build-script is broken, you should get an error.


let version = match Version::new() {
Some(version) => format!("{:#?}\n", version),
None => panic!("unexpected output from `rustc --version`"),
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ pub fn const_fn(args: TokenStream, input: TokenStream) -> TokenStream {
tokens
}
Arg::Version(req) => {
if req.major > 1 || req.minor > VERSION.minor {
if req.major > 1 || VERSION.as_ref().map_or(true, |v| req.minor > v.minor) {
func.print_const = false;
}
func.to_token_stream()
}
Arg::Nightly => {
if !VERSION.nightly {
if VERSION.as_ref().map_or(true, |v| !v.nightly) {
func.print_const = false;
}
func.to_token_stream()
Expand Down Expand Up @@ -208,4 +208,7 @@ struct Version {
nightly: bool,
}

const VERSION: Version = include!(concat!(env!("OUT_DIR"), "/version.rs"));
#[cfg(const_fn_has_build_script)]
const VERSION: Option<Version> = Some(include!(concat!(env!("OUT_DIR"), "/version.rs")));
#[cfg(not(const_fn_has_build_script))]
const VERSION: Option<Version> = None;