Skip to content

Commit 468d888

Browse files
committed
Put every function behind a feature gate
1 parent 12bb026 commit 468d888

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,34 @@ repository = "https://github.com/thejpster/tinyrlibc"
1212

1313
[build-dependencies]
1414
cc = "1.0"
15+
16+
[features]
17+
default = ["all"]
18+
all = [
19+
"abs",
20+
"strcmp",
21+
"strncmp",
22+
"strcpy",
23+
"strncpy",
24+
"strlen",
25+
"strtol",
26+
"strtoul",
27+
"strstr",
28+
"strchr",
29+
"atoi",
30+
"itoa",
31+
"snprintf",
32+
]
33+
abs = []
34+
strcmp = []
35+
strncmp = []
36+
strcpy = []
37+
strncpy = []
38+
strlen = []
39+
strtol = []
40+
strtoul = []
41+
strstr = []
42+
strchr = []
43+
atoi = []
44+
itoa = []
45+
snprintf = []

build.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
fn main() {
2-
// Build our snprintf substitute (which has to be C as Rust doesn't do varargs)
3-
cc::Build::new()
4-
.warnings(true)
5-
.extra_warnings(true)
6-
.flag("-std=c99")
7-
.file("./src/snprintf.c")
8-
.compile("clocal");
2+
if cfg!(feature = "snprintf") {
3+
// Build our snprintf substitute (which has to be C as Rust doesn't do varargs)
4+
cc::Build::new()
5+
.warnings(true)
6+
.extra_warnings(true)
7+
.flag("-std=c99")
8+
.file("./src/snprintf.c")
9+
.compile("clocal");
10+
}
911
}

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,67 @@
1313
#[allow(unused_imports)]
1414
use std as core;
1515

16+
#[cfg(feature = "abs")]
1617
mod abs;
18+
#[cfg(feature = "abs")]
1719
pub use self::abs::abs;
1820

21+
#[cfg(feature = "strcmp")]
1922
mod strcmp;
23+
#[cfg(feature = "strcmp")]
2024
pub use self::strcmp::strcmp;
2125

26+
#[cfg(feature = "strncmp")]
2227
mod strncmp;
28+
#[cfg(feature = "strncmp")]
2329
pub use self::strncmp::strncmp;
2430

31+
#[cfg(feature = "strcpy")]
2532
mod strcpy;
33+
#[cfg(feature = "strcpy")]
2634
pub use self::strcpy::strcpy;
2735

36+
#[cfg(feature = "strncpy")]
2837
mod strncpy;
38+
#[cfg(feature = "strncpy")]
2939
pub use self::strncpy::strncpy;
3040

41+
#[cfg(feature = "strlen")]
3142
mod strlen;
43+
#[cfg(feature = "strlen")]
3244
pub use self::strlen::strlen;
3345

46+
#[cfg(feature = "strtol")]
3447
mod strtol;
48+
#[cfg(feature = "strtol")]
3549
pub use self::strtol::strtol;
3650

51+
#[cfg(feature = "strtoul")]
3752
mod strtoul;
53+
#[cfg(feature = "strtoul")]
3854
pub use self::strtoul::strtoul;
3955

56+
#[cfg(feature = "strstr")]
4057
mod strstr;
58+
#[cfg(feature = "strstr")]
4159
pub use self::strstr::strstr;
4260

61+
#[cfg(feature = "strchr")]
4362
mod strchr;
63+
#[cfg(feature = "strchr")]
4464
pub use self::strchr::strchr;
4565

66+
#[cfg(feature = "atoi")]
4667
mod atoi;
68+
#[cfg(feature = "atoi")]
4769
pub use self::atoi::atoi;
4870

71+
#[cfg(feature = "itoa")]
4972
mod itoa;
73+
#[cfg(feature = "itoa")]
5074
pub use self::itoa::itoa;
5175

76+
#[cfg(feature = "snprintf")]
5277
mod snprintf;
5378

5479
/// `long long int`

0 commit comments

Comments
 (0)