Skip to content

Commit bbac3bf

Browse files
authored
Improve docs.rs builds (#195)
1 parent 530ec75 commit bbac3bf

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The MSRV (Minimum Supported Rust Version) is 1.37.0, and typenum is tested
66
against this Rust version.
77

88
### Unreleased
9+
- [removed] Remove `force_unix_path_separator` feature, make it the default
10+
- [added] docs.rs metadata and cfg options
11+
- [added] Playground metadata
912

1013
### 1.16.0 (2022-12-05)
1114
- [added] `const INT` field to the `ToInt` trait.

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ scale-info = { version = "1.0", default-features = false, optional = true }
2525
name = "typenum"
2626

2727
[features]
28-
no_std = []
28+
no_std = [] # Deprecated
2929
i128 = []
3030
strict = []
31-
force_unix_path_separator = []
31+
force_unix_path_separator = [] # Deprecated
3232
const-generics = []
3333
scale_info = ["scale-info/derive"]
34+
35+
[package.metadata.docs.rs]
36+
features = ["i128", "const-generics"]
37+
rustdoc-args = ["--cfg", "docsrs"]
38+
39+
[package.metadata.playground]
40+
features = ["i128", "const-generics"]

build/generic_const_mappings.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ use super::*;
33
pub fn emit_impls() -> ::std::io::Result<()> {
44
let out_dir = ::std::env::var("OUT_DIR").unwrap();
55
let dest = ::std::path::Path::new(&out_dir).join("generic_const_mappings.rs");
6-
println!(
7-
"cargo:rustc-env=TYPENUM_BUILD_GENERIC_CONSTS={}",
8-
dest.display()
9-
);
106
let mut f = ::std::fs::File::create(&dest).unwrap();
117

128
#[allow(clippy::write_literal)]
@@ -22,6 +18,7 @@ use generic_const_mappings::*;
2218
/// The main type to use here is [`U`], although [`Const`] and [`ToUInt`] may be needed
2319
/// in a generic context.
2420
#[allow(warnings)] // script-generated code
21+
#[cfg(feature = \"const-generics\")] // hints at doc_auto_cfg
2522
pub mod generic_const_mappings {
2623
use crate::*;
2724

build/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ pub fn gen_int(i: i64) -> IntCode {
7777
)]
7878
pub fn no_std() {}
7979

80+
#[cfg_attr(
81+
feature = "force_unix_path_separator",
82+
deprecated(
83+
since = "1.17.0",
84+
note = "the `force_unix_path_separator` flag is no longer necessary and will be removed in the future"
85+
)
86+
)]
87+
pub fn force_unix_path_separator() {}
88+
8089
const HIGHEST: u64 = 1024;
8190
fn uints() -> impl Iterator<Item = u64> {
8291
// Use hardcoded values to avoid issues with cross-compilation.
@@ -95,12 +104,11 @@ fn main() {
95104

96105
let out_dir = env::var("OUT_DIR").unwrap();
97106
let dest = Path::new(&out_dir).join("consts.rs");
98-
#[cfg(not(feature = "force_unix_path_separator"))]
99-
println!("cargo:rustc-env=TYPENUM_BUILD_CONSTS={}", dest.display());
100107

101108
let mut f = File::create(&dest).unwrap();
102109

103110
no_std();
111+
force_unix_path_separator();
104112

105113
// Header stuff here!
106114
write!(

build/op.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ struct Op {
1818
pub fn write_op_macro() -> ::std::io::Result<()> {
1919
let out_dir = ::std::env::var("OUT_DIR").unwrap();
2020
let dest = ::std::path::Path::new(&out_dir).join("op.rs");
21-
#[cfg(not(feature = "force_unix_path_separator"))]
22-
println!("cargo:rustc-env=TYPENUM_BUILD_OP={}", dest.display());
2321
let mut f = ::std::fs::File::create(&dest).unwrap();
2422

2523
// Operator precedence is taken from

src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,20 @@
6060
)]
6161
#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))]
6262
#![doc(html_root_url = "https://docs.rs/typenum/1.16.0")]
63+
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
6364

6465
// For debugging macros:
6566
// #![feature(trace_macros)]
6667
// trace_macros!(true);
6768

6869
use core::cmp::Ordering;
6970

70-
#[cfg(feature = "force_unix_path_separator")]
7171
mod generated {
7272
include!(concat!(env!("OUT_DIR"), "/op.rs"));
7373
include!(concat!(env!("OUT_DIR"), "/consts.rs"));
74-
#[cfg(feature = "const-generics")]
75-
include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs"));
76-
}
7774

78-
#[cfg(not(feature = "force_unix_path_separator"))]
79-
mod generated {
80-
include!(env!("TYPENUM_BUILD_OP"));
81-
include!(env!("TYPENUM_BUILD_CONSTS"));
8275
#[cfg(feature = "const-generics")]
83-
include!(env!("TYPENUM_BUILD_GENERIC_CONSTS"));
76+
include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs"));
8477
}
8578

8679
pub mod bit;

src/type_operators.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ impl_pow_f!(f64);
189189

190190
macro_rules! impl_pow_i {
191191
() => ();
192-
($t: ty $(, $tail:tt)*) => (
192+
($(#[$meta:meta])* $t: ty $(, $tail:tt)*) => (
193+
$(#[$meta])*
193194
impl Pow<UTerm> for $t {
194195
type Output = $t;
195196
#[inline]
@@ -198,6 +199,7 @@ macro_rules! impl_pow_i {
198199
}
199200
}
200201

202+
$(#[$meta])*
201203
impl<U: Unsigned, B: Bit> Pow<UInt<U, B>> for $t {
202204
type Output = $t;
203205
#[inline]
@@ -206,6 +208,7 @@ macro_rules! impl_pow_i {
206208
}
207209
}
208210

211+
$(#[$meta])*
209212
impl Pow<Z0> for $t {
210213
type Output = $t;
211214
#[inline]
@@ -214,6 +217,7 @@ macro_rules! impl_pow_i {
214217
}
215218
}
216219

220+
$(#[$meta])*
217221
impl<U: Unsigned + NonZero> Pow<PInt<U>> for $t {
218222
type Output = $t;
219223
#[inline]
@@ -228,7 +232,7 @@ macro_rules! impl_pow_i {
228232

229233
impl_pow_i!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize);
230234
#[cfg(feature = "i128")]
231-
impl_pow_i!(u128, i128);
235+
impl_pow_i!(#[cfg_attr(docsrs, doc(cfg(feature = "i128")))] u128, i128);
232236

233237
#[test]
234238
fn pow_test() {

0 commit comments

Comments
 (0)