2016-01-21 25 views
1

我目前正在嘗試安裝一個嵌入式Rust項目。爲此,如果我可以使用collections板條箱(以及由collections所要求的擴展板,alloc板條箱)將會很好。有沒有簡單的方法來實現這一目標?我目前在Cargo.toml使用收藏與貨物沒有stdlib

[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箱子?

+0

您是否有一些底層分配器可用於嵌入式設備?我不知道jemalloc是否支持ARM,如果不支持,則必須有一些分配器可用。 – Shepmaster

回答

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或系統分配器。我不知道是否有任何可用的目標,你正在編譯...

這並不完全讓你一路易於使用貨物的東西,無論是。 Rust裏面的東西實際上並不是貨物,也不是。您可以創建新貨的項目,並添加像這樣的Cargo.toml

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

那麼這將讓你依靠的貨物更多。