Skip to content

Commit 3483b93

Browse files
committed
Fix compiling -sys crates on docs.rs
We only have control over features when we're the crate being compiled, in other cases the parent crate should control which runtime to use, so we can't just check DOCS_RS - otherwise they'll error out because the wrong runtime was selected.
1 parent 08a60d4 commit 3483b93

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

block-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ unstable-winobjc = ["objc-sys/unstable-winobjc", "gnustep-1-8"]
4646
# Link to ObjFW
4747
unstable-objfw = []
4848

49+
# Private
50+
unstable-docrs = ["objc-sys"] # Need `objc-sys` on certain platforms
51+
4952
[dependencies]
5053
objc-sys = { path = "../objc-sys", version = "=0.2.0-alpha.1", default-features = false, optional = true }
5154

5255
[package.metadata.docs.rs]
5356
default-target = "x86_64-apple-darwin"
5457
no-default-features = true
58+
features = ["unstable-docrs"]
5559

5660
targets = [
5761
# MacOS

block-sys/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn main() {
1212
let mut gnustep = env::var_os("CARGO_FEATURE_GNUSTEP_1_7").is_some();
1313
let objfw = env::var_os("CARGO_FEATURE_UNSTABLE_OBJFW").is_some();
1414

15-
if std::env::var("DOCS_RS").is_ok() {
15+
// Only when the crate is being compiled directly
16+
if cfg!(feature = "unstable-docsrs") {
1617
if let "macos" | "ios" | "tvos" | "watchos" = &*target_os {
1718
apple = true;
1819
// Add cheaty #[cfg(feature = "apple")] directive

objc-sys/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ unstable-objfw = []
4747

4848
# Private
4949
unstable-exception = ["cc"]
50+
unstable-docrs = []
5051

5152
[build-dependencies]
5253
cc = { version = "1", optional = true }
5354

5455
[package.metadata.docs.rs]
5556
default-target = "x86_64-apple-darwin"
5657
no-default-features = true
58+
features = ["unstable-docrs"]
5759

5860
targets = [
5961
# MacOS

objc-sys/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ fn main() {
7474
let objfw = env::var_os("CARGO_FEATURE_UNSTABLE_OBJFW").is_some();
7575

7676
// Choose defaults when generating docs
77-
if std::env::var("DOCS_RS").is_ok() {
77+
// Only when the crate is being compiled directly
78+
if cfg!(feature = "unstable-docsrs") {
7879
if let "macos" | "ios" | "tvos" | "watchos" = &*target_os {
7980
apple = true;
8081
} else {
@@ -100,7 +101,7 @@ fn main() {
100101
}
101102
(false, true, false) => {
102103
// Choose defaults when generating docs
103-
if std::env::var("DOCS_RS").is_ok() {
104+
if cfg!(feature = "unstable-docsrs") {
104105
if "windows" == target_os {
105106
WinObjC
106107
} else {
@@ -229,6 +230,10 @@ fn main() {
229230
if std::env::var("DOCS_RS").is_ok() {
230231
// docs.rs doesn't have clang, so skip building this. The
231232
// documentation will still work since it doesn't need to link.
233+
//
234+
// This is independent of the `unstable-docrs` flag; we never want
235+
// to try invoking clang on docs.rs, whether we're the crate being
236+
// documented directly, or is a dependency of another crate.
232237
return;
233238
}
234239
println!("cargo:rerun-if-changed=extern/exception.m");

0 commit comments

Comments
 (0)