|
| 1 | +# `linux-cross` |
| 2 | + |
| 3 | +This image is used to cross compile libstd/rustc to targets that run linux but are not the |
| 4 | +`x86_64-unknown-linux-gnu` triple which is the "host" triple. |
| 5 | + |
| 6 | +To cross compile libstd/rustc we need a C cross toolchain: a cross gcc and a cross compiled libc. |
| 7 | +For some targets, we use crosstool-ng to build these toolchains ourselves instead of using the ones |
| 8 | +packaged for Ubuntu because: |
| 9 | + |
| 10 | +- We can control the glibc version of the toolchain. In particular, we can lower its version as much |
| 11 | + as possible, this lets us generate libstd/rustc binaries that run in systems with old glibcs. |
| 12 | +- We can create toolchains for targets that don't have an equivalent package available in Ubuntu. |
| 13 | + |
| 14 | +crosstool-ng uses a `.config` file, generated via a menuconfig interface, to specify the target, |
| 15 | +glibc version, etc. of the toolchain to build. Because this menuconfig interface requires user |
| 16 | +intervention we store pre-generated `.config` files in this repository to keep the `docker build` |
| 17 | +command free of user intervention. |
| 18 | + |
| 19 | +The next section explains how to generate a `.config` file for a new target, and the one after that |
| 20 | +contains the changes, on top of the default toolchain configuration, used to generate the `.config` |
| 21 | +files stored in this repository. |
| 22 | + |
| 23 | +## Generating a `.config` file |
| 24 | + |
| 25 | +If you have a `linux-cross` image lying around you can use that and skip the next two steps. |
| 26 | + |
| 27 | +- First we spin up a container and copy `build_toolchain_root.sh` into it. All these steps are |
| 28 | + outside the container: |
| 29 | + |
| 30 | +``` |
| 31 | +# Note: We use ubuntu:15.10 because that's the "base" of linux-cross Docker image |
| 32 | +$ docker run -it ubuntu:15.10 bash |
| 33 | +$ docker ps |
| 34 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 35 | +cfbec05ed730 ubuntu:15.10 "bash" 16 seconds ago Up 15 seconds drunk_murdock |
| 36 | +$ docker cp build_toolchain_root.sh drunk_murdock:/ |
| 37 | +``` |
| 38 | + |
| 39 | +- Then inside the container we build crosstool-ng by simply calling the bash script we copied in the |
| 40 | + previous step: |
| 41 | + |
| 42 | +``` |
| 43 | +$ bash build_toolchain_root.sh |
| 44 | +``` |
| 45 | + |
| 46 | +- Now, inside the container run the following command to configure the toolchain. To get a clue of |
| 47 | + which options need to be changed check the next section and come back. |
| 48 | + |
| 49 | +``` |
| 50 | +$ ct-ng menuconfig |
| 51 | +``` |
| 52 | + |
| 53 | +- Finally, we retrieve the `.config` file from the container and give it a meaningful name. This is |
| 54 | + done outside the container. |
| 55 | + |
| 56 | +``` |
| 57 | +$ docker drunk_murdock:/.config arm-linux-gnueabi.config |
| 58 | +``` |
| 59 | + |
| 60 | +- Now you can shutdown the container or repeat the two last steps to generate a new `.config` file. |
| 61 | + |
| 62 | +## Toolchain configuration |
| 63 | + |
| 64 | +Changes on top of the default toolchain configuration used to generate the `.config` files in this |
| 65 | +directory. The changes are formatted as follows: |
| 66 | + |
| 67 | +``` |
| 68 | +$category > $option = $value -- $comment |
| 69 | +``` |
| 70 | + |
| 71 | +## `arm-linux-gnueabi.config` |
| 72 | + |
| 73 | +For targets: `arm-unknown-linux-gnueabi` |
| 74 | + |
| 75 | +- Path and misc options > Prefix directory = /x-tools/${CT_TARGET} |
| 76 | +- Target options > Target Architecture = arm |
| 77 | +- Target options > Architecture level = armv6 -- (+) |
| 78 | +- Target options > Floating point = software (no FPU) -- (*) |
| 79 | +- Operating System > Target OS = linux |
| 80 | +- Operating System > Linux kernel version = 3.2.72 -- Precise kernel |
| 81 | +- C-library > glibc version = 2.14.1 |
| 82 | +- C compiler > gcc version = 4.9.3 |
| 83 | +- C compiler > C++ = ENABLE -- to cross compile LLVM |
| 84 | + |
| 85 | +## `arm-linux-gnueabihf.config` |
| 86 | + |
| 87 | +For targets: `arm-unknown-linux-gnueabihf`, `armv7-unknown-linux-gnueabihf` |
| 88 | + |
| 89 | +- Path and misc options > Prefix directory = /x-tools/${CT_TARGET} |
| 90 | +- Target options > Target Architecture = arm |
| 91 | +- Target options > Architecture level = armv6 -- (+) |
| 92 | +- Target options > Use specific FPU = vfpv3-d16 -- (*) |
| 93 | +- Target options > Floating point = hardware (FPU) -- (*) |
| 94 | +- Target options > Default instruction set mode (thumb) -- (*) |
| 95 | +- Operating System > Target OS = linux |
| 96 | +- Operating System > Linux kernel version = 3.2.72 -- Precise kernel |
| 97 | +- C-library > glibc version = 2.14.1 |
| 98 | +- C compiler > gcc version = 4.9.3 |
| 99 | +- C compiler > C++ = ENABLE -- to cross compile LLVM |
| 100 | + |
| 101 | +(*) These options have been selected to match the configuration of the arm toolchains shipped with |
| 102 | +Ubuntu 15.10 |
| 103 | +(+) These options have been selected to match the gcc flags we use to compile C libraries like |
| 104 | +jemalloc. See the mk/cfg/arm-uknown-linux-gnueabi{,hf}.mk file in Rust's source code. |
0 commit comments