Skip to content

Commit de034e2

Browse files
committed
Allow building as dependency on docs.rs with no features enabled
1 parent 32bdec7 commit de034e2

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

android-activity/build.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(dead_code)]
2-
31
fn build_glue_for_game_activity() {
42
for f in [
53
"GameActivity.h",
@@ -46,6 +44,16 @@ fn build_glue_for_game_activity() {
4644
}
4745

4846
fn main() {
49-
#[cfg(feature = "game-activity")]
50-
build_glue_for_game_activity();
47+
// Avoid re-running build script if nothing changed.
48+
println!("cargo:rerun-if-changed=build.rs");
49+
50+
if cfg!(feature = "game-activity") {
51+
build_glue_for_game_activity();
52+
}
53+
54+
// Whether this is used directly in or as a dependency on docs.rs.
55+
println!("cargo:rustc-check-cfg=cfg(used_on_docsrs)");
56+
if std::env::var("DOCS_RS").is_ok() {
57+
println!("cargo:rustc-cfg=used_on_docsrs");
58+
}
5159
}

android-activity/src/game_activity/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "game-activity")]
2-
31
use std::collections::HashMap;
42
use std::marker::PhantomData;
53
use std::ops::Deref;

android-activity/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ compile_error!(
140140
);
141141
#[cfg(all(
142142
not(any(feature = "game-activity", feature = "native-activity")),
143-
not(doc)
143+
not(any(doc, used_on_docsrs)),
144144
))]
145145
compile_error!(
146146
r#"Either "game-activity" or "native-activity" must be enabled as features
@@ -159,8 +159,18 @@ You may need to add a `[patch]` into your Cargo.toml to ensure a specific versio
159159
android-activity is used across all of your application's crates."#
160160
);
161161

162-
#[cfg_attr(any(feature = "native-activity", doc), path = "native_activity/mod.rs")]
163-
#[cfg_attr(any(feature = "game-activity", doc), path = "game_activity/mod.rs")]
162+
#[cfg_attr(feature = "native-activity", path = "native_activity/mod.rs")]
163+
#[cfg_attr(feature = "game-activity", path = "game_activity/mod.rs")]
164+
#[cfg_attr(
165+
all(
166+
// No activities enabled.
167+
not(any(feature = "native-activity", feature = "game-activity")),
168+
// And building docs.
169+
any(doc, used_on_docsrs),
170+
),
171+
// Fall back to documenting native activity.
172+
path = "native_activity/mod.rs"
173+
)]
164174
pub(crate) mod activity_impl;
165175

166176
pub mod error;

android-activity/src/native_activity/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(any(feature = "native-activity", doc))]
2-
31
use std::collections::HashMap;
42
use std::marker::PhantomData;
53
use std::panic::AssertUnwindSafe;

0 commit comments

Comments
 (0)