Allow building as dependency on docs.rs with no features enabled

This commit is contained in:
Mads Marquart
2025-06-05 11:54:18 +02:00
committed by Robert Bragg
parent b9e883866e
commit e686e80112
4 changed files with 30 additions and 11 deletions
+17 -4
View File
@@ -1,5 +1,3 @@
#![allow(dead_code)]
fn build_glue_for_game_activity() {
let android_games_sdk =
std::env::var("ANDROID_GAMES_SDK").unwrap_or_else(|_err| "android-games-sdk".to_string());
@@ -94,6 +92,21 @@ fn build_glue_for_game_activity() {
}
fn main() {
#[cfg(feature = "game-activity")]
build_glue_for_game_activity();
// Enable Cargo's change-detection to avoid re-running build script if
// irrelvant parts changed. Using build.rs here is just a dummy used to
// disable the default "rerun on every change" behaviour Cargo has.
println!("cargo:rerun-if-changed=build.rs");
if cfg!(feature = "game-activity") {
build_glue_for_game_activity();
}
// Whether this is used directly in or as a dependency on docs.rs.
//
// `cfg(docsrs)` cannot be used, since it's only set for the crate being
// built, and not for any dependent crates.
println!("cargo:rustc-check-cfg=cfg(used_on_docsrs)");
if std::env::var("DOCS_RS").is_ok() {
println!("cargo:rustc-cfg=used_on_docsrs");
}
}
@@ -1,5 +1,3 @@
#![cfg(feature = "game-activity")]
use std::collections::HashMap;
use std::marker::PhantomData;
use std::ops::Deref;
+13 -3
View File
@@ -141,7 +141,7 @@ compile_error!(
);
#[cfg(all(
not(any(feature = "game-activity", feature = "native-activity")),
not(doc)
not(any(doc, used_on_docsrs)),
))]
compile_error!(
r#"Either "game-activity" or "native-activity" must be enabled as features
@@ -160,8 +160,18 @@ You may need to add a `[patch]` into your Cargo.toml to ensure a specific versio
android-activity is used across all of your application's crates."#
);
#[cfg_attr(any(feature = "native-activity", doc), path = "native_activity/mod.rs")]
#[cfg_attr(any(feature = "game-activity", doc), path = "game_activity/mod.rs")]
#[cfg_attr(feature = "native-activity", path = "native_activity/mod.rs")]
#[cfg_attr(feature = "game-activity", path = "game_activity/mod.rs")]
#[cfg_attr(
all(
// No activities enabled.
not(any(feature = "native-activity", feature = "game-activity")),
// And building docs.
any(doc, used_on_docsrs),
),
// Fall back to documenting native activity.
path = "native_activity/mod.rs"
)]
pub(crate) mod activity_impl;
pub mod error;
@@ -1,5 +1,3 @@
#![cfg(any(feature = "native-activity", doc))]
use std::collections::HashMap;
use std::marker::PhantomData;
use std::panic::AssertUnwindSafe;