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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, it looks like we deliberately didn't check one in but forgot to exclude it globally.

The other gitignore in the crate should be useless as these files are created at the workspace root, i.e. here. In light of that, can you prefix these with / to ensure they only ignore this file in the root of the repository to match that?

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");
Comment on lines +47 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "nothing" should be clarified to "avoid re-running the build script if anything but the build script changed".

At first I thought this was redundant, but supposedly the build script reruns on any file changes inside the package directory by default unless specified with rerun-if - which won't be set without game-activity. As such, changing the rest of the crate is not "nothing" but we still don't need to re-run the build script in that case.


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");
Comment on lines +54 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link the doc here that says that cfg(docsrs) cannot be used because it's only set for the final/endpoint crate (i.e. winit)?

}
}
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")]
Comment on lines -162 to -163
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little fuzzy on the old implementation here. Setting doc would enable both path attributes, which one takes precedence?

Additionally, this together with the redundant cfg in the mod.rs should have enabled things to work on docs.rs without features, which should at least set cfg(doc) too?

#[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