Skip to content
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

Manifest (de)serialization #106

Merged
merged 17 commits into from
Apr 20, 2021
Merged

Manifest (de)serialization #106

merged 17 commits into from
Apr 20, 2021

Conversation

maxded
Copy link
Contributor

@maxded maxded commented Jan 4, 2021

This PR contains major changes to the Manifest struct in ndk-build, changing it to a proper (de)serialization struct. The Cargo.toml's [package.metadata.android] is now directly deserialized into Manifest and can be serialized into an AndroidManifest.xml using quick-xml.

The AndroidManifest structure matches, android's manifest structure and it's components. Note that not all components have been implemented yet, just the ones that were already implemented.

One downside of my current implementation is the verbosity in the .toml file. Having to write [[package.metadata.android.application.activity.intent_filter]] is a bit much. If needed this could be improved by implementing Deserialize manually (I think, never implemented Deserialize myself yet).

All default values remain the same so for a user of cargo-apk, the only thing that changes is the syntax in their Cargo.toml, the generated AndroidManifest is exactly the same.

Hope this is a welcome change :)

@msiglreith msiglreith self-requested a review January 4, 2021 16:05
@msiglreith
Copy link
Contributor

@MarijnS95 would you be fine with the proposed changes as well?

@MarijnS95
Copy link
Member

MarijnS95 commented Jan 11, 2021

@msiglreith Yeah I'm totally content with the proposed refactor, which I suggested to do after wading through the "pipeline" (and stringformatted xml 🙈). This is still stuck in my review queue, will try to prioritize it first thing tomorrow morning :)

EDIT: This is now lifted into the weekend, got a bit distracted with other android-ndk issues and PRs, apologies!

Copy link
Contributor

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

In general I'm fine with the new manifest structure, thanks for that!
I would prefer to keep some of the defaults tho to better match the old manifest. In particular, it should be possible to run most applications using bare minimum changes to ones cargo toml. As example, the current ndk-examples won't execute on my phone due to missing MAIN action intent.

@maxded
Copy link
Contributor Author

maxded commented Jan 25, 2021

All the default values from the previous implementation should be present in my implementation except for

  • activity: label
  • activity: launchMode
  • activity: screenOrientation

Android provides default values for these components when missing from the manifest, which are the exact same as the previous default values so I left them out, should we be explicit here or is that ok?

@msiglreith
Copy link
Contributor

Android provides default values for these components when missing from the manifest, which are the exact same as the previous default values so I left them out, should we be explicit here or is that ok?

Thanks, should be good!

@msiglreith
Copy link
Contributor

I would go forward with merging it tomorrow if there are no reasons against doing so

@MarijnS95
Copy link
Member

Sorry for holding this up so long. I'll go through the changes now and let you know.

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Looking really good thus far! This review contains a couple questions and suggestions to simplify the code. Things to pay attention to:

  • Android requires certain fields to have a specific value. Some are filled with defaults upon deserialization, others are unconditionally overwritten during build. That should be streamlined and made more explicit to the user;
  • Tests: While the readme is nice I'd suggest moving it over to an example app that is actively parsed and tested by the CI. That way the documentation can hardly ever get out of sync with the actual parsing logic/structure in Rust.

cargo-apk/CHANGELOG.md Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
cargo-apk/README.md Outdated Show resolved Hide resolved
@maxded maxded requested a review from MarijnS95 March 9, 2021 21:01
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

That cleans up really nicely! Some nits on the last commit, will check the remaining comments after.

cargo-apk/CHANGELOG.md Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
@maxded
Copy link
Contributor Author

maxded commented Mar 12, 2021

@MarijnS95 think we are good to go now!

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

@maxded Thanks! We're almost there, just a couple more documentation changes. Be sure to check the unresolved comments above, we should either fix/discuss those here or open an issue to follow up on them.

ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
@maxded
Copy link
Contributor Author

maxded commented Mar 15, 2021

