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

Improve docs.rs builds #195

Merged
merged 2 commits into from
Sep 15, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The MSRV (Minimum Supported Rust Version) is 1.37.0, and typenum is tested
against this Rust version.

### Unreleased
- [removed] Remove `force_unix_path_separator` feature, make it the default
paholg marked this conversation as resolved.
Show resolved Hide resolved
- [added] docs.rs metadata and cfg options
- [added] Playground metadata

### 1.16.0 (2022-12-05)
- [added] `const INT` field to the `ToInt` trait.
Expand Down
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ scale-info = { version = "1.0", default-features = false, optional = true }
name = "typenum"

[features]
no_std = []
no_std = [] # Deprecated
i128 = []
strict = []
force_unix_path_separator = []
force_unix_path_separator = [] # Deprecated
const-generics = []
scale_info = ["scale-info/derive"]

[package.metadata.docs.rs]
features = ["i128", "const-generics"]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
features = ["i128", "const-generics"]
5 changes: 1 addition & 4 deletions build/generic_const_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ use super::*;
pub fn emit_impls() -> ::std::io::Result<()> {
let out_dir = ::std::env::var("OUT_DIR").unwrap();
let dest = ::std::path::Path::new(&out_dir).join("generic_const_mappings.rs");
println!(
"cargo:rustc-env=TYPENUM_BUILD_GENERIC_CONSTS={}",
dest.display()
);
let mut f = ::std::fs::File::create(&dest).unwrap();

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

Expand Down
12 changes: 10 additions & 2 deletions build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ pub fn gen_int(i: i64) -> IntCode {
)]
pub fn no_std() {}

#[cfg_attr(
feature = "force_unix_path_separator",
deprecated(
since = "1.17.0",
note = "the `force_unix_path_separator` flag is no longer necessary and will be removed in the future"
)
)]
pub fn force_unix_path_separator() {}

const HIGHEST: u64 = 1024;
fn uints() -> impl Iterator<Item = u64> {
// Use hardcoded values to avoid issues with cross-compilation.
Expand All @@ -95,12 +104,11 @@ fn main() {

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

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

no_std();
force_unix_path_separator();

// Header stuff here!
write!(
Expand Down
2 changes: 0 additions & 2 deletions build/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct Op {
pub fn write_op_macro() -> ::std::io::Result<()> {
let out_dir = ::std::env::var("OUT_DIR").unwrap();
let dest = ::std::path::Path::new(&out_dir).join("op.rs");
#[cfg(not(feature = "force_unix_path_separator"))]
println!("cargo:rustc-env=TYPENUM_BUILD_OP={}", dest.display());
let mut f = ::std::fs::File::create(&dest).unwrap();

// Operator precedence is taken from
Expand Down
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,20 @@
)]
#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))]
#![doc(html_root_url = "https://docs.rs/typenum/1.16.0")]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]

// For debugging macros:
// #![feature(trace_macros)]
// trace_macros!(true);

use core::cmp::Ordering;

#[cfg(feature = "force_unix_path_separator")]
mod generated {
include!(concat!(env!("OUT_DIR"), "/op.rs"));
include!(concat!(env!("OUT_DIR"), "/consts.rs"));
#[cfg(feature = "const-generics")]
include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs"));
}

#[cfg(not(feature = "force_unix_path_separator"))]
mod generated {
include!(env!("TYPENUM_BUILD_OP"));
include!(env!("TYPENUM_BUILD_CONSTS"));
#[cfg(feature = "const-generics")]
include!(env!("TYPENUM_BUILD_GENERIC_CONSTS"));
include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs"));
}

pub mod bit;
Expand Down
8 changes: 6 additions & 2 deletions src/type_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ impl_pow_f!(f64);

macro_rules! impl_pow_i {
() => ();
($t: ty $(, $tail:tt)*) => (
($(#[$meta:meta])* $t: ty $(, $tail:tt)*) => (
$(#[$meta])*
impl Pow<UTerm> for $t {
type Output = $t;
#[inline]
Expand All @@ -198,6 +199,7 @@ macro_rules! impl_pow_i {
}
}

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

$(#[$meta])*
impl Pow<Z0> for $t {
type Output = $t;
#[inline]
Expand All @@ -214,6 +217,7 @@ macro_rules! impl_pow_i {
}
}

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

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

#[test]
fn pow_test() {
Expand Down
Loading