[SOLVED] Can you precompile a crate from 2018 rust for use in a 2015 compiler?

I’m working on android-based projects, and therefore I use cargo-apk, but unfortunately this hasn’t been updated yet for rust 2018, and one of my dependencies depends on the latest version of another crate, which has already “migrated”, and so can I precompile it for use in cargo-apk which hasn’t migrated yet to use a rust 2018 compiler?
Like something similar to a c++/c library but as transparent as simply using extern crate?
Edit: Sorry I pressed tab instead of ``, and then accidentally “enter”

You can depend on a 2818 crate in a 2015 crate. All that matters is that your rustc version is 1.31 or newer.

1 Like

There’s only a converter for 2015 → 2018 migration, not the other way.

Rust 1.31 supports both editions at the same time, so if you have that version or newer, it wouldn’t matter (2015 projects support 2018 libraries).

Rust 1.30 and older support only 2015 edition, so the only way is to upgrade the compiler.

1 Like

I’ve managed to gather the following:

  • I’m failing to compile stb_truetype = "0.2.5"
  • I have the following rustc output:
$ rustc -V
rustc 1.33.0-nightly (2d3e909e4 2018-12-22)
  • I get the following output from running cargo apk build:
$ cargo apk build
Compiling android_native_app_glue.c
Compiling injected-glue
Compiling glue_obj
Compiling crate
warning: unused manifest key: package.edition
   Compiling stb_truetype v0.2.5
   Compiling crossbeam-epoch v0.3.1
   Compiling gl v0.11.0
   Compiling glutin v0.19.0
   Compiling serde_derive v1.0.82
   Compiling opengles_graphics v0.1.0 (file:///mnt/z/android/android_base/opengles_graphics)
   Compiling png v0.6.2
error[E0432]: unresolved import `byteorder`
 --> /home/User/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.5/src/lib.rs:9:5
9 | use byteorder::{BigEndian as BE, ByteOrder};
  |     ^^^^^^^^^ maybe a missing `extern crate byteorder;`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `stb_truetype`.
Build failed, waiting for other jobs to finish...
error: build failed
  • And I would like to emphasize that I have specified the following in my Cargo.toml:
name = "base_test"
version = "0.1.0"
edition = "2018"

and it’s failing to take note that I’ve specified this in edition
I’m using cargo-apk as per cargo install cargo-apk -force, and am getting the above error.
After compiling cargo-apk from source, there seems to be a bug in it currently :confused::

$ cargo apk build
error: Expected `build`, `install`, `run`, or `logcat`

which is pretty unfortunate.

Looks like the last release of cargo-apk was 1 year ago. This PR was merged a few weeks ago, which claims to fix Rust 2018 crates: https://github.com/tomaka/android-rs-glue/pull/189

I can’t comment on why it would show that error, but building from source should be done with cargo install --path . --force from within the git repo.

1 Like

What happens here is that cargo-apk is statically linked against old version of Cargo, so, effectively, you are building your project with a Cargo that doesn’t have a concept of editions yet. The fix is, as that PR does, to update the version of Cargo dependency. The proper fix would be to change cargo-apk to not link with cargo, and use it via cli interface, but I don’t know if that is feasible.


I wasn’t aware you could do that in the GitHub repo, but what I did was cargo build and then mv ./target/debug/cargo-apk ~/.cargo/bin/ , which I presume is equivalent.
So what I gather is that I just have to wait until they’re done implementing the 2018 edition support?

Thanks to all!
It actually seems to be a minor error in their implementation with clap, and the call to cargo apk build looks at apk instead of build, so it’s as simple as cargo-apk build for a workaround, because ~/.cargo/bin is in PATH.