japaric/steed

Xargo integration

Closed this issue · 2 comments

We want to be able to build std programs against steed.

Xargo already supports building a custom std source (cf. XARGO_RUST_SRC) but it expects a very specific directory layout.

We may have to hack Xargo to achieve this.

Once japaric/xargo#117 and #41 land, you'll be able to use Xargo to compile your program against steed as if it were std.

Here's an example:

$ cargo new --bin hello && cd $_

$ edit Xargo.toml && cat $_
[dependencies.collections]  # `steed` depends on collections
# stage = 0  # implicit

[dependencies.std]  # use `steed` as the `std` crate
path = "/home/japaric/rust/steed"
stage = 1
$ edit Cargo.toml && tail -n6 $_
[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
lto = true
$ edit .cargo/config && cat $_
[build]
rustflags = [
    "-C", "link-arg=-Wl,--build-id=none",
    "-C", "link-arg=-nostartfiles",
    "-C", "link-arg=-static",
]
$ edit src/main.rs && cat $_
#![no_main]

#[no_mangle]
pub fn main() -> i32 {
    println!("Hello, world!");
    0
}

Note that there's no need to use extern crate steed and that the prelude also works. Until #14 is implemented you'll have to use #![no_main] and the non standard main signature though.

$ xargo run --release --target x86_64-unknown-linux-gnu
    Finished release [optimized] target(s) in 0.0 secs
     Running `target/x86_64-unknown-linux-gnu/release/hello`
Hello, world!

cc @cmr This is may interest you ^. Xargo can now replace std with a custom (re)implementation and that replacement can depend on crates from crates.io or from git repos. The Xargo sysroot will contain all those dependencies.

Once japaric/xargo#117 and #41 land

Those two landed so this is basically done. Yay!