riscv.Dockerfile 2.9 KB

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