Skip to content

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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
Cargo.lock
10 changes: 0 additions & 10 deletions android-activity/.gitignore

This file was deleted.

16 changes: 12 additions & 4 deletions android-activity/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(dead_code)]

fn build_glue_for_game_activity() {
for f in [
"GameActivity.h",
Expand Down Expand Up @@ -46,6 +44,16 @@ fn build_glue_for_game_activity() {
}

fn main() {
#[cfg(feature = "game-activity")]
build_glue_for_game_activity();
// Avoid re-running build script if nothing changed.
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.
println!("cargo:rustc-check-cfg=cfg(used_on_docsrs)");
if std::env::var("DOCS_RS").is_ok() {
println!("cargo:rustc-cfg=used_on_docsrs");
}
}
2 changes: 0 additions & 2 deletions android-activity/src/game_activity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "game-activity")]

use std::collections::HashMap;
use std::marker::PhantomData;
use std::ops::Deref;
Expand Down
16 changes: 13 additions & 3 deletions android-activity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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
Expand All @@ -159,8 +159,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;
Expand Down
2 changes: 0 additions & 2 deletions android-activity/src/native_activity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(any(feature = "native-activity", doc))]

use std::collections::HashMap;
use std::marker::PhantomData;
use std::panic::AssertUnwindSafe;
Expand Down