Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
default to lld as the linker, update the README
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Apr 11, 2017
1 parent 306a4a8 commit 1d6fa97
Show file tree
Hide file tree
Showing 32 changed files with 323 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -41,7 +41,7 @@ after_success:
after_script: set +e

before_cache:
- docker history -q japaric/$TARGET:v0.1.8 |
- docker history -q japaric/$TARGET:v0.1.10 |
grep -v \<missing\> |
xargs docker save |
gzip > $HOME/docker/$TARGET.tar.gz
Expand Down
8 changes: 1 addition & 7 deletions Cargo.toml
Expand Up @@ -18,14 +18,8 @@ optional = true
optional = true
path = "naive_ralloc"

[dependencies.compiler_builtins]
default-features = false
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"

[features]
default = ["compiler-builtins", "ralloc"]
compiler-builtins = ["compiler_builtins/compiler-builtins"]
default = ["ralloc"]

[profile.release]
lto = true
124 changes: 54 additions & 70 deletions README.md
Expand Up @@ -9,8 +9,9 @@
- [Features](#features)
- [Supported architectures](#supported-architectures)
- [Usage](#usage)
- [On x86_64 Linux](#on-x86_64-linux)
- [On other systems](#on-other-systems)
- [Using `cross`](#using-cross)
- [Using `lld`](#using-lld)
- [Using `gcc`](#using-gcc)
- [Current functionality](#current-functionality)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -76,21 +77,21 @@ fn main() {
```

```
# xargo build --target x86_64-unknown-linux-steed --release --example hello
# xargo rustc --target x86_64-unknown-linux-steed --release --example hello -- -C lto
$ ./hello
Hello, world!
$ strip -s hello
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped, with debug_info
$ size hello
text data bss dec hex filename
173 0 0 173 bd hello
173 0 0 173 ad hello
$ ls -l hello
-rwxr-xr-x 1 japaric japaric 632 Feb 1 00:00 hello
-rwxr-xr-x 2 japaric japaric 4712 Apr 11 00:00 hello
```

**Disclaimer** The binary size will inevitably go up after we add missing
Expand Down Expand Up @@ -141,31 +142,24 @@ To compile your library / application against `steed`, follow these steps:
[issues]: https://github.com/japaric/steed/issues

### On x86_64 Linux
### Using `cross`

To easiest way to use `steed` is to use the `cross` tool:
To easiest way to use `steed` is to use the [`cross`] tool:

[`cross`]: https://github.com/japaric/cross#cross

> **NOTE** `cross` depends on Docker and only works on x86_64 Linux
```
# if you don't have cross installed
# (Cross v0.1.8 or newer is required)
# Always use the latest version
$ cargo install cross
# instead of this step, just go to the crate you want to build
$ cargo new --bin hello && cd $_
# this is the part that replaces `std` with `steed`
$ edit Xargo.toml && cat $_
```

``` toml
[dependencies.collections] # `steed` depends on collections
[dependencies.rand] # and rand

[dependencies.std]
git = "https://github.com/japaric/steed" # `path` works too
stage = 1
# Xargo magic to replace `std` with `steed`
# (if you want to run tests, fetch `Xargo.test.toml` instead of `Xargo.std.toml`)
$ curl -L https://raw.githubusercontent.com/japaric/steed/master/Xargo.std.toml > Xargo.toml
```

```
Expand All @@ -175,20 +169,21 @@ $ cross run --target x86_64-unknown-linux-steed
Hello, world!
$ file target/x86_64-unknown-linux-steed/debug/hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),statically linked, not stripped, with debug_info
```

You can use `cross` to cross compile your crate to other architectures as well.

```
# (continuation from the previous example)
# continuation from the previous example
$ cross build --target aarch64-unknown-linux-steed
$ file target/aarch64-unknown-linux-steed/debug/hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV),statically linked, not stripped
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped, with debug_info
```

`cross` can even transparently execute those cross compiled binaries using QEMU.
QEMU doesn't need to be installed on the host system.

```
$ cross run --target aarch64-unknown-linux-steed -v
Expand All @@ -198,78 +193,67 @@ $ cross run --target aarch64-unknown-linux-steed -v
Hello, world!
```

### On other systems

If you are not using a x86_64 Linux system or don't want to use/install Docker,
then you can use Xargo to compile your program against `steed`.
> **NOTE** `cross test` works as well but you have to use the other Xargo.toml
```
# if you don't have Xargo installed
# (Xargo v0.3.4 or newer is required)
$ cargo install xargo
### Using `lld`

# grab the target specification file for the `steed` target
$ curl -OL https://github.com/japaric/steed/raw/master/docker/x86_64-unknown-linux-steed.json
If you are not running x86_64 Linux or don't want to install / use Docker. You
can compile `steed` programs using [`xargo`] and [`lld`].

# required to compile some of `steed` dependencies
$ export RUST_TARGET_PATH=$(pwd)
[`xargo`]: https://github.com/japaric/xargo#xargo
[`lld`]: https://lld.llvm.org/

# this is the part that replaces `std` with `steed`
$ edit Xargo.toml && cat $_
```
# This is for Ubuntu, adjust as necessary
$ sudo apt-get install lld-4.0
``` toml
[dependencies.collections] # `steed` depends on collections
[dependencies.rand] # and rand
# Xargo v0.3.4 or newer is required
$ cargo install xargo
[dependencies.std]
git = "https://github.com/japaric/steed" # `path` works too
stage = 1
```
# OMITTED: fetching Xargo.toml
# Fetch the target definition
$ curl -LO https://raw.githubusercontent.com/japaric/steed/master/docker/x86_64-unknown-linux-steed.json
```
$ xargo run --target x86_64-unknown-linux-steed
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/x86_64-unknown-linux-steed/debug/hello`
Hello, world!
$ file target/x86_64-unknown-linux-steed/debug/hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
```

You can cross compile as well but you'll have to install a cross linker on your
host system:
Cross compilation works out of the box; there's no need to install a cross C
toolchain:

```
# assuming Ubuntu
$ sudo apt-get install gcc-aarch64-linux-gnu
# point Cargo to the right linker
$ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_STEED_LINKER=aarch64-linux-gnu-gcc
# grab the target specification file for the `steed` target
$ curl -OL https://github.com/japaric/steed/raw/master/docker/aarch64-unknown-linux-steed.json
# required to compile some of `steed` dependencies
$ export RUST_TARGET_PATH=$(pwd)
# fetch another target definition
$ curl -LO https://raw.githubusercontent.com/japaric/steed/master/docker/aarch64-unknown-linux-steed.json
$ xargo build --target aarch64-unknown-linux-steed
$ file target/aarch64-unknown-linux-steed/debug/hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV),statically linked, not stripped
$ file target/aarch64-unknown-linux-steed/debug/examples/hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped, with debug_info
```

You can execute the cross compiled binaries too but you'll have to install and
explicitly call QEMU:
To execute foreign binaries you can use QEMU:

```
# assuming Ubuntu
# This is for Ubuntu, adjust as necessary
$ sudo apt-get install qemu-user
$ qemu-aarch64 target/aarch64-unknown-linux-steed/debug/hello
$ qemu-aarch64 target/aarch64-unknown-linux-steed/debug/examples/hello
Hello, world!
```

### Using `gcc`

If you don't want to install `lld`, you can link `steed` programs using `gcc`,
which you probably already have installed.

```
$ xargo rustc --target x86_64-unknown-linux-gnu -- -C linker=gcc -Z linker-flavor=gcc
$ file target/x86_64-unknown-linux-steed/debug/hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=ac4fce139edd9741b818cd73123be6c934718f78, not stripped, with debug_info
```

## Current functionality

Check the [API docs](https://japaric.github.io/steed/steed/index.html), but to
Expand Down
12 changes: 12 additions & 0 deletions Xargo.std.toml
@@ -0,0 +1,12 @@
[dependencies]
collections = {}
rand = {}

[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

[dependencies.std]
git = "https://github.com/japaric/steed"
stage = 2
16 changes: 16 additions & 0 deletions Xargo.test.toml
@@ -0,0 +1,16 @@
[dependencies]
collections = {}
rand = {}

[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

[dependencies.std]
git = "https://github.com/japaric/steed"
stage = 2

[dependencies.test]
git = "https://github.com/japaric/steed"
stage = 3
5 changes: 5 additions & 0 deletions Xargo.toml
@@ -1,3 +1,8 @@
[dependencies]
collections = {}
rand = {}

[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1
2 changes: 1 addition & 1 deletion build-docker-image.sh
Expand Up @@ -2,7 +2,7 @@ set -ex

run() {
docker build \
-t japaric/${1}:v0.1.9 \
-t japaric/${1}:v0.1.10 \
-f docker/${1}/Dockerfile \
docker
}
Expand Down
2 changes: 1 addition & 1 deletion ci/install.sh
Expand Up @@ -8,7 +8,7 @@ main() {
sh -s -- \
--force \
--git japaric/cross \
--tag v0.1.9 \
--tag v0.1.10 \
--target x86_64-unknown-linux-musl
}

Expand Down
17 changes: 9 additions & 8 deletions docker/aarch64-unknown-linux-steed.json
Expand Up @@ -11,18 +11,19 @@
"env": "steed",
"executables": true,
"has-elf-tls": true,
"linker-is-gnu": true,
"linker": "ld.lld",
"linker-flavor": "ld",
"llvm-target": "aarch64-unknown-linux",
"max-atomic-width": 128,
"os": "linux",
"panic-strategy": "abort",
"pre-link-args": [
"-Wl,--as-needed",
"-Wl,--build-id=none",
"-Wl,-z,noexecstack",
"-nostartfiles",
"-static"
],
"pre-link-args": {
"gcc": [
"-Wl,--as-needed",
"-Wl,-z,noexecstack",
"-nostartfiles"
]
},
"target-endian": "little",
"target-family": "unix",
"target-pointer-width": "64",
Expand Down
19 changes: 8 additions & 11 deletions docker/aarch64-unknown-linux-steed/Dockerfile
Expand Up @@ -7,19 +7,16 @@ RUN apt-get update && \
libc6-dev && \
mkdir /json

COPY xargo.sh /
RUN bash /xargo.sh

COPY lld.sh /
RUN bash /lld.sh

COPY qemu.sh /
RUN apt-get install -y --no-install-recommends \
gcc-aarch64-linux-gnu && \
bash /qemu.sh 2.8.0 aarch64
RUN bash /qemu.sh 2.8.0 aarch64

COPY aarch64-unknown-linux-steed.json /json

RUN apt-get install -y --no-install-recommends \
curl && \
curl -LSfs http://japaric.github.io/trust/install.sh | \
sh -s -- --git japaric/xargo --tag v0.3.5 --target x86_64-unknown-linux-gnu --to /usr/bin && \
apt-get purge --auto-remove -y curl

ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_STEED_LINKER=aarch64-linux-gnu-gcc \
RUST_TARGET_PATH=/json \
ENV RUST_TARGET_PATH=/json \
RUST_TEST_THREADS=1
17 changes: 9 additions & 8 deletions docker/arm-unknown-linux-steedeabi.json
Expand Up @@ -12,18 +12,19 @@
"executables": true,
"features": "+v6",
"has-elf-tls": true,
"linker-is-gnu": true,
"linker": "ld.lld",
"linker-flavor": "ld",
"llvm-target": "arm-unknown-linux-eabi",
"max-atomic-width": 64,
"os": "linux",
"panic-strategy": "abort",
"pre-link-args": [
"-Wl,--as-needed",
"-Wl,--build-id=none",
"-Wl,-z,noexecstack",
"-nostartfiles",
"-static"
],
"pre-link-args": {
"gcc": [
"-Wl,--as-needed",
"-Wl,-z,noexecstack",
"-nostartfiles"
]
},
"target-endian": "little",
"target-family": "unix",
"target-pointer-width": "32",
Expand Down

0 comments on commit 1d6fa97

Please sign in to comment.