-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Techcable/feature/rustc-check-cfg
Automatically emit `rustc-check-cfg` directives for AutoCfg
- Loading branch information
Showing
6 changed files
with
147 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Rust | ||
/target | ||
/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
# NOTE: Cannot be in workspace because of rustc 1.0 support | ||
name = "autocfg-verify-check-cfg" | ||
description = "A dummy crate to verify autocfg is emitting check-cfg directives" | ||
version = "0.1.0" | ||
edition = "2015" | ||
# only for testing | ||
publish = false | ||
|
||
build = "build.rs" | ||
|
||
[build-dependencies] | ||
autocfg = { path = "../.." } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
extern crate autocfg; | ||
|
||
pub fn main() { | ||
let cfg = autocfg::AutoCfg::new().unwrap(); | ||
|
||
// | ||
// tests | ||
// | ||
|
||
// always true | ||
cfg.emit_rustc_version(1, 0); | ||
// should always be false | ||
cfg.emit_rustc_version(7, std::u32::MAX as usize); | ||
|
||
// always true | ||
cfg.emit_has_path("std::vec::Vec"); | ||
cfg.emit_path_cfg("std::vec::Vec", "has_path_std_vec"); | ||
// always false | ||
cfg.emit_has_path("dummy::DummyPath"); | ||
cfg.emit_path_cfg("dummy::DummyPath", "has_path_dummy"); | ||
|
||
// always true | ||
cfg.emit_has_trait("std::ops::Add"); | ||
cfg.emit_trait_cfg("std::ops::Add", "has_trait_add"); | ||
// always false | ||
cfg.emit_has_trait("dummy::DummyTrait"); | ||
cfg.emit_trait_cfg("dummy::DummyTrait", "has_trait_dummy"); | ||
|
||
// always true | ||
cfg.emit_has_type("i32"); | ||
cfg.emit_type_cfg("i32", "has_type_i32"); | ||
// always false | ||
cfg.emit_has_type("i7billion"); | ||
cfg.emit_type_cfg("i7billion", "has_type_i7billion"); | ||
|
||
// always true | ||
cfg.emit_expression_cfg("3 + 7", "has_working_addition"); | ||
// always false | ||
cfg.emit_expression_cfg("3 ^^^^^ 12", "has_working_5xor"); | ||
|
||
// always true | ||
cfg.emit_constant_cfg("7", "has_const_7"); | ||
// false - Opening file should never be `const` | ||
cfg.emit_constant_cfg("std::fs::File::open(\"foo.txt\")", "has_const_file_open"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![allow(unknown_lints)] | ||
#![deny(unexpected_cfgs)] | ||
|
||
macro_rules! test_cfgs { | ||
($($cfg:ident,)*) => {$({ | ||
let cfg_desc = format!("cfg!({})", stringify!($cfg)); | ||
if cfg!($cfg) { | ||
println!("Enabled: {}", cfg_desc); | ||
} else { | ||
println!("Disabled: {}", cfg_desc); | ||
} | ||
})*}; | ||
|
||
} | ||
|
||
pub fn main() { | ||
test_cfgs!( | ||
// emit_rustc_version | ||
rustc_1_0, | ||
rustc_7_4294967295, | ||
// emit_has_path, emit_path_cfg | ||
has_std__vec__Vec, | ||
has_path_std_vec, | ||
has_dummy__DummyPath, | ||
has_path_dummy, | ||
// emit_has_trait, emit_trait_cfg | ||
has_std__ops__Add, | ||
has_trait_add, | ||
has_dummy__DummyTrait, | ||
has_trait_dummy, | ||
// emit_has_type, has_type_i32 | ||
has_i32, | ||
has_type_i32, | ||
has_i7billion, | ||
has_type_i7billion, | ||
// emit_expression_cfg | ||
has_working_addition, | ||
has_working_5xor, | ||
// emit_constant_cfg | ||
has_const_7, | ||
has_const_file_open, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters