Skip to content

Commit

Permalink
test the thumb targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Oct 17, 2016
1 parent ccfe4fc commit e4fa0f6
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.thumbv6m-none-eabi]
rustflags = ["-C", "link-arg=-nostartfiles"]

[target.thumbv7m-none-eabi]
rustflags = ["-C", "link-arg=-nostartfiles"]

[target.thumbv7em-none-eabi]
rustflags = ["-C", "link-arg=-nostartfiles"]

[target.thumbv7em-none-eabihf]
rustflags = ["-C", "link-arg=-nostartfiles"]
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ matrix:
- env: TARGET=powerpc64-unknown-linux-gnu
- env: TARGET=powerpc64le-unknown-linux-gnu
- env: TARGET=s390x-unknown-linux-gnu
- env: TARGET=thumbv6m-none-eabi
- env: TARGET=thumbv7em-none-eabi
- env: TARGET=thumbv7em-none-eabihf
- env: TARGET=thumbv7m-none-eabi
- env: TARGET=x86_64-unknown-linux-musl

# just to check these build jobs are skipped during deploys
Expand All @@ -54,8 +58,10 @@ install:
# curl: `std for cross-compilation
# docker: For transparent QEMU user emulation
- if [ -z $TRAVIS_TAG ] || [ $TRAVIS_RUST_VERSION = $DEPLOY_VERSION ]; then
curl https://static.rust-lang.org/rustup.sh |
sh -s -- --add-target=$TARGET --disable-sudo -y --prefix=`rustc --print sysroot`;
case $TARGET in thumbv*-none-eabi*) ;; *)
curl https://static.rust-lang.org/rustup.sh |
sh -s -- --add-target=$TARGET --disable-sudo -y --prefix=`rustc --print sysroot`;;
esac;

test $TRAVIS_OS_NAME = osx ||
docker run --privileged --rm -it ubuntu:16.04 sh -c
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
[build-dependencies]
gcc = { git = "https://github.com/alexcrichton/gcc-rs" }

[dependencies]
[target.'cfg(not(target_os = "none"))'.dependencies]
# Just to test 'cache: cargo'
clap = "2.13.0"

Expand Down
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ fn main() {
if env::var_os("CARGO_FEATURE_C").is_some() {
gcc::compile_library("libhello.a", &["hello.c"]);
}

let target = env::var("TARGET").unwrap();

if target.starts_with("thumb") {
println!("cargo:rustc-cfg=thumb");
}
}
11 changes: 11 additions & 0 deletions ci/docker/thumbv6m-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
gcc-arm-none-eabi \
libc6-dev \
libnewlib-dev
RUN curl -LSfs http://japaric.github.io/trust/install.sh | \
sh -s -- --git japaric/xargo --tag v0.2.0 --target x86_64-unknown-linux-gnu --to /usr/bin
11 changes: 11 additions & 0 deletions ci/docker/thumbv7em-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
gcc-arm-none-eabi \
libc6-dev \
libnewlib-dev
RUN curl -LSfs http://japaric.github.io/trust/install.sh | \
sh -s -- --git japaric/xargo --tag v0.2.0 --target x86_64-unknown-linux-gnu --to /usr/bin
11 changes: 11 additions & 0 deletions ci/docker/thumbv7em-none-eabihf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
gcc-arm-none-eabi \
libc6-dev \
libnewlib-dev
RUN curl -LSfs http://japaric.github.io/trust/install.sh | \
sh -s -- --git japaric/xargo --tag v0.2.0 --target x86_64-unknown-linux-gnu --to /usr/bin
11 changes: 11 additions & 0 deletions ci/docker/thumbv7m-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
gcc-arm-none-eabi \
libc6-dev \
libnewlib-dev
RUN curl -LSfs http://japaric.github.io/trust/install.sh | \
sh -s -- --git japaric/xargo --tag v0.2.0 --target x86_64-unknown-linux-gnu --to /usr/bin
22 changes: 19 additions & 3 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
set -ex

test_mode() {
cargo build $flags
cargo build $flags --release
case $TARGET in
thumbv*-none-eabi*)
xargo build $flags
xargo build $flags --release
;;
*)
cargo build $flags
cargo build $flags --release
;;
esac

case $TARGET in
thumbv*-none-eabi*)
;;
s390x-unknown-linux-gnu)
cargo test $flags --no-run
cargo test $flags --no-run --release
Expand All @@ -19,7 +29,13 @@ test_mode() {
}

deploy_mode() {
cargo rustc $flags --release --bin hello -- -C lto
case $TARGET in
thumbv*-none-eabi*)
;;
*)
cargo rustc $flags --release --bin hello -- -C lto
;;
esac
}

run() {
Expand Down
121 changes: 121 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/sh

set -e

say() {
echo "install.sh: $1"
}

say_err() {
say "$1" >&2
}

err() {
if [ ! -z $td ]; then
rm -rf $td
fi

say_err "ERROR $1"
exit 1
}

need() {
if ! command -v $1 > /dev/null 2>&1; then
err "need $1 (command not found)"
fi
}

need basename
need curl
need cut
need grep
need install
need mkdir
need mktemp
need rev
need rustc
need tar

force=false
while test $# -gt 1; do
case $1 in
--crate)
crate=$2
shift
;;
--git)
git=$2
shift
;;
--force)
force=true
;;
--tag)
tag=$2
shift
;;
--target)
target=$2
shift
;;
--to)
dest=$2
shift
;;
*)
;;
esac
shift
done

if [ -z $git ]; then
err 'must specify a git repository using `--git`. Example: `install.sh --git japaric/xargo`'
fi

url="https://github.com/$git"
say_err "Git repository: $url"

if [ -z $crate ]; then
crate=$(echo $git | cut -d'/' -f2)
fi

say_err "Crate: $crate"

url="$url/releases"

if [ -z $tag ]; then
tag=$(curl -s "$url/latest" | cut -d'"' -f2 | rev | cut -d'/' -f1 | rev)
say_err "Tag: latest ($tag)"
else
say_err "Tag: $tag"
fi

if [ -z $target ]; then
target=$(rustc -Vv | grep host | cut -d' ' -f2)
fi

say_err "Target: $target"

if [ -z $dest ]; then
dest="$HOME/.cargo/bin"
fi

say_err "Installing to: $dest"

url="$url/download/$tag/$crate-$tag-$target.tar.gz"

td=$(mktemp -d || mktemp -d -t tmp)
curl -sL $url | tar -C $td -xz

for f in $(find $td -type f -executable); do
fn=$(basename $f)

if [ -e "$dest/$fn" ] && [ $force = false ]; then
err "$fn already exists in $dest"
else
mkdir -p $dest
install -m 755 $f $dest
fi
done

rm -rf $td
19 changes: 19 additions & 0 deletions src/bin/hello.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#![cfg_attr(thumb, feature(lang_items))]
#![cfg_attr(thumb, no_main)]
#![cfg_attr(thumb, no_std)]

extern crate trust;

#[cfg(not(thumb))]
fn main() {
println!(concat!("target: ",
include_str!(concat!(env!("OUT_DIR"), "/target.txt"))));

trust::hello();
}

#[cfg(thumb)]
#[no_mangle]
pub fn _start() -> ! {
loop {}
}

#[cfg(thumb)]
#[no_mangle]
pub fn __aeabi_unwind_cpp_pr0() {}

#[cfg(thumb)]
#[lang = "panic_fmt"]
fn panic_fmt() {}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(thumb, no_std)]

#[cfg(feature = "c")]
pub fn hello() {
extern {
Expand Down

0 comments on commit e4fa0f6

Please sign in to comment.