From 2729fb1b80cdb4f6039bbe326fcf023ca3d96398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 09:19:45 +0200 Subject: [PATCH 01/10] Build contracts and dylint driver with stable --- build.rs | 3 +++ ink_linting/rust-toolchain.toml | 6 ------ src/util.rs | 21 ++++++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 ink_linting/rust-toolchain.toml diff --git a/build.rs b/build.rs index a7849aa34..c90317ecc 100644 --- a/build.rs +++ b/build.rs @@ -211,6 +211,9 @@ fn build_and_zip_dylint_driver( cmd.env_remove("RUSTUP_TOOLCHAIN"); cmd.env_remove("CARGO_TARGET_DIR"); + // Dylint drivers need unstable features. Allow them on a stable toolchain. + cmd.env("RUSTC_BOOTSTRAP", "1"); + println!( "Setting cargo working dir to '{}'", ink_dylint_driver_dir.display() diff --git a/ink_linting/rust-toolchain.toml b/ink_linting/rust-toolchain.toml deleted file mode 100644 index 6bcb1e0b7..000000000 --- a/ink_linting/rust-toolchain.toml +++ /dev/null @@ -1,6 +0,0 @@ -# This file corresponds to the `rust-toolchain` file used for the `dylint` examples here: -# https://github.com/trailofbits/dylint/tree/master/examples. - -[toolchain] -channel = "nightly-2022-06-30" -components = ["llvm-tools-preview", "rustc-dev"] \ No newline at end of file diff --git a/src/util.rs b/src/util.rs index 6d66978d2..16ab64e20 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,6 +21,7 @@ use anyhow::{ }; use heck::ToUpperCamelCase as _; use rustc_version::Channel; +use semver::Version; use std::{ ffi::OsStr, fs, @@ -41,15 +42,22 @@ use std::{ /// Check whether the current rust channel is valid: `nightly` is recommended. pub fn assert_channel() -> Result<()> { let meta = rustc_version::version_meta()?; + let min_version = Version::new(1, 63, 0); match meta.channel { - Channel::Dev | Channel::Nightly => Ok(()), - Channel::Stable | Channel::Beta => { + Channel::Stable if meta.semver >= min_version => Ok(()), + Channel::Stable => { + anyhow::bail!( + "Minimum Rust version is {}. You are using {}.", + min_version, + meta.semver + ) + } + _ => { anyhow::bail!( "cargo-contract cannot build using the {:?} channel. \ - Switch to nightly. \ - See https://github.com/paritytech/cargo-contract#build-requires-the-nightly-toolchain", + Contracts should be build using a stable toolchain.", format!("{:?}", meta.channel).to_lowercase(), - ); + ) } } } @@ -93,6 +101,9 @@ where cmd.current_dir(path); } + // Allow nightly features on a stable toolchain + cmd.env("RUSTC_BOOTSTRAP", "1"); + cmd.arg(command); cmd.args(args); match verbosity { From f5f6c19c63741c6d34efe66e5bb64bdc0127d065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 10:56:09 +0200 Subject: [PATCH 02/10] Make CI use stable --- .github/workflows/macos.yml | 4 ++-- .github/workflows/windows.yml | 2 +- .gitlab-ci.yml | 11 ++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2e39e0622..714de8d1b 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -19,7 +19,7 @@ jobs: platform: - macos-latest toolchain: - - nightly + - stable runs-on: ${{ matrix.platform }} env: RUST_BACKTRACE: full @@ -68,4 +68,4 @@ jobs: echo "[workspace]" >> foobar/Cargo.toml cargo run -- contract build --manifest-path=foobar/Cargo.toml cargo run -- contract check --manifest-path=foobar/Cargo.toml - cargo run -- contract test --manifest-path=foobar/Cargo.toml \ No newline at end of file + cargo run -- contract test --manifest-path=foobar/Cargo.toml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d95d564b6..1816f26e3 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -19,7 +19,7 @@ jobs: platform: - windows-latest toolchain: - - nightly + - stable runs-on: ${{ matrix.platform }} env: RUST_BACKTRACE: full diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7bb4d951e..adabb96ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ variables: RUSTY_CACHIER_SINGLE_BRANCH: master RUSTY_CACHIER_DONT_OPERATE_ON_MAIN_BRANCH: "true" # paritytech/contracts-ci-linux:production defaults to nightly toolchain, default rusty-cachier to it too - RUSTY_CACHIER_TOOLCHAIN: nightly + RUSTY_CACHIER_TOOLCHAIN: stable workflow: rules: @@ -111,14 +111,7 @@ test-dylint: - cd ink_linting/ - mv _Cargo.toml Cargo.toml - # Installing these components here is necessary because - # `ink_linting/` has a fixed `rust-toolchain` file. - # We can't move this line to the Docker container, since - # that would then make it impossible to upgrade the - # `ink_linting/rust-toolchain` file while still having - # this CI job succeed. - - rustup component add rustfmt clippy rust-src - + - export RUSTC_BOOTSTRAP=1 - cargo check --verbose - cargo fmt --verbose --all -- --check - cargo clippy --verbose -- -D warnings; From 6dd74869e1c4594a439e5eb1630e50cf17b708f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 11:17:17 +0200 Subject: [PATCH 03/10] Set toolchain to stable and install components --- .github/workflows/macos.yml | 3 +-- .github/workflows/windows.yml | 2 +- .gitlab-ci.yml | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 714de8d1b..32c936669 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -40,8 +40,7 @@ jobs: with: profile: minimal toolchain: ${{ matrix.toolchain }} - components: rust-src - override: true + components: rust-src, rustc-dev, llvm-tools-preview - name: Install cargo-dylint uses: baptiste0928/cargo-install@v1 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 1816f26e3..03958fd65 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -42,7 +42,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.toolchain }} - components: rust-src + components: rust-src, rustc-dev, llvm-tools-preview - name: Install cargo-dylint uses: baptiste0928/cargo-install@v1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index adabb96ba..472773b50 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,6 +49,8 @@ workflow: image: name: "${CI_IMAGE}" before_script: + - rustup default stable + - rustup component add rustfmt clippy rust-src rustc-dev llvm-tools-preview - cargo -vV - rustc -vV - rustup show From ada719cc22fd0b61365b0c448e291649110a28c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 11:19:21 +0200 Subject: [PATCH 04/10] Fmt still needs nightly --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 472773b50..e790c54ad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -93,7 +93,7 @@ fmt: stage: check <<: *docker-env script: - - cargo fmt --verbose --all -- --check + - cargo +nightly fmt --verbose --all -- --check clippy: stage: check @@ -115,7 +115,7 @@ test-dylint: - export RUSTC_BOOTSTRAP=1 - cargo check --verbose - - cargo fmt --verbose --all -- --check + - cargo +nightly fmt --verbose --all -- --check - cargo clippy --verbose -- -D warnings; # Needed until https://github.com/mozilla/sccache/issues/1000 is fixed. @@ -150,7 +150,7 @@ test-new-project-template: - cargo check --verbose - cargo test --verbose --all - - cargo fmt --verbose --all -- --check + - cargo +nightly fmt --verbose --all -- --check - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings -A clippy::let-unit-value; - rusty-cachier cache upload From e14379f257fef552ee3741df035d86e33fe56cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 11:33:58 +0200 Subject: [PATCH 05/10] Remove useless before_script --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e790c54ad..c784bc0d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -161,15 +161,13 @@ test-new-project-template: test-registry-publish-install: stage: test <<: *docker-env - before_script: - - !reference [.rusty-cachier, before_script] + script: # Set up a local registry. - mkdir -p ./estuary/crates/ ./estuary/indices/ - estuary --base-url=http://0.0.0.0:7878 --crate-dir ./estuary/crates/ --index-dir ./estuary/indices & - mkdir .cargo - echo -e '[registries]\nestuary = { index = "http://0.0.0.0:7878/git/index" }' > .cargo/config.toml - echo 0000 | cargo login --registry estuary - script: - rusty-cachier snapshot create - cargo publish --registry estuary - cargo install cargo-contract --index http://0.0.0.0:7878/git/index From a9b5f22df5b12fffeac1d9dccdcabfb0ef35c8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 11:37:13 +0200 Subject: [PATCH 06/10] Allow clippy::extra-unused-lifetimes --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c784bc0d1..2b0689515 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -151,7 +151,7 @@ test-new-project-template: - cargo check --verbose - cargo test --verbose --all - cargo +nightly fmt --verbose --all -- --check - - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings -A clippy::let-unit-value; + - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings -A clippy::let-unit-value -A clippy::extra-unused-lifetimes - rusty-cachier cache upload # With the introduction of `ink_linting` in `build.rs` the installation process From 4f5db94ba05a59c1a7ef7c0a00b8f1981465e26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 20 Aug 2022 12:25:05 +0200 Subject: [PATCH 07/10] Fix UI tests to specific toolchain version --- .gitlab-ci.yml | 6 +++++- ink_linting/README.md | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b0689515..1a810e0b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -109,11 +109,15 @@ test-dylint: stage: test <<: *docker-env script: + # We need to fix this test to a toolchain because of the UI tests + # We can't use stable here because the UI tests freak out if there are dots in the drivers file name + - rustup default nightly-2022-06-30 + - rustup component add rustfmt clippy rust-src rustc-dev llvm-tools-preview + - rusty-cachier snapshot create - cd ink_linting/ - mv _Cargo.toml Cargo.toml - - export RUSTC_BOOTSTRAP=1 - cargo check --verbose - cargo +nightly fmt --verbose --all -- --check - cargo clippy --verbose -- -D warnings; diff --git a/ink_linting/README.md b/ink_linting/README.md index 80279a661..7181d7e5e 100644 --- a/ink_linting/README.md +++ b/ink_linting/README.md @@ -13,5 +13,8 @@ cargo build --release # Run the linting on a contract. DYLINT_LIBRARY_PATH=$PWD/target/release cargo dylint contract_instantiated - --manifest-path ../ink/examples/erc20/Cargo.toml -``` \ No newline at end of file + --manifest-path ../ink/examples/erc20/Cargo.toml + +# The UI tests are written against a specific toolchain version. If you wish to run them locally: +cargo +nightly-2022-06-30 test +``` From 32ff7c4238f626309a25393b23eb94952e491039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 23 Aug 2022 11:24:00 +0200 Subject: [PATCH 08/10] Update src/util.rs Co-authored-by: Hernando Castano --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 16ab64e20..814e892da 100644 --- a/src/util.rs +++ b/src/util.rs @@ -55,7 +55,7 @@ pub fn assert_channel() -> Result<()> { _ => { anyhow::bail!( "cargo-contract cannot build using the {:?} channel. \ - Contracts should be build using a stable toolchain.", + Contracts should be build using a "stable" toolchain.", format!("{:?}", meta.channel).to_lowercase(), ) } From 850f7242e3e103405f1a75f1cc2e0b69ee3c9c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 23 Aug 2022 11:31:27 +0200 Subject: [PATCH 09/10] Updated docs --- src/util.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util.rs b/src/util.rs index 814e892da..f01e3e504 100644 --- a/src/util.rs +++ b/src/util.rs @@ -39,7 +39,7 @@ use std::{ process::Command, }; -/// Check whether the current rust channel is valid: `nightly` is recommended. +/// This makes sure we are building with a minimum `stable` toolchain version. pub fn assert_channel() -> Result<()> { let meta = rustc_version::version_meta()?; let min_version = Version::new(1, 63, 0); @@ -47,15 +47,15 @@ pub fn assert_channel() -> Result<()> { Channel::Stable if meta.semver >= min_version => Ok(()), Channel::Stable => { anyhow::bail!( - "Minimum Rust version is {}. You are using {}.", + "The minimum Rust version is {}. You are using {}.", min_version, meta.semver ) } _ => { anyhow::bail!( - "cargo-contract cannot build using the {:?} channel. \ - Contracts should be build using a "stable" toolchain.", + "Using the {:?} channel is not supported. \ + Contracts should be built using a "stable" toolchain.", format!("{:?}", meta.channel).to_lowercase(), ) } From 8bf2ad909762ccc1dc002c8a17565d5afbc655fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 23 Aug 2022 11:58:26 +0200 Subject: [PATCH 10/10] Fix syntax err --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index f01e3e504..08ec138b3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -55,7 +55,7 @@ pub fn assert_channel() -> Result<()> { _ => { anyhow::bail!( "Using the {:?} channel is not supported. \ - Contracts should be built using a "stable" toolchain.", + Contracts should be built using a \"stable\" toolchain.", format!("{:?}", meta.channel).to_lowercase(), ) }