riscv.Dockerfile 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # This script uses QEMU emulation, so before execution pull the corresponding
  2. # images:
  3. # docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  4. # Usage(on repo root folder):
  5. # docker build . --platform=linux/riscv64 --pull --no-cache --shm-size=196m -t darkfi:riscv -f ./contrib/docker/riscv2.Dockerfile -o riscv-bins
  6. # Optionally, add arguments like: --build-arg BINS=darkirc
  7. # If you want to keep building using the same builder, remove --no-cache option.
  8. # Arguments configuration
  9. ARG DEBIAN_VER=sid
  10. ARG RUST_VER=nightly-2024-04-05
  11. #TODO: only darkirc has been tested, have to check rest binaries to add deps and ports.
  12. ARG BINS=darkirc
  13. # Environment setup
  14. FROM --platform=$TARGETPLATFORM riscv64/debian:${DEBIAN_VER} as builder
  15. ## Arguments import
  16. ARG RUST_VER
  17. ARG BINS
  18. ## Install system dependencies
  19. RUN apt-get update
  20. RUN apt-get install -y git cmake make gcc g++ pkg-config \
  21. libasound2-dev libclang-dev libssl-dev libsqlcipher-dev \
  22. libsqlite3-dev wabt wget
  23. ## Rust installation
  24. RUN wget -O install-rustup.sh https://sh.rustup.rs && \
  25. sh install-rustup.sh -yq --default-toolchain none && \
  26. rm install-rustup.sh
  27. ENV PATH "${PATH}:/root/.cargo/bin/"
  28. RUN rustup default ${RUST_VER}
  29. RUN rustup target add wasm32-unknown-unknown --toolchain ${RUST_VER}
  30. # Build binaries
  31. FROM builder as rust_builder
  32. WORKDIR /opt/darkfi
  33. COPY . /opt/darkfi
  34. # Cleanup existing binaries
  35. RUN rm -rf zkas bin/zkas/zkas darkfid bin/darkfid/darkfid \
  36. darkirc bin/darkirc/darkirc lilith bin/lilith/lilith \
  37. tau-cli bin/tau/tau-cli/tau-cli taud bin/tau/taud/taud \
  38. vanityaddr bin/vanityaddr/vanityaddr
  39. # Risc-V support is highly experimental so we have to add some hack patches
  40. # at Cargo.toml where [patch.crates-io] exists.
  41. RUN sed -i Cargo.toml -e '335iring = {git="https://github.com/aggstam/ring"} \n\
  42. rustls = {git="https://github.com/aggstam/rustls", branch="risc-v"} \n\
  43. rcgen = {git="https://github.com/aggstam/rcgen"} \n'
  44. # Add hacked dependencies into each crate that uses them
  45. RUN sed -i bin/darkirc/Cargo.toml \
  46. -e "s|\[dependencies\]|\[dependencies\]\nring = \"0.16.20\"|g"
  47. RUN cargo +${RUST_VER} update
  48. RUN sed -i rust-toolchain.toml -e "s|nightly|${RUST_VER}|g"
  49. RUN make CARGO="cargo +${RUST_VER}" ${BINS} && \
  50. mkdir compiled-bins && \
  51. (if [ -e zkas ]; then cp -a zkas compiled-bins/; fi;) && \
  52. (if [ -e darkfid ]; then cp -a darkfid compiled-bins/; fi;) && \
  53. (if [ -e darkirc ]; then cp -a darkirc compiled-bins/; fi;) && \
  54. (if [ -e lilith ]; then cp -a lilith compiled-bins/; fi;) && \
  55. (if [ -e "tau-cli" ]; then cp -a tau-cli compiled-bins/; fi;) && \
  56. (if [ -e taud ]; then cp -a taud compiled-bins/; fi;) && \
  57. (if [ -e vanityaddr ]; then cp -a vanityaddr compiled-bins/; fi;)
  58. # Export binaries from rust builder
  59. FROM scratch
  60. COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./