How can I run cargo tests on another machine without the Rust compiler?

允我心安 提交于 2019-12-01 06:38:49
kennytm

There are two kinds of tests supported by cargo test, one is the normal tests (#[test] fns and files inside tests/), the other is the doc tests.

The normal tests are as simple as running all binaries. The test is considered successful if it exits with error code 0.

Doc tests cannot be cross-tested. Doc tests are compiled and executed directly by rustdoc using the compiler libraries, so the compiler must be installed on the ARM machine to run the doc tests. In fact, running cargo test --doc when HOST ≠ TARGET will do nothing.

So, the answer to your last question is yes as long as you don't rely on doc-tests for coverage.


Starting from Rust 1.19, cargo supports target specific runners, which allows you to specify a script to upload and execute the test program on the ARM machine.

#!/bin/sh
set -e
adb push "$1" "/sdcard/somewhere/$1"
adb shell "chmod 755 /sdcard/somewhere/$1 && /sdcard/somewhere/$1" 
# ^ note: may need to change this line, see https://stackoverflow.com/q/9379400

Put this to your .cargo/config:

[target.arm-linux-androideabi]
runner = ["/path/to/your/run/script.sh"]

then cargo test --target=arm-linux-androideabi should Just Work™.


If your project is hosted on GitHub and uses Travis CI, you may also want to check out trust. It provides a pre-packaged solution for testing on many architectures including ARMv7 Linux on the CI (no Android unfortunately).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!