mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 08:37:14 +00:00
RISC-V GNU/Linux as host platform
This commit is contained in:
parent
0c03aee8b8
commit
933ba82266
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -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: {}
|
||||
|
|
|
@ -111,6 +111,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) {
|
||||
|
@ -164,8 +173,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");
|
||||
|
@ -212,6 +221,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");
|
||||
|
|
|
@ -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: {}
|
||||
|
|
31
src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile
Normal file
31
src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile
Normal 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
|
|
@ -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
|
1
src/ci/docker/host-x86_64/dist-various-1/crosstool-ng.sh → src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh
Executable file → Normal file
1
src/ci/docker/host-x86_64/dist-various-1/crosstool-ng.sh → src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh
Executable file → Normal 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
|
|
@ -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
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue