Rollup merge of #72973 - msizanoen1:riscv-host, r=pietroalbini

RISC-V GNU/Linux as host platform

This PR add a new builder named `dist-riscv64-linux` that builds the compiler toolchain for RISC-V 64-bit GNU/Linux.

r? @alexcrichton
This commit is contained in:
Manish Goregaokar 2020-07-15 11:01:02 -07:00 committed by GitHub
commit af3d4cb936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 25 deletions

View File

@ -297,6 +297,9 @@ jobs:
- name: dist-powerpc64le-linux
os: ubuntu-latest-xl
env: {}
- name: dist-riscv64-linux
os: ubuntu-latest-xl
env: {}
- name: dist-s390x-linux
os: ubuntu-latest-xl
env: {}

View File

@ -112,6 +112,15 @@ fn make_run(run: RunConfig<'_>) {
/// Compile LLVM for `target`.
fn run(self, builder: &Builder<'_>) -> PathBuf {
let target = self.target;
let target_native = if self.target.starts_with("riscv") {
// RISC-V target triples in Rust is not named the same as C compiler target triples.
// This converts Rust RISC-V target triples to C compiler triples.
let idx = target.find('-').unwrap();
format!("riscv{}{}", &target[5..7], &target[idx..])
} else {
target.to_string()
};
let Meta { stamp, build_llvm_config, out_dir, root } =
match prebuilt_llvm_config(builder, target) {
@ -165,8 +174,8 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
.define("LLVM_ENABLE_BINDINGS", "OFF")
.define("LLVM_ENABLE_Z3_SOLVER", "OFF")
.define("LLVM_PARALLEL_COMPILE_JOBS", builder.jobs().to_string())
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
.define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
.define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);
if !target.contains("netbsd") {
cfg.define("LLVM_ENABLE_ZLIB", "ON");
@ -213,6 +222,17 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
}
}
if target.starts_with("riscv") {
// In RISC-V, using C++ atomics require linking to `libatomic` but the LLVM build
// system check cannot detect this. Therefore it is set manually here.
if !builder.config.llvm_tools_enabled {
cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic");
} else {
cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic -static-libstdc++");
}
cfg.define("CMAKE_SHARED_LINKER_FLAGS", "-latomic");
}
if target.contains("msvc") {
cfg.define("LLVM_USE_CRT_DEBUG", "MT");
cfg.define("LLVM_USE_CRT_RELEASE", "MT");

View File

@ -53,6 +53,7 @@ jobs:
dist-powerpc-linux: {}
dist-powerpc64-linux: {}
dist-powerpc64le-linux: {}
dist-riscv64-linux: {}
dist-s390x-linux: {}
dist-x86_64-freebsd: {}
dist-x86_64-illumos: {}

View File

@ -0,0 +1,31 @@
FROM ubuntu:18.04
COPY scripts/cross-apt-packages.sh /scripts/
RUN sh /scripts/cross-apt-packages.sh
COPY host-x86_64/dist-riscv64-linux/crosstool-ng.sh /scripts/
RUN sh /scripts/crosstool-ng.sh
COPY scripts/rustbuild-setup.sh /scripts/
RUN sh /scripts/rustbuild-setup.sh
USER rustbuild
WORKDIR /tmp
COPY host-x86_64/dist-riscv64-linux/build-toolchains.sh host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.config /tmp/
RUN ./build-toolchains.sh
USER root
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
ENV PATH=$PATH:/x-tools/riscv64-unknown-linux-gnu/bin
ENV CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++
ENV HOSTS=riscv64gc-unknown-linux-gnu
ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
ENV SCRIPT python3 ../x.py dist --target $HOSTS --host $HOSTS

View File

@ -19,9 +19,9 @@ exit 1
set -x
}
mkdir -p /tmp/build-riscv
cp riscv64-unknown-linux-gnu.config /tmp/build-riscv/.config
cd /tmp/build-riscv
mkdir build
cd build
cp ../riscv64-unknown-linux-gnu.config .config
hide_output ct-ng build
cd ..
rm -rf build-riscv
rm -rf build

View File

@ -1,4 +1,3 @@
#!/bin/bash
set -ex
# Mirrored from https://github.com/crosstool-ng/crosstool-ng/archive/crosstool-ng-1.24.0.tar.gz

View File

@ -17,8 +17,6 @@ CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
CT_CONFIGURE_has_python_3_4_or_newer=y
CT_CONFIGURE_has_bison_2_7_or_newer=y
CT_CONFIGURE_has_python=y
CT_CONFIGURE_has_dtc=y
CT_CONFIGURE_has_svn=y
CT_CONFIGURE_has_git=y
CT_CONFIGURE_has_md5sum=y
CT_CONFIGURE_has_sha1sum=y

View File

@ -47,18 +47,6 @@ RUN add-apt-repository ppa:team-gcc-arm-embedded/ppa && \
apt-get update && \
apt-get install -y --no-install-recommends gcc-arm-embedded
COPY scripts/rustbuild-setup.sh host-x86_64/dist-various-1/build-riscv-toolchain.sh host-x86_64/dist-various-1/riscv64-unknown-linux-gnu.config host-x86_64/dist-various-1/crosstool-ng.sh /build/
RUN ./crosstool-ng.sh
# Crosstool-ng will refuse to build as root
RUN sh ./rustbuild-setup.sh
USER rustbuild
RUN ./build-riscv-toolchain.sh
USER root
ENV PATH=/x-tools/riscv64-unknown-linux-gnu/bin:$PATH
COPY host-x86_64/dist-various-1/build-rumprun.sh /build
RUN ./build-rumprun.sh
@ -158,7 +146,6 @@ ENV TARGETS=$TARGETS,riscv32imc-unknown-none-elf
ENV TARGETS=$TARGETS,riscv32imac-unknown-none-elf
ENV TARGETS=$TARGETS,riscv64imac-unknown-none-elf
ENV TARGETS=$TARGETS,riscv64gc-unknown-none-elf
ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-gnu
ENV TARGETS=$TARGETS,armebv7r-none-eabi
ENV TARGETS=$TARGETS,armebv7r-none-eabihf
ENV TARGETS=$TARGETS,armv7r-none-eabi
@ -186,9 +173,6 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
CFLAGS_aarch64_unknown_none_softfloat=-mstrict-align -march=armv8-a+nofp+nosimd \
CC_aarch64_unknown_none=aarch64-none-elf-gcc \
CFLAGS_aarch64_unknown_none=-mstrict-align -march=armv8-a+fp+simd \
CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++ \
CC_riscv32i_unknown_none_elf=false \
CC_riscv32imc_unknown_none_elf=false \
CC_riscv32imac_unknown_none_elf=false \

View File

@ -341,6 +341,9 @@ jobs:
- name: dist-powerpc64le-linux
<<: *job-linux-xl
- name: dist-riscv64-linux
<<: *job-linux-xl
- name: dist-s390x-linux
<<: *job-linux-xl

View File

@ -275,6 +275,11 @@ fn main() {
"stdc++"
};
// RISC-V requires libatomic for sub-word atomic operations
if target.starts_with("riscv") {
println!("cargo:rustc-link-lib=atomic");
}
// C++ runtime library
if !target.contains("msvc") {
if let Some(s) = llvm_static_stdcpp {