@MarijnS95 resolved all the comments above!

Be sure to check the unresolved comments above, we should either fix/discuss those here or open an issue to follow up on them.

What exactly did you mean here? Running cargo test --doc in CI or?

Comment on lines 250 to 251
/// - `name="android.hardware.vulkan.version"`: The minimum version of the Vulkan API required. See the [Android documentation](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_VULKAN_HARDWARE_VERSION)
/// for available levels and the respective Vulkan features required/provided.
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps worth mentioning that this is a bitmask with the same encoding as Vulkan version numbers, representing the value of VkPhysicalDeviceProperties::apiVersion (and has nothing to do with Vulkan features in the sense as the other two features).

@MarijnS95
Copy link
Member

What exactly did you mean here? Running cargo test --doc in CI or?

The question where to perform manifest default overrides: #106 (comment)

Testing all docs besides (target-specific) ndk docs was a separate bulletpoint in the "PR review description" apparently; regardless we should look into this.

- Moved manifest default overrides to `fn from_subcommand`
@maxded
Copy link
Contributor Author

maxded commented Mar 18, 2021

Moved the non-artifact dependent default overrides to the from_subcommand function as, like you mentioned, that makes more sense indeed.

@maxded maxded requested a review from MarijnS95 March 18, 2021 09:39
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Moved the non-artifact dependent default overrides to the from_subcommand function as, like you mentioned, that makes more sense indeed.

Great, thanks! Upon second thought it might have been better situated in fn build() (including the parse_from_toml call, cmd is available in ApkBuilder anyway) since no other call needs it, even though they all call fn build() now anyway. Bit unfortunate that we still need the clone and mut to set one or two extra fields basted on the Artifact to build.

Anyway, I guess this looks good now! Haven't given the final code a full read-through but the last diff addresses the remaining issue. Thanks for pulling it all the way through 🥳 !

@msiglreith Do you want to give this a quick look and make sure I didn't miss anything? Then how do we want to release this, just bump the version and throw it out in the wild, hoping all projects read the changelog and update their toml?

Copy link
Contributor

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

Really nice and thanks for the review! A few minor nitpicks from me (:

Then how do we want to release this, just bump the version and throw it out in the wild, hoping all projects read the changelog and update their toml?

Mostly, yeah 😄 With the current CHANGELOG and example manifest it should be pretty clear on how to transition imo.

ndk-build/src/manifest.rs Outdated Show resolved Hide resolved
ndk-build/CHANGELOG.md Outdated Show resolved Hide resolved
ndk-build/CHANGELOG.md Outdated Show resolved Hide resolved
@maxded
Copy link
Contributor Author

maxded commented Mar 22, 2021

Done!

@MarijnS95
Copy link
Member

Fix cargo doc

Not specifically the docs, but the rustdoc run disallows any warnings in documented code (/// ```rust stuff) and apparently also any code outside it! The test run (https://github.com/rust-windowing/android-ndk-rs/runs/2168935502) finds these issues as well but doesn't exit with a failure code. We'll need to add some explicit check/clippy runs to the CI in the future...

@@ -1,5 +1,7 @@
# Unreleased

- **Breaking:** uses `ndk-build`'s new (de)serialized `Manifest` struct to properly serialize a toml's `[package.metadata.android]` to an `AndroidManifest.xml`. The `[package.metadata.android]` now closely resembles the structure of [an android manifest file](https://developer.android.com/guide/topics/manifest/manifest-element). See [README](README.md) for an example of the new `[package.metadata.android]` structure and all manifest attributes that are currently supported.
Copy link
Member

Choose a reason for hiding this comment

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

See the README for...?

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

This all looks okay to me. I guess we're just too afraid to press the merge button on larger changesets and do a release, but we should push through anyhow. Let's make this happen and give it some wider attention 🎉

@MarijnS95 MarijnS95 merged commit 6703767 into rust-mobile:master Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants