Skip to content

Commit

Permalink
Add error message when using cfg(docsrs) with RUSTFLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 8, 2024
1 parent ddd35f9 commit 35b010f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/docsrs-error-1.60.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`
aborting due to previous error
1 change: 1 addition & 0 deletions .github/docsrs-error-nightly.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`
1 change: 1 addition & 0 deletions .github/docsrs-error-stable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`
54 changes: 54 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,57 @@ jobs:
cargo update -p syn --precise 2.0.67
- name: Build
run: cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }}

docsrs-error:
name: |
`cfg(docsrs)` error message ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{ matrix.features.description }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
target:
- { target: x86_64-unknown-linux-gnu, description: Native }
- { target: wasm32-unknown-unknown, description: Web }
- { target: wasm32v1-none, description: Wasm v1 }
rust:
- { version: "1.60", description: MSRV }
- { version: stable }
- { version: nightly }
# We don't check `serde` because it fails on the dependency itself already.
features:
- { features: "", no_std: false }
- { features: --no-default-features, no_std: true, description: (`no_std`) }
exclude:
- target: { target: x86_64-unknown-linux-gnu, description: Native }
rust: { version: nightly }
- target: { target: wasm32-unknown-unknown, description: Web }
rust: { version: nightly }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: "1.60" }
- target: { target: wasm32v1-none, description: Wasm v1 }
rust: { version: stable }
- target: { target: wasm32v1-none, description: Wasm v1 }
features: { no_std: false }

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
- name: Fix MSRV dependencies
if: matrix.rust.version == '1.60'
run: |
cargo update -p bumpalo --precise 3.14.0
cargo update -p serde --precise 1.0.210
cargo update -p syn --precise 2.0.67
- name: Build
env:
RUSTFLAGS: --cfg docsrs
run:
diff <(cargo build --target ${{ matrix.target.target }} ${{ matrix.features.features }}
--message-format json | jq -r "select(.reason == \"compiler-message\") |
.message.message") .github/docsrs-error-${{ matrix.rust.version }}.txt
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
#![cfg_attr(all(target_family = "wasm", not(feature = "std")), no_std)]
#![cfg_attr(all(test, target_family = "wasm"), no_main)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(all(doc, docsrs), feature(doc_cfg))]
#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))]
#![cfg_attr(
all(
Expand All @@ -173,9 +173,9 @@ mod time;
any(target_os = "unknown", target_os = "none"),
feature = "std"
),
docsrs
all(doc, docsrs)
))]
#[cfg_attr(docsrs, doc(cfg(all(Web, feature = "std"))))]
#[cfg_attr(all(doc, docsrs), doc(cfg(all(Web, feature = "std"))))]
pub mod web;

#[cfg(not(all(target_family = "wasm", any(target_os = "unknown", target_os = "none"))))]
Expand All @@ -187,6 +187,9 @@ use tests_web as _;
#[cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))]
pub use self::time::*;

#[cfg(all(not(doc), docsrs))]
compile_error!("`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`");

#[cfg(all(test, target_family = "wasm"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

Expand Down
6 changes: 3 additions & 3 deletions src/time/system_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
doc = "[`std::time::SystemTime`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html"
)]

#[cfg(all(doc, not(feature = "std")))]
#[cfg(all(all(doc, docsrs), not(feature = "std")))]
use core::error::Error;
use core::fmt::{self, Display, Formatter};
use core::ops::{Add, AddAssign, Sub, SubAssign};
Expand Down Expand Up @@ -162,6 +162,6 @@ impl Display for SystemTimeError {
}
}

#[cfg(any(feature = "std", docsrs))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg(any(feature = "std", all(doc, docsrs)))]
#[cfg_attr(all(doc, docsrs), doc(cfg(feature = "std")))]
impl Error for SystemTimeError {}

0 comments on commit 35b010f

Please sign in to comment.