Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use cargo binstall to speed up builds #2321

Merged
merged 26 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
24177fa
feat: hardcoded identity transfers in strategy tests
pauldelucia Nov 4, 2024
dacc6db
fix(drive): uncommitted state if db transaction fails (#2305)
shumkov Nov 4, 2024
306b86c
fix(drive): apply batch is not using transaction in `remove_all_votes…
QuantumExplorer Nov 4, 2024
99fe5fa
add comment
pauldelucia Nov 4, 2024
cee3098
Merge remote-tracking branch 'origin/v1.6-dev' into feat/hardcoded-id…
pauldelucia Nov 4, 2024
0d3e091
comment
pauldelucia Nov 5, 2024
e421514
use into_iter instead of iter
pauldelucia Nov 5, 2024
3d941ec
use current identities instead of hardcoded start identities
pauldelucia Nov 5, 2024
4bc0a65
let transfer keys be any security level or key type
pauldelucia Nov 5, 2024
dc48827
fix
pauldelucia Nov 5, 2024
cafda11
feat: hardcoded identity transfers in strategy tests (#2312)
pauldelucia Nov 5, 2024
b86f4e0
Merge branch 'v1.6-dev' of github.com:dashpay/platform into v1.6-dev
shumkov Nov 6, 2024
ae97f47
ci: run devcontainers workflow only on push to master (#2295)
shumkov Nov 6, 2024
48cca1a
ci: do not run test on push (#2308)
shumkov Nov 6, 2024
5c80069
ci: use prebuilt librocksdb in github actions (#2316)
lklimek Nov 8, 2024
fc0082d
build: use cargo binstall to speed up builds
shumkov Nov 9, 2024
d4c2f7d
build: use binstall in devcontainer too
shumkov Nov 9, 2024
88d3596
Merge branch 'v1.6-dev' into ci/binstall
shumkov Nov 10, 2024
681bf72
ci: install wasm bindgen for release
shumkov Nov 11, 2024
1ac8d3b
build: CARGO_HOME is not defined
shumkov Nov 11, 2024
fa4cf99
build: fix sccache error
shumkov Nov 13, 2024
6584fae
ci: use version instead of branch
shumkov Nov 13, 2024
8c880aa
Merge branch 'refs/heads/v1.6-dev' into ci/binstall
shumkov Nov 13, 2024
113e695
ci: specify correct version
shumkov Nov 13, 2024
6e02f6a
build: set HOME variable
shumkov Nov 13, 2024
e395f2e
ci: disable saving mount cache
shumkov Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,30 @@ ENV PATH=$CARGO_HOME/bin:$PATH
COPY rust-toolchain.toml .
RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | tr -d '"')" && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
--profile minimal \
-y \
--default-toolchain "${TOOLCHAIN_VERSION}" \
--target wasm32-unknown-unknown

# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain
# better build caching
RUN if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \
RUSTFLAGS="-C target-feature=-crt-static" \
# Meanwhile if you want to update wasm-bindgen you also need to update version in:
# - packages/wasm-dpp/Cargo.toml
# - packages/wasm-dpp/scripts/build-wasm.sh
cargo install [email protected] --locked
# Download and install cargo-binstall
ENV BINSTALL_VERSION=1.10.11
RUN set -ex; \
if [ "$TARGETARCH" = "amd64" ]; then \
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
elif [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi; \
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
curl -L --fail --show-error "$DOWNLOAD_URL" -o /tmp/cargo-binstall.tgz; \
tar -xzf /tmp/cargo-binstall.tgz -C /tmp cargo-binstall; \
chmod +x /tmp/cargo-binstall; \
/tmp/cargo-binstall -y --force cargo-binstall; \
rm /tmp/cargo-binstall; \
cargo binstall -V

shumkov marked this conversation as resolved.
Show resolved Hide resolved
RUN cargo binstall [email protected] --locked \
--no-discover-github-token \
--disable-telemetry \
--no-track \
--no-confirm
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ jobs:
- name: Setup Node.JS
uses: ./.github/actions/nodejs

- name: Install Cargo binstall
uses: cargo-bins/[email protected]
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Install wasm-bindgen-cli
run: cargo binstall [email protected]
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Build packages
run: yarn build
env:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests-build-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ jobs:
with:
target: wasm32-unknown-unknown

- name: Install Cargo binstall
uses: cargo-bins/[email protected]
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Install wasm-bindgen-cli
run: cargo binstall [email protected]
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Build JS packages
run: yarn build
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand Down
72 changes: 41 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.5
# syntax = docker/dockerfile:1

lklimek marked this conversation as resolved.
Show resolved Hide resolved
# Docker image for rs-drive-abci
#
Expand Down Expand Up @@ -35,13 +35,12 @@
# 3. Configuration variables are shared between runs using /root/env file.

ARG ALPINE_VERSION=3.18
ARG PROTOC_VERSION=27.3
ARG RUSTC_WRAPPER

#
# DEPS: INSTALL AND CACHE DEPENDENCIES
#
FROM node:20-alpine${ALPINE_VERSION} as deps-base
FROM node:20-alpine${ALPINE_VERSION} AS deps-base

#
# Install some dependencies
Expand Down Expand Up @@ -93,9 +92,12 @@ RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | t
--default-toolchain "${TOOLCHAIN_VERSION}" \
--target wasm32-unknown-unknown

ONBUILD ENV HOME=/root
ONBUILD ENV CARGO_HOME=$HOME/.cargo

# Install protoc - protobuf compiler
# The one shipped with Alpine does not work
ARG PROTOC_VERSION
ARG PROTOC_VERSION=27.3
RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64; fi; \
curl -Ls https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip \
-o /tmp/protoc.zip && \
Expand All @@ -107,14 +109,13 @@ RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else e
RUN rm /usr/bin/cc && ln -s /usr/bin/clang /usr/bin/cc

# Select whether we want dev or release
ARG CARGO_BUILD_PROFILE=dev
ENV CARGO_BUILD_PROFILE ${CARGO_BUILD_PROFILE}
ONBUILD ARG CARGO_BUILD_PROFILE=dev

ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
ENV NODE_ENV=${NODE_ENV}

#
# DEPS-SCCACHE stage
# DEPS-SCCACHE stage
#
# This stage is used to install sccache and configure it.
# Later on, one should source /root/env before building to use sccache.
Expand Down Expand Up @@ -158,12 +159,12 @@ ARG SCCACHE_REGION
ARG SCCACHE_S3_KEY_PREFIX

# Generate sccache configuration variables and save them to /root/env
#
#
# We only enable one cache at a time. Setting env variables belonging to multiple cache backends may fail the build.
RUN <<EOS
set -ex -o pipefail

if [ -n "${SCCACHE_GHA_ENABLED}" ]; then
if [ -n "${SCCACHE_GHA_ENABLED}" ]; then
# Github Actions cache
echo "export SCCACHE_GHA_ENABLED=${SCCACHE_GHA_ENABLED}" >> /root/env
echo "export ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}" >> /root/env
Expand All @@ -186,7 +187,7 @@ RUN <<EOS
# memcached
echo "export SCCACHE_MEMCACHED='${SCCACHE_MEMCACHED}'" >> /root/env
fi

if [ -n "${RUSTC_WRAPPER}" ]; then
echo "export CXX='${RUSTC_WRAPPER} clang++'" >> /root/env
echo "export CC='${RUSTC_WRAPPER} clang'" >> /root/env
Expand Down Expand Up @@ -217,7 +218,7 @@ WORKDIR /tmp/rocksdb

RUN <<EOS
set -ex -o pipefail
git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 .
git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 .
source /root/env

if [[ "$TARGETARCH" == "amd64" ]] ; then
Expand Down Expand Up @@ -251,22 +252,32 @@ FROM deps-rocksdb AS deps

WORKDIR /platform

# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain
# better build caching
RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \
--mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \
--mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \
--mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \
source $HOME/.cargo/env && \
source /root/env && \
RUSTFLAGS="-C target-feature=-crt-static" \
CARGO_TARGET_DIR="/platform/target" \
# TODO: Build wasm with build.rs
# Meanwhile if you want to update wasm-bindgen you also need to update version in:
# - packages/wasm-dpp/Cargo.toml
# - packages/wasm-dpp/scripts/build-wasm.sh
cargo install --profile "$CARGO_BUILD_PROFILE" [email protected] [email protected] --locked && \
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi
# Download and install cargo-binstall
ENV BINSTALL_VERSION=1.10.11
RUN set -ex; \
if [ "$TARGETARCH" = "amd64" ]; then \
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi; \
# Construct download URL
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
# Download and extract the cargo-binstall binary
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -L --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL" | tar -xvzf -; \
./cargo-binstall -y --force cargo-binstall; \
rm ./cargo-binstall; \
source $HOME/.cargo/env; \
cargo binstall -V

RUN source $HOME/.cargo/env; \
shumkov marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +255 to +273
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling in cargo-binstall installation

The installation script should verify the successful installation of cargo-binstall before removing the binary and should handle potential network failures.

 RUN set -ex; \
     if [ "$TARGETARCH" = "amd64" ]; then \
         CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
     elif [ "$TARGETARCH" = "arm64" ]; then \
         CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
     else \
         echo "Unsupported architecture: $TARGETARCH"; exit 1; \
     fi; \
     DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
-    curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -L --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL" | tar -xvzf -;  \
-    ./cargo-binstall -y --force cargo-binstall; \
-    rm ./cargo-binstall; \
+    curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -L --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL" -o cargo-binstall.tgz || exit 1; \
+    tar -xvzf cargo-binstall.tgz || exit 1; \
+    ./cargo-binstall -y --force cargo-binstall || exit 1; \
+    if ! command -v cargo-binstall >/dev/null 2>&1; then \
+        echo "cargo-binstall installation failed"; \
+        exit 1; \
+    fi; \
+    rm ./cargo-binstall cargo-binstall.tgz; \
     source $HOME/.cargo/env; \
     cargo binstall -V
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Download and install cargo-binstall
ENV BINSTALL_VERSION=1.10.11
RUN set -ex; \
if [ "$TARGETARCH" = "amd64" ]; then \
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi; \
# Construct download URL
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
# Download and extract the cargo-binstall binary
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -L --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL" | tar -xvzf -; \
./cargo-binstall -y --force cargo-binstall; \
rm ./cargo-binstall; \
source $HOME/.cargo/env; \
cargo binstall -V
# Download and install cargo-binstall
ENV BINSTALL_VERSION=1.10.11
RUN set -ex; \
if [ "$TARGETARCH" = "amd64" ]; then \
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi; \
# Construct download URL
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
# Download and extract the cargo-binstall binary
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -L --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL" -o cargo-binstall.tgz || exit 1; \
tar -xvzf cargo-binstall.tgz || exit 1; \
./cargo-binstall -y --force cargo-binstall || exit 1; \
if ! command -v cargo-binstall >/dev/null 2>&1; then \
echo "cargo-binstall installation failed"; \
exit 1; \
fi; \
rm ./cargo-binstall cargo-binstall.tgz; \
source $HOME/.cargo/env; \
cargo binstall -V

cargo binstall [email protected] [email protected] \
--locked \
--no-discover-github-token \
--disable-telemetry \
--no-track \
--no-confirm

#
# Rust build planner to speed up builds
Expand All @@ -291,7 +302,6 @@ FROM deps AS build-drive-abci

SHELL ["/bin/bash", "-o", "pipefail","-e", "-x", "-c"]


WORKDIR /platform

COPY --from=build-planner /platform/recipe.json recipe.json
Expand Down Expand Up @@ -333,9 +343,9 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM
--package drive-abci \
${FEATURES_FLAG} \
--locked && \
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi

#
Comment on lines +346 to +348
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for binary copy operation

The copy operation of the built binary should be verified to ensure the file exists and the copy was successful.

-    cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
+    if [ ! -f "/platform/target/${OUT_DIRECTORY}/drive-abci" ]; then \
+        echo "Binary not found in /platform/target/${OUT_DIRECTORY}/drive-abci"; \
+        exit 1; \
+    fi && \
+    cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ || exit 1 && \
     if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi
if [ ! -f "/platform/target/${OUT_DIRECTORY}/drive-abci" ]; then \
echo "Binary not found in /platform/target/${OUT_DIRECTORY}/drive-abci"; \
exit 1; \
fi && \
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ || exit 1 && \
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi

# STAGE: BUILD JAVASCRIPT INTERMEDIATE IMAGE
#
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ this repository may be used on the following networks:
in terminal run `echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc` or `echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.bash_profile` depending on your default shell.
You can find your default shell with `echo $SHELL`
- Reload your shell with `source ~/.zshrc` or `source ~/.bash_profile`
- `cargo install [email protected].85`
- `cargo install [email protected].86`
- *double-check that wasm-bindgen-cli version above matches wasm-bindgen version in Cargo.lock file*
- *Depending on system, additional packages may need to be installed as a prerequisite for wasm-bindgen-cli. If anything is missing, installation will error and prompt what packages are missing (i.e. clang, llvm, libssl-dev)*
- essential build tools - example for Debian/Ubuntu: `apt install -y build-essential libssl-dev pkg-config clang cmake llvm`
Expand Down
2 changes: 1 addition & 1 deletion packages/wasm-dpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Library consumers must ignore class names minification for `@dashevo/wasm-dpp` l

- Install [Rust](https://www.rust-lang.org/tools/install) v1.73+
- Add wasm32 target: `$ rustup target add wasm32-unknown-unknown`
- Install wasm-bingen-cli: `cargo install [email protected].85`
- Install wasm-bingen-cli: `cargo install [email protected].86`
- *double-check that wasm-bindgen-cli version above matches wasm-bindgen version in Cargo.lock file*
- *Depending on system, additional packages may need to be installed as a prerequisite for wasm-bindgen-cli. If anything is missing, installation will error and prompt what packages are missing (i.e. clang, llvm, libssl-dev)*

Expand Down
4 changes: 2 additions & 2 deletions packages/wasm-dpp/scripts/build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fi
# - packages/wasm-dpp/Cargo.toml
# - Dockerfile
if ! [[ -x "$(command -v wasm-bindgen)" ]]; then
echo "Wasm-bindgen CLI ${WASM_BINDGEN_VERSION} is not installed. Installing"
cargo install --config net.git-fetch-with-cli=true --profile "${CARGO_BUILD_PROFILE}" -f "[email protected]"
echo "Wasm-bindgen CLI ${WASM_BINDGEN_VERSION} is not installed."
exit 1
shumkov marked this conversation as resolved.
Show resolved Hide resolved
fi

# On a mac, bundled clang won't work - you need to install LLVM manually through brew,
Expand Down
Loading