Skip to content

Commit

Permalink
Add support for cargo build --verifiable --lint command (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
smiasojed authored Apr 23, 2024
1 parent 6c5930b commit 255d0ef
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
38 changes: 30 additions & 8 deletions build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM docker.io/bitnami/minideb:bullseye-amd64 as slimmed-rust
# The rust version to use
ARG RUST_VERSION=stable
# The cargo contract version to use
ARG CARGO_CONTRACT_VERSION=3.2.0
ARG CARGO_CONTRACT_VERSION=4.1.0
# Url to the cargo-contract repository to install from
ARG CARGO_CONTRACT_GIT
# Branch to use in git repository
Expand All @@ -19,6 +19,8 @@ ARG WGET_VERSION=1.21-1+deb11u1
# g++ package version
ARG G_VERSION=4:10.2.1-1
ARG MUSL_V=1.2.2-1
# The rust version used by linter
ARG RUST_LINTER_VERSION=nightly-2023-12-28

# metadata
LABEL io.parity.image.vendor="Parity Technologies" \
Expand All @@ -37,7 +39,8 @@ LABEL io.parity.image.vendor="Parity Technologies" \
io.parity.version.gcc=${GCC_VERSION} \
io.parity.version.wget=${WGET_VERSION} \
io.parity.version.g_plus_plus=${G_VERSION} \
io.parity.version.musl=${MUSL_V}
io.parity.version.musl=${MUSL_V} \
io.parity.version.rust_linter=${RUST_LINTER_VERSION}

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
Expand All @@ -51,6 +54,9 @@ RUN set -eux \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --profile minimal --component rust-src rustfmt clippy --default-toolchain $RUST_VERSION \
&& rm rustup-init \
# Install nightly toolchain required by `cargo contract build --verifiable --lint` command
&& rustup install ${RUST_LINTER_VERSION} --profile minimal \
&& rustup component add rust-src --toolchain ${RUST_LINTER_VERSION} \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
&& cargo --version \
Expand All @@ -68,12 +74,15 @@ ARG CARGO_CONTRACT_BRANCH
ARG CARGO_CONTRACT_TAG
ARG CARGO_CONTRACT_REV
ARG CARGO_CONTRACT_GIT
ARG RUST_LINTER_VERSION

# This is important, see https://github.com/rust-lang/docker-rust/issues/85
ENV RUSTFLAGS="-C target-feature=-crt-static"
ENV RUSTFLAGS="-C target-feature=-crt-static" \
DYLINT_DRIVER_PATH=/usr/local/dylint_drivers

# Install required packages for `cargo-contract`
RUN apt-get -y update && apt-get -y install gcc=${GCC_VERSION} g++=${G_VERSION} musl-dev=${MUSL_V} \
# libssl-dev and pkg-config is required by cargo-dylint
RUN apt-get -y update && apt-get -y install gcc=${GCC_VERSION} g++=${G_VERSION} musl-dev=${MUSL_V} libssl-dev pkg-config \
# Install cargo contract from git if the arg is set
&& if [ -n "$CARGO_CONTRACT_GIT" ]; then \
COMMAND="cargo install --git ${CARGO_CONTRACT_GIT}" ; \
Expand All @@ -91,19 +100,32 @@ RUN apt-get -y update && apt-get -y install gcc=${GCC_VERSION} g++=${G_VERSION}
fi \
&& echo "Executing ${COMMAND}" \
&& eval "${COMMAND}" \
# Cleanup after `cargo install`
&& rm -rf ${CARGO_HOME}/"registry" ${CARGO_HOME}/"git" /root/.cache/sccache \
# Install cargo-dylint, dylint-link required by `cargo contract build --verifiable --lint` command
&& cargo +${RUST_LINTER_VERSION} install cargo-dylint dylint-link \
&& cargo install cargo-dylint dylint-link \
# Check if build with linting works
&& cargo contract new test \
# Generate /usr/local/dylint_drivers/nightly-2023-12-28-x86_64-unknown-linux-gnu/dylint-driver bin
&& mkdir -p $DYLINT_DRIVER_PATH \
&& cd test && cargo contract build --lint --verbose --release && cd .. \
&& rm -rf test \
# apt clean up
&& apt-get remove -y gnupg \
&& apt-get remove -y gnupg libssl-dev pkg-config \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
# Cleanup cargo
&& rm -rf ${CARGO_HOME}/"registry" ${CARGO_HOME}/"git" /root/.cache/sccache

FROM slimmed-rust as ink-dev

COPY --from=cc-builder /usr/local/dylint_drivers /usr/local/dylint_drivers
COPY --from=cc-builder /usr/local/cargo/bin/cargo-contract /usr/local/bin/cargo-contract
COPY --from=cc-builder /usr/local/cargo/bin/cargo-dylint /usr/local/cargo/bin/cargo-dylint
COPY --from=cc-builder /usr/local/cargo/bin/dylint-link /usr/local/cargo/bin/dylint-link

WORKDIR /contract
ENV DYLINT_DRIVER_PATH=/usr/local/dylint_drivers

# default entry point
ENTRYPOINT ["cargo", "contract"]
6 changes: 3 additions & 3 deletions build-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ _Settings_ -> _Features in development_ tab in Docker Desktop App.
Build docker image:

```bash
docker buildx build -t paritytech/contracts-verifiable:0.0.1 .
docker buildx build -t paritytech/contracts-verifiable:0.0.1-local --build-arg CARGO_CONTRACT_VERSION=4.1.0 .
```

Run docker container:

```bash
docker container run \
-it --entrypoint /bin/bash \
-it --rm --entrypoint /bin/bash \
--mount type=bind,source="$(pwd)",target="/contract" \
paritytech/contracts-verifiable:0.0.1
paritytech/contracts-verifiable:0.0.1-local
```
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct BuildCommand {
/// Performs extra linting checks for ink! specific issues during the build process.
///
/// Basic clippy lints are deemed important and run anyways.
#[clap(long, conflicts_with = "verifiable")]
#[clap(long)]
lint: bool,
/// Which build artifacts to generate.
///
Expand Down

0 comments on commit 255d0ef

Please sign in to comment.