Skip to content

Commit f1f0470

Browse files
authored
build: use cargo binstall to speed up builds (#2321)
1 parent 4b0316c commit f1f0470

File tree

8 files changed

+91
-50
lines changed

8 files changed

+91
-50
lines changed

.devcontainer/Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,30 @@ ENV PATH=$CARGO_HOME/bin:$PATH
4444
COPY rust-toolchain.toml .
4545
RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | tr -d '"')" && \
4646
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
47-
--profile minimal \
4847
-y \
4948
--default-toolchain "${TOOLCHAIN_VERSION}" \
5049
--target wasm32-unknown-unknown
5150
52-
# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain
53-
# better build caching
54-
RUN if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \
55-
RUSTFLAGS="-C target-feature=-crt-static" \
56-
# Meanwhile if you want to update wasm-bindgen you also need to update version in:
57-
# - packages/wasm-dpp/Cargo.toml
58-
# - packages/wasm-dpp/scripts/build-wasm.sh
59-
cargo install [email protected] --locked
51+
# Download and install cargo-binstall
52+
ENV BINSTALL_VERSION=1.10.11
53+
RUN set -ex; \
54+
if [ "$TARGETARCH" = "amd64" ]; then \
55+
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
56+
elif [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
57+
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
58+
else \
59+
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
60+
fi; \
61+
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
62+
curl -L --fail --show-error "$DOWNLOAD_URL" -o /tmp/cargo-binstall.tgz; \
63+
tar -xzf /tmp/cargo-binstall.tgz -C /tmp cargo-binstall; \
64+
chmod +x /tmp/cargo-binstall; \
65+
/tmp/cargo-binstall -y --force cargo-binstall; \
66+
rm /tmp/cargo-binstall; \
67+
cargo binstall -V
68+
69+
RUN cargo binstall [email protected] --locked \
70+
--no-discover-github-token \
71+
--disable-telemetry \
72+
--no-track \
73+
--no-confirm

.github/actions/docker/action.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ runs:
115115
cache-to: ${{ steps.layer_cache_settings.outputs.cache_to }}
116116
outputs: type=image,name=${{ inputs.image_org }}/${{ inputs.image_name }},push-by-digest=${{ inputs.push_tags != 'true' }},name-canonical=true,push=true
117117

118-
- name: Save Docker mount cache
119-
uses: dcginfra/buildkit-cache-dance/extract@s5cmd
120-
if: ${{ inputs.cache_mounts != '' }}
121-
with:
122-
bucket: ${{ inputs.bucket }}
123-
mounts: ${{ inputs.cache_mounts }}
118+
# TODO: This is doesn't work
119+
# - name: Save Docker mount cache
120+
# uses: dcginfra/buildkit-cache-dance/extract@s5cmd
121+
# if: ${{ inputs.cache_mounts != '' }}
122+
# with:
123+
# bucket: ${{ inputs.bucket }}
124+
# mounts: ${{ inputs.cache_mounts }}

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ jobs:
6969
- name: Setup Node.JS
7070
uses: ./.github/actions/nodejs
7171

72+
- name: Install Cargo binstall
73+
uses: cargo-bins/[email protected]
74+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
75+
76+
- name: Install wasm-bindgen-cli
77+
run: cargo binstall [email protected]
78+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
79+
7280
- name: Build packages
7381
run: yarn build
7482
env:

.github/workflows/tests-build-js.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ jobs:
4646
with:
4747
target: wasm32-unknown-unknown
4848

49+
- name: Install Cargo binstall
50+
uses: cargo-bins/[email protected]
51+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
52+
53+
- name: Install wasm-bindgen-cli
54+
run: cargo binstall [email protected]
55+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
56+
4957
- name: Build JS packages
5058
run: yarn build
5159
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

Dockerfile

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# syntax = docker/dockerfile:1.5
1+
# syntax = docker/dockerfile:1
22

33
# Docker image for rs-drive-abci
44
#
@@ -35,13 +35,12 @@
3535
# 3. Configuration variables are shared between runs using /root/env file.
3636

3737
ARG ALPINE_VERSION=3.18
38-
ARG PROTOC_VERSION=27.3
3938
ARG RUSTC_WRAPPER
4039

4140
#
4241
# DEPS: INSTALL AND CACHE DEPENDENCIES
4342
#
44-
FROM node:20-alpine${ALPINE_VERSION} as deps-base
43+
FROM node:20-alpine${ALPINE_VERSION} AS deps-base
4544

4645
#
4746
# Install some dependencies
@@ -93,9 +92,12 @@ RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | t
9392
--default-toolchain "${TOOLCHAIN_VERSION}" \
9493
--target wasm32-unknown-unknown
9594
95+
ONBUILD ENV HOME=/root
96+
ONBUILD ENV CARGO_HOME=$HOME/.cargo
97+
9698
# Install protoc - protobuf compiler
9799
# The one shipped with Alpine does not work
98-
ARG PROTOC_VERSION
100+
ARG PROTOC_VERSION=27.3
99101
RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64; fi; \
100102
curl -Ls https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip \
101103
-o /tmp/protoc.zip && \
@@ -107,14 +109,13 @@ RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else e
107109
RUN rm /usr/bin/cc && ln -s /usr/bin/clang /usr/bin/cc
108110
109111
# Select whether we want dev or release
110-
ARG CARGO_BUILD_PROFILE=dev
111-
ENV CARGO_BUILD_PROFILE ${CARGO_BUILD_PROFILE}
112+
ONBUILD ARG CARGO_BUILD_PROFILE=dev
112113
113114
ARG NODE_ENV=production
114-
ENV NODE_ENV ${NODE_ENV}
115+
ENV NODE_ENV=${NODE_ENV}
115116
116117
#
117-
# DEPS-SCCACHE stage
118+
# DEPS-SCCACHE stage
118119
#
119120
# This stage is used to install sccache and configure it.
120121
# Later on, one should source /root/env before building to use sccache.
@@ -158,12 +159,12 @@ ARG SCCACHE_REGION
158159
ARG SCCACHE_S3_KEY_PREFIX
159160
160161
# Generate sccache configuration variables and save them to /root/env
161-
#
162+
#
162163
# We only enable one cache at a time. Setting env variables belonging to multiple cache backends may fail the build.
163164
RUN <<EOS
164165
set -ex -o pipefail
165166
166-
if [ -n "${SCCACHE_GHA_ENABLED}" ]; then
167+
if [ -n "${SCCACHE_GHA_ENABLED}" ]; then
167168
# Github Actions cache
168169
echo "export SCCACHE_GHA_ENABLED=${SCCACHE_GHA_ENABLED}" >> /root/env
169170
echo "export ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}" >> /root/env
@@ -186,7 +187,7 @@ RUN <<EOS
186187
# memcached
187188
echo "export SCCACHE_MEMCACHED='${SCCACHE_MEMCACHED}'" >> /root/env
188189
fi
189-
190+
190191
if [ -n "${RUSTC_WRAPPER}" ]; then
191192
echo "export CXX='${RUSTC_WRAPPER} clang++'" >> /root/env
192193
echo "export CC='${RUSTC_WRAPPER} clang'" >> /root/env
@@ -217,7 +218,7 @@ WORKDIR /tmp/rocksdb
217218
218219
RUN <<EOS
219220
set -ex -o pipefail
220-
git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 .
221+
git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 .
221222
source /root/env
222223
223224
if [[ "$TARGETARCH" == "amd64" ]] ; then
@@ -251,22 +252,32 @@ FROM deps-rocksdb AS deps
251252
252253
WORKDIR /platform
253254
254-
# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain
255-
# better build caching
256-
RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOME}/registry/index \
257-
--mount=type=cache,sharing=shared,id=cargo_registry_cache,target=${CARGO_HOME}/registry/cache \
258-
--mount=type=cache,sharing=shared,id=cargo_git,target=${CARGO_HOME}/git/db \
259-
--mount=type=cache,sharing=shared,id=target_${TARGETARCH},target=/platform/target \
260-
source $HOME/.cargo/env && \
261-
source /root/env && \
262-
RUSTFLAGS="-C target-feature=-crt-static" \
263-
CARGO_TARGET_DIR="/platform/target" \
264-
# TODO: Build wasm with build.rs
265-
# Meanwhile if you want to update wasm-bindgen you also need to update version in:
266-
# - packages/wasm-dpp/Cargo.toml
267-
# - packages/wasm-dpp/scripts/build-wasm.sh
268-
cargo install --profile "$CARGO_BUILD_PROFILE" [email protected] [email protected] --locked && \
269-
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi
255+
# Download and install cargo-binstall
256+
ENV BINSTALL_VERSION=1.10.11
257+
RUN set -ex; \
258+
if [ "$TARGETARCH" = "amd64" ]; then \
259+
CARGO_BINSTALL_ARCH="x86_64-unknown-linux-musl"; \
260+
elif [ "$TARGETARCH" = "arm64" ]; then \
261+
CARGO_BINSTALL_ARCH="aarch64-unknown-linux-musl"; \
262+
else \
263+
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
264+
fi; \
265+
# Construct download URL
266+
DOWNLOAD_URL="https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-${CARGO_BINSTALL_ARCH}.tgz"; \
267+
# Download and extract the cargo-binstall binary
268+
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 -; \
269+
./cargo-binstall -y --force cargo-binstall; \
270+
rm ./cargo-binstall; \
271+
source $HOME/.cargo/env; \
272+
cargo binstall -V
273+
274+
RUN source $HOME/.cargo/env; \
275+
276+
--locked \
277+
--no-discover-github-token \
278+
--disable-telemetry \
279+
--no-track \
280+
--no-confirm
270281
271282
#
272283
# Rust build planner to speed up builds
@@ -291,7 +302,6 @@ FROM deps AS build-drive-abci
291302
292303
SHELL ["/bin/bash", "-o", "pipefail","-e", "-x", "-c"]
293304
294-
295305
WORKDIR /platform
296306
297307
COPY --from=build-planner /platform/recipe.json recipe.json
@@ -333,9 +343,9 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM
333343
--package drive-abci \
334344
${FEATURES_FLAG} \
335345
--locked && \
336-
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
346+
cp /platform/target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
337347
if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi
338-
348+
339349
#
340350
# STAGE: BUILD JAVASCRIPT INTERMEDIATE IMAGE
341351
#

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ this repository may be used on the following networks:
6161
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.
6262
You can find your default shell with `echo $SHELL`
6363
- Reload your shell with `source ~/.zshrc` or `source ~/.bash_profile`
64-
- `cargo install [email protected].85`
64+
- `cargo install [email protected].86`
6565
- *double-check that wasm-bindgen-cli version above matches wasm-bindgen version in Cargo.lock file*
6666
- *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)*
6767
- essential build tools - example for Debian/Ubuntu: `apt install -y build-essential libssl-dev pkg-config clang cmake llvm`

packages/wasm-dpp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Library consumers must ignore class names minification for `@dashevo/wasm-dpp` l
3939

4040
- Install [Rust](https://www.rust-lang.org/tools/install) v1.73+
4141
- Add wasm32 target: `$ rustup target add wasm32-unknown-unknown`
42-
- Install wasm-bingen-cli: `cargo install [email protected].85`
42+
- Install wasm-bingen-cli: `cargo install [email protected].86`
4343
- *double-check that wasm-bindgen-cli version above matches wasm-bindgen version in Cargo.lock file*
4444
- *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)*
4545

packages/wasm-dpp/scripts/build-wasm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ fi
2828
# - packages/wasm-dpp/Cargo.toml
2929
# - Dockerfile
3030
if ! [[ -x "$(command -v wasm-bindgen)" ]]; then
31-
echo "Wasm-bindgen CLI ${WASM_BINDGEN_VERSION} is not installed. Installing"
32-
cargo install --config net.git-fetch-with-cli=true --profile "${CARGO_BUILD_PROFILE}" -f "[email protected]"
31+
echo "Wasm-bindgen CLI ${WASM_BINDGEN_VERSION} is not installed."
32+
exit 1
3333
fi
3434

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

0 commit comments

Comments
 (0)