-
Notifications
You must be signed in to change notification settings - Fork 365
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
android: Migrate from ndk-glue
to ndk-context
#641
Conversation
023f310
to
ed0a452
Compare
`ndk-glue` suffers one fatal flaw: it's "only" supposed to be used by the crate providing `fn main()` and only supposed to end up in the dependency graph once as it has `static` globals which get duplicated across versions. In the current case with `winit 0.26` still on `ndk-glue 0.5` but `cpal` on `ndk-glue 0.6` it'll always panic in `fn native_activity()` as the `static` globals on this version is not initialized. Introducing `ndk-context`: a crate that holds these `static`s, with the intention/premise to not see a breaking release /ever/ and make this a problem of the past. The crate is currently initialized with the VM and Android Context on `ndk-glue` 0.5.1 and 0.6.1 (0.4.1 pending) making it compatible with whatever is current, and the possibility for backporting to older `ndk-glue` versions too. See also: rust-mobile/ndk#211 rust-mobile/ndk#223
ed0a452
to
f8b05ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Hmm wait it failed in CI:
|
It seems that |
This looks to be an odd issues inside our macros, investigating... |
This might be because cpal is still on the 2015 edition? The macro might be emitting a wrong span that points to cpal's sources so rustc treats it as edition 2015 code. |
The issue is that And our fallback in I'm fixing both and will get back to you when it's done, sorry for the noise! |
In [RustAudio/cpal#641] we're seeing a [failure in `ndk-macro`] to turn a crate name with dashes into underscores as fallback, with the underlying issue that `proc-macro-crate` failed to find our crate in `Cargo.toml` when limited to a specific target cfg. According to [the Rust docs] it is perfectly possible to have `dev-dependencies` behind such a target predicate too. [RustAudio/cpal#641]: RustAudio/cpal#641 (comment) [failure in `ndk-macro`]: https://github.com/rust-windowing/android-ndk-rs/blob/9060d5dbea8bdd9aee9e42ef8e8375c35adbc271/ndk-macro/src/helper.rs#L64 [the Rust docs]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
I'll think about removing the erroneous fallback in |
In [RustAudio/cpal#641] we're seeing a [failure in `ndk-macro`] to turn a crate name with dashes into underscores as fallback, with the underlying issue that `proc-macro-crate` failed to find our crate in `Cargo.toml` when limited to a specific target cfg. According to [the Rust docs] it is perfectly possible to have `dev-dependencies` behind such a target predicate too. [RustAudio/cpal#641]: RustAudio/cpal#641 (comment) [failure in `ndk-macro`]: https://github.com/rust-windowing/android-ndk-rs/blob/9060d5dbea8bdd9aee9e42ef8e8375c35adbc271/ndk-macro/src/helper.rs#L64 [the Rust docs]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
`proc_macro_crate::crate_name` fails to find our `ndk-glue` crate when it sits inside `[target.'cfg(target_os = "android")'.dev-dependencies]` as shown in [RustAudio/cpal#641], with a fix pending in [bkchr/proc-macro-crate#15]. This function is only ever called with `"ndk-glue"` which is an invalid identifier and should have its dash replaced with an underscore to be valid. However, since this fallback doesn't seem to have been hit before (we've never received reports of `` `"ndk-glue"` is not a valid identifier ``) it is safe and desired to enforce the crate name to reside in `Cargo.toml` and `proc-macro-crate` being able to find it. [RustAudio/cpal#641]: https://github.com/RustAudio/cpal/runs/5203107529?check_suite_focus=true [bkchr/proc-macro-crate#15]: bkchr/proc-macro-crate#15
`proc_macro_crate::crate_name` fails to find our `ndk-glue` crate when it sits inside `[target.'cfg(target_os = "android")'.dev-dependencies]` as shown in [RustAudio/cpal#641], with a fix pending in [bkchr/proc-macro-crate#15]. This function is only ever called with `"ndk-glue"` which is an invalid identifier and should have its dash replaced with an underscore to be valid. However, since this fallback doesn't seem to have been hit before (we've never received reports of `` `"ndk-glue"` is not a valid identifier ``) it is safe and desired to enforce the crate name to reside in `Cargo.toml` and `proc-macro-crate` being able to find it. [RustAudio/cpal#641]: https://github.com/RustAudio/cpal/runs/5203107529?check_suite_focus=true [bkchr/proc-macro-crate#15]: bkchr/proc-macro-crate#15
`proc_macro_crate::crate_name` fails to find our `ndk-glue` crate when it sits inside `[target.'cfg(target_os = "android")'.dev-dependencies]` as shown in [RustAudio/cpal#641], with a fix pending in [bkchr/proc-macro-crate#15]. This function is only ever called with `"ndk-glue"` which is an invalid identifier and should have its dash replaced with an underscore to be valid. However, since this fallback doesn't seem to have been hit before (we've never received reports of `` `"ndk-glue"` is not a valid identifier ``) it is safe and desired to enforce the crate name to reside in `Cargo.toml` and `proc-macro-crate` being able to find it. [RustAudio/cpal#641]: https://github.com/RustAudio/cpal/runs/5203107529?check_suite_focus=true [bkchr/proc-macro-crate#15]: bkchr/proc-macro-crate#15
@est31 the fix to (The workaround has also been removed from |
Well, I'm not sure how this happened: I made sure to test the fix locally, yet it seems we're now hit by bkchr/proc-macro-crate#16... Not sure how I got it working without that at some point. |
@MarijnS95 it's alright, take your time. I'm impressed by how quickly you figured out the cause of the problem and came up with a solution! |
@est31 I just don't like making PRs (to Anyway, the second fix is merged and released now too. I double checked it locally and the CI should not fail on it now 🤞 |
Looks like we're all set now, the current issues also appear on |
Thanks again, please write if you want a release. As for the CI failures, yeah maybe the three failling jobs should be commented out or be allowed to fail. Ideally at least the windows job would be fixed tho. PRs welcome :). |
No need for a release from my side yet, just propagating our |
I don't have any hurry, I'm keeping my cpal and oboe forks for my project. But once both this PR and the oboe one hit a new release I will be able to remove some duplicate code, thanks to |
`proc_macro_crate::crate_name` fails to find our `ndk-glue` crate when it sits inside `[target.'cfg(target_os = "android")'.dev-dependencies]` as shown in [RustAudio/cpal#641], with a fix pending in [bkchr/proc-macro-crate#15]. This function is only ever called with `"ndk-glue"` which is an invalid identifier and should have its dash replaced with an underscore to be valid. However, since this fallback doesn't seem to have been hit before (we've never received reports of `` `"ndk-glue"` is not a valid identifier ``) it is safe and desired to enforce the crate name to reside in `Cargo.toml` and `proc-macro-crate` being able to find it. [RustAudio/cpal#641]: https://github.com/RustAudio/cpal/runs/5203107529?check_suite_focus=true [bkchr/proc-macro-crate#15]: bkchr/proc-macro-crate#15
In [RustAudio/cpal#641] we're seeing a [failure in `ndk-macro`] to turn a crate name with dashes into underscores as fallback, with the underlying issue that `proc-macro-crate` failed to find our crate in `Cargo.toml` when limited to a specific target cfg. According to [the Rust docs] it is perfectly possible to have `dev-dependencies` behind such a target predicate too. [RustAudio/cpal#641]: RustAudio/cpal#641 (comment) [failure in `ndk-macro`]: https://github.com/rust-windowing/android-ndk-rs/blob/9060d5dbea8bdd9aee9e42ef8e8375c35adbc271/ndk-macro/src/helper.rs#L64 [the Rust docs]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
In [RustAudio/cpal#641] we're seeing a [failure in `ndk-macro`] to turn a crate name with dashes into underscores as fallback, with the underlying issue that `proc-macro-crate` failed to find our crate in `Cargo.toml` when limited to a specific target cfg. According to [the Rust docs] it is perfectly possible to have `dev-dependencies` behind such a target predicate too. [RustAudio/cpal#641]: RustAudio/cpal#641 (comment) [failure in `ndk-macro`]: https://github.com/rust-windowing/android-ndk-rs/blob/9060d5dbea8bdd9aee9e42ef8e8375c35adbc271/ndk-macro/src/helper.rs#L64 [the Rust docs]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
ndk-glue
suffers one fatal flaw: it's "only" supposed to be used by the crate providingfn main()
and only supposed to end up in the dependency graph once as it hasstatic
globals which get duplicated across versions.In the current case with
winit 0.26
still onndk-glue 0.5
butcpal
onndk-glue 0.6
it'll always panic infn native_activity()
as thestatic
globals on this version is not initialized.Introducing
ndk-context
: a crate that holds thesestatic
s, with the intention/premise to not see a breaking release /ever/ and make this a problem of the past. The crate is currently initialized with the VM and Android Context onndk-glue
0.5.1 and 0.6.1 (0.4.1 pending) making it compatible with whatever is current, and the possibility for backporting to olderndk-glue
versions too.See also:
rust-mobile/ndk#211
rust-mobile/ndk#223