使用没有stdlib的货物的集合

时间:2016-01-21 21:03:51

标签: embedded rust rust-cargo

我目前正在尝试设置嵌入式Rust项目。为此,如果我可以使用collections crate(以及alloc crate,那将是很好的,因为collections}需要它。有没有一种简单的方法来实现这一目标?我目前在Cargo.toml

中有以下依赖项
[build-dependencies]
gcc = "0.3"

[dependencies]
rust-libcore = "*"

[dependencies.rlibc]
git = "https://github.com/hackndev/rlibc"
branch = "zinc"

使用它们如下:

#![no_std]
#![crate_type="staticlib"]
#![feature(lang_items)]
#![feature(start)]

// This is not found when building with Cargo
extern crate collections;

//#[cfg(target_os = "none")]
extern crate rlibc;

#[start]
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
    // or some call like this
    core::collections::Vec::new();

    0
}

是否有一种简单的方法可以包含collections crate?

1 个答案:

答案 0 :(得分:0)

一种可能的解决方案是自己编译。这需要检查Rust源。我没有一个工作环境来测试这个,所以采取一些盐的建议。从概念上讲,你会做这样的事情:

cd $RUST_SRC_DIR
rustc --version --verbose | grep commit-hash # Grab the hash
git checkout $RUSTC_HASH
mkdir cross-compiled-libraries
rustc --target=arm-whatever-whatever -O src/libcollections/lib.rs \
      --out-dir cross-compiled-libraries

对您需要的任何库重复最后一步。其中很多都取自Embedded Rust Right Now!中的想法。

这个解决方案的一个大问题是libcollections需要一个分配器。通常,有jemalloc或系统分配器。我不知道你正在编译的目标是否有可用...

这也不能让你一直到Cargo易用的东西。 Rust里面的东西实际上也不是Cargo-ified。你可以创建一个新的货物项目,并将这样的内容添加到Cargo.toml

[lib]
path = "/path/to/rust/src/libcollections/lib.rs"

这将允许您更多地依赖货物。

相关问题