diff --git a/build-image/Dockerfile b/build-image/Dockerfile index ec138f0bb..13239e41f 100644 --- a/build-image/Dockerfile +++ b/build-image/Dockerfile @@ -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 @@ -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" \ @@ -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 \ @@ -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 \ @@ -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}" ; \ @@ -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"] diff --git a/build-image/README.md b/build-image/README.md index 2719b02c2..a36359daa 100644 --- a/build-image/README.md +++ b/build-image/README.md @@ -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 ``` diff --git a/crates/cargo-contract/src/cmd/build.rs b/crates/cargo-contract/src/cmd/build.rs index 68b86d976..6222ec417 100644 --- a/crates/cargo-contract/src/cmd/build.rs +++ b/crates/cargo-contract/src/cmd/build.rs @@ -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. ///