|
| 1 | +# riscv64 build container for android-cuttlefish. |
| 2 | +# |
| 3 | +# debian:trixie is used because debian:bookworm does not support riscv64. |
| 4 | +# Trixie (Debian 13) is the first Debian release with official riscv64. |
| 5 | +# clang-19 (19.1.7) in trixie matches the hermetic LLVM 19.1.7 used by |
| 6 | +# amd64/arm64 via toolchains_llvm. |
| 7 | +# |
| 8 | +# Host requirement: Docker's default seccomp profile blocks the |
| 9 | +# RISCV_FLUSH_ICACHE syscall needed by the JVM on riscv64. Configure: |
| 10 | +# echo '{"seccomp-profile": "unconfined"}' | sudo tee /etc/docker/daemon.json |
| 11 | +# sudo systemctl restart docker |
| 12 | + |
| 13 | +FROM debian:trixie AS base |
| 14 | + |
| 15 | +ENV DEBIAN_FRONTEND=noninteractive |
| 16 | + |
| 17 | +RUN apt-get update -y && apt-get upgrade -y |
| 18 | +RUN apt-get install -y sudo devscripts |
| 19 | + |
| 20 | +# Build tools |
| 21 | +RUN apt-get install -y \ |
| 22 | + build-essential \ |
| 23 | + ca-certificates \ |
| 24 | + ca-certificates-java \ |
| 25 | + git \ |
| 26 | + openjdk-21-jdk \ |
| 27 | + pkg-config \ |
| 28 | + python3 \ |
| 29 | + zip \ |
| 30 | + unzip \ |
| 31 | + wget |
| 32 | + |
| 33 | +# Debian packaging tools (needed by build_packages.sh / debuild) |
| 34 | +RUN apt-get install -y \ |
| 35 | + config-package-dev \ |
| 36 | + debhelper-compat \ |
| 37 | + equivs |
| 38 | + |
| 39 | +# LLVM/Clang 19 toolchain - matches the hermetic LLVM 19.1.7 used by |
| 40 | +# amd64/arm64. System-installed because no prebuilt hermetic LLVM exists |
| 41 | +# for riscv64. |
| 42 | +RUN apt-get install -y \ |
| 43 | + clang-19 \ |
| 44 | + lld-19 \ |
| 45 | + libc++-19-dev \ |
| 46 | + libc++abi-19-dev \ |
| 47 | + libclang-rt-19-dev \ |
| 48 | + libunwind-19-dev |
| 49 | + |
| 50 | +# Bridge Debian's legacy clang-rt layout to the per-target layout expected |
| 51 | +# by toolchains_llvm. |
| 52 | +RUN LEGACY_RT="/usr/lib/llvm-19/lib/clang/19/lib/linux/libclang_rt.builtins-riscv64.a" && \ |
| 53 | + TARGET_DIR="/usr/lib/llvm-19/lib/clang/19/lib/riscv64-unknown-linux-gnu" && \ |
| 54 | + TARGET_RT="${TARGET_DIR}/libclang_rt.builtins.a" && \ |
| 55 | + if [ -f "$LEGACY_RT" ] && [ ! -e "$TARGET_RT" ]; then \ |
| 56 | + mkdir -p "$TARGET_DIR" && ln -sf "$LEGACY_RT" "$TARGET_RT"; \ |
| 57 | + fi |
| 58 | + |
| 59 | +# Rust toolchain (needed for cargo-bazel) |
| 60 | +RUN apt-get install -y rustc cargo |
| 61 | + |
| 62 | +# Golang |
| 63 | +RUN apt-get install -y golang |
| 64 | + |
| 65 | +# Build Bazel from source - no prebuilt binary for riscv64. |
| 66 | +ARG BAZEL_VERSION=8.5.1 |
| 67 | +RUN tmpdir="$(mktemp -d)" && \ |
| 68 | + cd "$tmpdir" && \ |
| 69 | + wget -q "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip" && \ |
| 70 | + unzip -q "bazel-${BAZEL_VERSION}-dist.zip" && \ |
| 71 | + env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh && \ |
| 72 | + cp output/bazel /usr/local/bin/bazel && \ |
| 73 | + cd / && rm -rf "$tmpdir" |
| 74 | + |
| 75 | +# Build cargo-bazel from the rules_rust source tree. The crates.io |
| 76 | +# "cargo-bazel" package is NOT the same binary -- it lacks flags like |
| 77 | +# --repository-name that rules_rust expects. Must build from the matching |
| 78 | +# rules_rust release tag. |
| 79 | +ARG RULES_RUST_VERSION=0.68.1 |
| 80 | +RUN tmpdir="$(mktemp -d)" && \ |
| 81 | + cd "$tmpdir" && \ |
| 82 | + wget -q "https://github.com/bazelbuild/rules_rust/archive/refs/tags/${RULES_RUST_VERSION}.tar.gz" && \ |
| 83 | + tar xzf "${RULES_RUST_VERSION}.tar.gz" && \ |
| 84 | + cargo install --locked --path "rules_rust-${RULES_RUST_VERSION}/crate_universe" \ |
| 85 | + --root /usr/local && \ |
| 86 | + cd / && rm -rf "$tmpdir" |
| 87 | + |
| 88 | +ENV CARGO_BAZEL_GENERATOR_URL=file:///usr/local/bin/cargo-bazel |
| 89 | + |
| 90 | +ENTRYPOINT ["tools/buildutils/cw/entrypoint.sh"] |
0 commit comments