80 releases

new 0.7.1 Apr 11, 2024
0.6.8 Sep 29, 2023
0.6.4 Apr 13, 2023
0.6.3 Nov 18, 2022
0.3.1 Mar 13, 2018

#180 in Cargo plugins

Download history 17/week @ 2023-12-23 2/week @ 2024-02-10 31/week @ 2024-02-17 26/week @ 2024-02-24 5/week @ 2024-03-02 28/week @ 2024-03-09 44/week @ 2024-03-16 4/week @ 2024-03-23 129/week @ 2024-03-30 251/week @ 2024-04-06

435 downloads per month

MIT/Apache

190KB
4.5K SLoC

Dinghy

rustc >= 1.74.0 MIT/Apache 2 Build and test

What?

Dinghy is a cargo extension to bring cargo workflow to cross-compilation situations.

Dinghy is specifically useful with "small" processor-based devices, like Android and iOS phones, or small single board computers like the Raspberry Pi. Situations where native compilation is not possible, or not practical.

Initially tests and benches were the primary objective of Dinghy, but now at Snips we use it to cross-compile our entire platform. This includes setting up the stage for cc and pkg-config crates in one single place.

If you are a Rust library author, you can run your tests and benches on your smartphone in minutes. And you should, at least once in a while.

Demo

Let's try how BurntSushi's byteorder handles f32 on a few arm devices, two smartphones, and a Raspberry Pi.

Demo

Phew. It works.

How?

Once dinghy knows about your toolchains and devices, you will be able to run tests and benches from a simple cargo command in any cargo project, most of the time without altering them.

Just add dinghy -d some_device between cargo and its subcommand:

cargo dinghy -d my_android test
cargo dinghy -d my_raspberry bench

By default, without -d, Dinghy will make a native build, just like cargo would do.

Getting started

Depending on your targets and your workstation, the ease of setting up Dinghy can vary.

  • Android is relatively easy, specifically if you already are a mobile developer.
  • iOS setup has a lot of steps, but at least Apple provides everything you will need. Once again, if you are an iOS developer, most of the heavy lifting has been already done. And if you are not, be aware that you won't have to pay anything.
  • other remote ssh-accessible devices are the easiest from dinghy point of view, but you will be on your own to obtain the toolchain for your device architecture and operating system. If your device is a Raspberry Pi running raspbian, we can help. :)

Advanced topics and features

  • Some projects need resources files for running their tests or benches. Dinghy tries its best to make it work in as many project/target configurations as possible but some projects need a bit of help.
  • In some bigger projects, you may need to filter your project's members depending on the platform you want to test.
  • Passing environment variables to your executable may sometimes be useful.
  • Dinghy offers an overlay system to "add" stuff to your toolchain sysroot. This allows you to add "stuff" to your build dependencies, like static libraries or headers without altering the sysroot toolchain.
  • The dinghy-build crate offers some build.rs features that are useful in the context of cross-compilation.

Using dinghy as a runner only

If your project already build for the target platform without dinghy and you only want to use dinghy to run code on a device, you can use dinghy's bundled runner directly. You simply need to register the dinghy as a runner in .cargo/config. Here's an example for all apple targets

[target.'cfg(all(any(target_arch="aarch64",target_arch="x86_64"),target_vendor="apple",any(target_os="ios",target_os="tvos",target_os="apple-watchos")))']
runner = "cargo dinghy runner --"

You can then run your tests directly with cargo test --target aarch64-apple-ios-sim for example.

Please note that the recommended way to use dinghy is as a cargo subcommand as it will set up quite a few things automatically for your project to even build.

The runner will try to auto-detect the platform if it is not passed (as in the above example)

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~12–26MB
~350K SLoC