japaric / steed

[INACTIVE] Rust's standard library, free of C dependencies, for Linux systems
518 stars 22 forks source link

How to test on real hardware? #77

Open RandomInsano opened 7 years ago

RandomInsano commented 7 years ago

I have PowerPC (IBM G3) and ARMv7 (Allwinner R18) with cross installed and steed's dependencies built. I removed the docker bits that I don't need and passed in the targets. On both, I received this:

edwinamsler@chip-01:~/Documents/Code/steed$ TARGET=armv7-unknown-linux-gnueabihf bash ci/script.sh 
+ main
+ examples=(_llseek create format format hello instant open preadwrite stderr system-time vec zero)
+ local examples
+ for example in '${examples[@]}'
+ cross run --target armv7-unknown-linux-gnueabihf --example _llseek
   Compiling unborrow v0.3.1
   Compiling sc v0.1.3 (https://github.com/japaric/syscall.rs#ee704d7f)
   Compiling sc v0.1.3
   Compiling ralloc_shim v0.1.1 (https://github.com/japaric/ralloc?branch=sc#837933b6)
   Compiling compiler_builtins v0.1.0 (https://github.com/rust-lang-nursery/compiler-builtins#764557f0)
   Compiling ralloc v1.0.0 (https://github.com/japaric/ralloc?branch=sc#837933b6)
   Compiling std v0.1.0 (file:///home/edwinamsler/Documents/Code/steed)
error: language item required, but not found: `eh_personality`

error: aborting due to previous error

error: Could not compile `std`.

As a Canadian, I can provide plenty of "Eh" personality, but I don't know how to hand it over to Steed :D

RandomInsano commented 7 years ago

After finding this and injecting the "create" example with a little Canadian personality function, it's now dying on multiple "start" functions, which is a bit silly... I'll let you guys direct me here.

#![feature(lang_items)]

use std::fs::File;
use std::io::Write;

#[lang = "eh_personality"]
#[no_mangle]
pub extern fn back_bacon() {
}

fn main() {
    let mut f = File::create("/target/hello").unwrap();
    f.write_all(b"Hello, world!\n").unwrap();
}

Also, the important infos:

edwinamsler@chip-01:~/Documents/Code/steed$ rustc --version
rustc 1.16.0-nightly (ff591b6dc 2017-01-15)
edwinamsler@chip-01:~/Documents/Code/steed$ cross --version
cross 0.1.8
cargo 0.17.0-nightly (6c79cf9 2017-01-13)
tbu- commented 7 years ago

Try it with the target armv7-unknown-linux-steed.

japaric commented 7 years ago

@RandomInsano

$ TARGET=armv7-unknown-linux-steedeabihf bash ci/script.sh 

Should do the trick for the ARM machine. Use powerpc-unknown-linux-steed for the PowerPC machine. In general, you have to use steed targets instead of the gnu ones. Just replace gnu by steed in the target triple.

RandomInsano commented 7 years ago

Updated to a new nightly, new problems:

edwinamsler@chip-01:~/Documents/Code/steed$ TARGET=armv7-unknown-linux-steedeabihf bash ci/script.sh --verbose
+ main
+ examples=(_llseek create format format hello instant open preadwrite stderr system-time vec zero)
+ local examples
+ for example in '${examples[@]}'
+ cross run --verbose --target armv7-unknown-linux-steedeabihf --example _llseek
+ "cargo" "run" "--verbose" "--target" "armv7-unknown-linux-steedeabihf" "--example" "_llseek"
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type rlib --target armv7-unknown-linux-steedeabihf` (exit code: 101)
--- stderr
error: Error loading target specification: Could not find specification for target "armv7-unknown-linux-steedeabihf"
  |
  = help: Use `--print target-list` for a list of built-in targets
RandomInsano commented 7 years ago

Also, just for a fun wrinkle, I tried running the whole thing with cross run --example create and got a multple _start definition error. I guess that makes sense as one is in rt.rs and the other is in Scrt1.o from gcc.

I also tried extracting the call straight from script.sh and got a whole other weird error:

edwinamsler@chip-01:~/Documents/Code/steed$ TARGET=armv7-unknown-linux-steed cross run --verbose --target $TARGET --example create  
+ "cargo" "run" "--verbose" "--target" "--example" "create"
error: a bin target must be available for `cargo run`
edwinamsler@chip-01:~/Documents/Code/steed$ TARGET=armv7-unknown-linux-steedeabihf cross run --verbose --target $TARGET --example create
+ "cargo" "run" "--verbose" "--target" "--example" "create"
error: a bin target must be available for `cargo run`
tbu- commented 7 years ago
"cargo" "run" "--verbose" "--target" "--example" "create"

The $TARGET variable didn't get substituted in.

RandomInsano commented 7 years ago

Ugh. Mildly discouraged. Here are the results from the recommendation of an out-of-the-box experience on an ARMv7 machine: (probably trying to run the wrong arch in the container)

edwinamsler@chip-01:~/Documents/Code/steed$ sudo TARGET=armv7-unknown-linux-steedeabihf bash ci/script.sh
+ main
+ sh build-docker-image.sh armv7-unknown-linux-steedeabihf
+ '[' -z armv7-unknown-linux-steedeabihf ']'
+ run armv7-unknown-linux-steedeabihf
+ docker build -t japaric/armv7-unknown-linux-steedeabihf:v0.1.8 -f docker/armv7-unknown-linux-steedeabihf/Dockerfile docker
Sending build context to Docker daemon 34.82 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:16.04
 ---> 6aa0b6d7eb90
Step 1 : RUN apt-get update &&     apt-get install -y --no-install-recommends     ca-certificates     gcc     libc6-dev &&     mkdir /json
 ---> Running in 83c65ecba6a3
exec format error
INFO[0004] [8] System error: exec format error          

Just an aside, but how do you teach rustc new tricks for rustc --print target-list? There's no steedliness in there anywheres.

japaric commented 7 years ago

@RandomInsano Sorry for the wrong instructions in my previous comment. You actually have to run these commands (assuming an ARM host)

# in the root of the Cargo project
$ cp docker/armv7-unknown-linux-steedeabihf.json .

# if you don't have Xargo around
$ cargo install xargo

# you have to run each example individually
$ xargo run --target armv7-unknown-linux-steedeabihf --example hello

# sanity check that the executable is statically linked
$ file target/armv7-unknown-linux-steedeabihf/debug/example/hello
... statically linked ...

The script.sh won't work for you because it uses cross and that only work on x86_64 hosts.


Just an aside, but how do you teach rustc new tricks for rustc --print target-list?

The targets in that list are "built in" targets. For the steed targets to be there, this repo would have to be merged with rust-lang/rust beacuse the targets would have to be added to the compiler.

RandomInsano commented 7 years ago

Ah well, ya live, ya learn.

Xargo's a bit of a problem because it assumes .rustup for the Rust installation which I don't really have. I can run through some hoops and grab it, but I think I'm done on this for the next few days. I'll circle back when I'm ready to double down on this Xargo thing.

Also good news, I should have some SPARC hardware soon enough, so I'll have quite a few bases covered.

edwinamsler@chip-01:~/Documents/Code/steed$ xargo run --target armv7-unknown-linux-steedeabihf --example hello
error: couldn't walk the sysroot
caused by: IO error for operation on /home/edwinamsler/.rustup/toolchains/nightly-armv7-unknown-linux-gnueabihf/lib/rustlib/src: No such file or directory (os error 2)
caused by: No such file or directory (os error 2)
note: run with `RUST_BACKTRACE=1` for a backtrace
aleksander commented 7 years ago

This did not work for me:

$ cp docker/armv7-unknown-linux-steedeabihf.json .
$ cargo install xargo
$ xargo run --target armv7-unknown-linux-steedeabihf --example hello

besause one of the dependencies does not build.

This is working without coping json from docker dir:

RUST_TARGET_PATH=$HOME/src/steed/docker` xargo run --target `uname -m`-unknown-linux-steed --example hello --verbose