Skip to content

Commit

Permalink
RISC-V GNU/Linux as host platform
Browse files Browse the repository at this point in the history
  • Loading branch information
msizanoen1 committed Jul 11, 2020
1 parent 0c03aee commit 933ba82
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
24 changes: 22 additions & 2 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ impl Step for Llvm {
/// 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) {
Expand Down Expand Up @@ -164,8 +173,8 @@ impl Step for Llvm {
.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");
Expand Down Expand Up @@ -212,6 +221,17 @@ impl Step for Llvm {
}
}

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");
Expand Down
1 change: 1 addition & 0 deletions src/ci/azure-pipelines/auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-musl: {}
Expand Down
31 changes: 31 additions & 0 deletions src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions src/ci/docker/host-x86_64/dist-various-1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 933ba82

Please sign in to comment.