|
| 1 | +# `s390x-unknown-linux-gnu` |
| 2 | + |
| 3 | +**Tier: 2 (with Host Tools)** |
| 4 | + |
| 5 | +IBM z/Architecture (s390x) targets (including IBM Z and LinuxONE) running Linux. |
| 6 | + |
| 7 | +## Target maintainers |
| 8 | + |
| 9 | +- Ulrich Weigand, < [email protected]>, [@uweigand](https://github.com/uweigand) |
| 10 | +- Josh Stone, <[email protected]>, [@cuviper](https://github.com/cuviper) |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +This target requires: |
| 15 | + |
| 16 | +* Linux Kernel version 3.2 or later |
| 17 | +* glibc 2.17 or later |
| 18 | + |
| 19 | +Code generated by the target uses the z/Architecture ISA assuming a minimum |
| 20 | +architecture level of z10 (Eighth Edition of the z/Architecture Principles |
| 21 | +of Operation), and is compliant with the s390x ELF ABI. |
| 22 | + |
| 23 | +Reference material: |
| 24 | + |
| 25 | +* [z/Architecture Principles of Operation][s390x-isa] |
| 26 | +* [z/Architecture ELF Application Binary Interface][s390x-abi] |
| 27 | + |
| 28 | +[s390x-isa]: https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf |
| 29 | +[s390x-abi]: https://github.com/IBM/s390x-abi |
| 30 | + |
| 31 | +## Building the target |
| 32 | + |
| 33 | +This target is distributed through `rustup`, and otherwise requires no |
| 34 | +special configuration. |
| 35 | + |
| 36 | +If you need to build your own Rust for some reason though, the target can be |
| 37 | +enabled in `config.toml`. For example: |
| 38 | + |
| 39 | +```toml |
| 40 | +[build] |
| 41 | +target = ["s390x-unknown-linux-gnu"] |
| 42 | +``` |
| 43 | + |
| 44 | +## Building Rust programs |
| 45 | + |
| 46 | +On a s390x Linux host, the `s390x-unknown-linux-gnu` target should be |
| 47 | +automatically installed and used by default. |
| 48 | + |
| 49 | +On a non-s390x host, add the target: |
| 50 | + |
| 51 | +```bash |
| 52 | +rustup target add s390x-unknown-linux-gnu |
| 53 | +``` |
| 54 | + |
| 55 | +Then cross compile crates with: |
| 56 | + |
| 57 | +```bash |
| 58 | +cargo build --target s390x-unknown-linux-gnu |
| 59 | +``` |
| 60 | + |
| 61 | +## Testing |
| 62 | + |
| 63 | +There are no special requirements for testing and running the target. |
| 64 | +For testing cross builds on the host, please refer to the "Cross-compilation |
| 65 | +toolchains and C code" section below. |
| 66 | + |
| 67 | +## Cross-compilation toolchains and C code |
| 68 | + |
| 69 | +Rust code built using the target is compatible with C code compiled with |
| 70 | +GCC or Clang using the `s390x-unknown-linux-gnu` target triple (via either |
| 71 | +native or cross-compilation). |
| 72 | + |
| 73 | +On Ubuntu, a s390x cross-toolchain can be installed with: |
| 74 | + |
| 75 | +```bash |
| 76 | +apt install gcc-s390x-linux-gnu g++-s390x-linux-gnu libc6-dev-s390x-cross |
| 77 | +``` |
| 78 | + |
| 79 | +Depending on your system, you may need to configure the target to use the GNU |
| 80 | +GCC linker. To use it, add the following to your `.cargo/config.toml`: |
| 81 | + |
| 82 | +```toml |
| 83 | +[target.s390x-unknown-linux-gnu] |
| 84 | +linker = "s390x-linux-gnu-gcc" |
| 85 | +``` |
| 86 | + |
| 87 | +If your `s390x-linux-gnu-*` toolchain is not in your `PATH` you may need to |
| 88 | +configure additional settings: |
| 89 | + |
| 90 | +```toml |
| 91 | +[target.s390x-unknown-linux-gnu] |
| 92 | +# Adjust the paths to point at your toolchain |
| 93 | +cc = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-gcc" |
| 94 | +cxx = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-g++" |
| 95 | +ar = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-ar" |
| 96 | +ranlib = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-ranlib" |
| 97 | +linker = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-gcc" |
| 98 | +``` |
| 99 | + |
| 100 | +To test cross compiled binaries on a non-s390x host, you can use |
| 101 | +[`qemu`](https://www.qemu.org/docs/master/system/target-s390x.html). |
| 102 | +On Ubuntu, a s390x emulator can be obtained with: |
| 103 | + |
| 104 | +```bash |
| 105 | +apt install qemu-system-s390x |
| 106 | +``` |
| 107 | + |
| 108 | +Then, in `.cargo/config.toml` set the `runner`: |
| 109 | + |
| 110 | +```toml |
| 111 | +[target.s390x-unknown-linux-gnu] |
| 112 | +runner = "qemu-s390x-static -L /usr/s390x-linux-gnu" |
| 113 | +``` |
0 commit comments