3 个版本
0.1.2 | 2022 年 11 月 21 日 |
---|---|
0.1.1 | 2022 年 8 月 23 日 |
0.1.0 | 2022 年 6 月 16 日 |
#332 在 Cargo 插件 中
24 每月下载量
68KB
1.5K SLoC
cargo-acap
用于构建适用于 AXIS 相机应用平台 的 Rust 程序的工具。
示例
$ cargo install cargo-acap
…
Installed package `cargo-acap v0.1.0` (executable `cargo-acap`)
$ cargo new --bin your-app
Created binary (application) `your-app` package
$ cd your-app/
$ cargo acap build
cargo-acap: building ACAP package `your-app` using Docker image trunnion/cargo-acap-build:1.60.0
…
Finished release [optimized] target(s) in 0.56s
$ ls target/acap/*.* | cat
target/acap/your-app_0.1.0_aarch64.eap
target/acap/your-app_0.1.0_aarch64.elf
target/acap/your-app_0.1.0_armv5tej.eap
target/acap/your-app_0.1.0_armv5tej.elf
target/acap/your-app_0.1.0_armv6.eap
target/acap/your-app_0.1.0_armv6.elf
target/acap/your-app_0.1.0_armv7.eap
target/acap/your-app_0.1.0_armv7.elf
target/acap/your-app_0.1.0_armv7hf.eap
target/acap/your-app_0.1.0_armv7hf.elf
target/acap/your-app_0.1.0_mips.eap
target/acap/your-app_0.1.0_mips.elf
cargo-acap
使用专门用于为 AXIS 设备编译 Rust 的 Docker 镜像来构建您的应用程序。因此,为了构建,需要安装并运行 Docker。
应用程序组织
foo/
Cargo.toml Rust project configuration + `[package.metadata.acap]`
data/ Copied to `/usr/local/packages/foo/data/`, i.e. `./data/`
src/
main.rs `fn main()`
target/
acap/
foo_0.1.0_aarch64.eap An ACAP package suitable for AArch64 devices
foo_0.1.0_aarch64.elf The executable inside foo_0.1.0_aarch64.eap prior to stripping symbols
…4 more…
foo_0.1.0_mips.eap An ACAP package suitable for MIPS devices
foo_0.1.0_mips.elf The executable inside foo_0.1.0_mips.eap prior to stripping symbols
条件编译
cargo acap
使用 target_vendor = "axis"
构建您的应用程序,通过 条件编译 使单个源树支持设备和离线使用。
#[cfg(target_vendor = "axis")]
fn foo() {
// call on-device APIs
}
#[cfg(not(target_vendor = "axis"))]
fn foo() {
// call off-device APIs
}
fn bar() {
if cfg!(target_vendor = "axis") {
// on-device
} else {
// off-device
}
}
#[cfg_attr(target_vendor = "axis", path = "baz_on_device.rs")]
#[cfg_attr(not(target_vendor = "axis"), path = "baz_off_device.rs")]
mod baz;
#[test]
#[cfg_attr(not(target_vendor = "axis"), ignore)]
fn quxx() {
// this test will run everywhere, but will be ignored if not on-device
}
打包
cargo acap
构建您的应用程序的可执行文件,并将其打包成 .eap
应用程序包。该包包含元数据,默认设置为合理的值,但可以通过 Cargo.toml
覆盖。
[package.metadata.acap]
# The machine-friendly name of the package. Used for:
#
# * Installation path: `/usr/local/packages/<app_name>`
# * Executable path: `/usr/local/packages/<app_name>/<app_name>`
# * Generated package names: `<app_name>_1_2_3_arch.eap`
# * Myriad related files
#
# app_name = ""
# A user-friendly package name. The name will be displayed in the Axis product's web pages.
# display_name = ""
# The application name that will be displayed in the web pages' left-hand side menu.
# menu_name = ""
# The name of the vendor that created the application.
# vendor = ""
# The URL of the vendor's home page, to be linked in the product's web pages.
# vendor_homepage_url = ""
# The command line arguments to pass when the application is launched normally.
# launch_arguments = ""
# The command line arguments to pass when the application is executed to perform a custom license check, if using custom
# licensing.
# license_check_arguments = ""
# The Axis-assigned application ID, if using Axis licensing.
# axis_application_id = ""
# The start mode to use for this application.
# (One of: "respawn", "once", "never")
# start_mode = ""
目标
不同的 AXIS 产品使用不同的 SoC,其中包含不同的处理器。 cargo acap
提供一个包含构建各种 AXIS 设备所需所有内容的 Docker 构建环境。这些目标在 cargo acap targets table
中描述。
cargo acap target |
Rust --target
|
---|---|
ARM 64位架构 |
aarch64-axis-linux-gnu |
armv5tej |
armv5te-axis-linux-gnueabi |
armv6 |
arm-axis-linux-gnueabi |
armv7 |
armv7-axis-linux-gnueabi |
armv7hf |
armv7-axis-linux-gnueabihf |
mips |
mipsel-axis-linux-gnu |
cargo acap
专门针对AXIS产品,因此左侧使用缩写目标名称。为了完整性,这里展示了由环境变量 cargo-acap-build
定义的Rust目标三元组。
这些目标与以下命令 cargo acap targets soc_table
列出的系统芯片相对应。
SOC | 年份 | cargo acap target |
Rust --target
|
---|---|---|---|
Axis ARTPEC-1 | 1999 | (不兼容) | (不兼容) |
Axis ARTPEC-2 | 2003 | (不兼容) | (不兼容) |
Axis ARTPEC-3 | 2007 | (不兼容) | (不兼容) |
Ambarella A5S | 2010 | armv6 |
arm-axis-linux-gnueabi |
Axis ARTPEC-4 | 2011 | mips |
mipsel-axis-linux-gnu |
Ambarella S2 | 2012 | armv7 |
armv7-axis-linux-gnueabi |
Ambarella S2E | 2012 | armv7hf |
armv7-axis-linux-gnueabihf |
Ambarella S2L | 2012 | armv7hf |
armv7-axis-linux-gnueabihf |
Axis ARTPEC-5 | 2013 | mips |
mipsel-axis-linux-gnu |
NXP i.MX 8 QP | 2013 | ARM 64位架构 |
aarch64-axis-linux-gnu |
Ambarella S3L | 2014 | armv7hf |
armv7-axis-linux-gnueabihf |
Ambarella S5 | 2016 | ARM 64位架构 |
aarch64-axis-linux-gnu |
Ambarella S5L | 2016 | ARM 64位架构 |
aarch64-axis-linux-gnu |
Hi3516C V300 | 2016 | armv5tej |
armv5te-axis-linux-gnueabi |
Hi3719C V100 | 2016 | armv7hf |
armv7-axis-linux-gnueabihf |
Axis ARTPEC-6 | 2017 | armv7hf |
armv7-axis-linux-gnueabihf |
Axis ARTPEC-7 | 2019 | armv7hf |
armv7-axis-linux-gnueabihf |
AXIS产品接口指南[链接]详细描述了许多硬件配置,尽管它是不完整的。检查您设备的root.Properties.System.Soc
和.Architecture
参数以查看您的特定设备使用的内容。
cargo acap build
默认启用所有目标。这可以在Cargo.toml
中覆盖。
[package.metadata.acap]
targets = ["aarch64", "armv7", "armv7hf"]
依赖关系
~38–50MB
~1M SLoC