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
|
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
ndk-gluesuffers 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 hasstaticglobals which get duplicated across versions.In the current case with
winit 0.26still onndk-glue 0.5butcpalonndk-glue 0.6it'll always panic infn native_activity()as thestaticglobals on this version is not initialized.Introducing
ndk-context: a crate that holds thesestatics, 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-glue0.5.1 and 0.6.1 (0.4.1 pending) making it compatible with whatever is current, and the possibility for backporting to olderndk-glueversions too.See also:
rust-mobile/ndk#211
rust-mobile/ndk#223