diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2e39e0622..32c936669 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 @@ -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 @@ -68,4 +67,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..03958fd65 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 @@ -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 7bb4d951e..1a810e0b1 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: @@ -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 @@ -91,7 +93,7 @@ fmt: stage: check <<: *docker-env script: - - cargo fmt --verbose --all -- --check + - cargo +nightly fmt --verbose --all -- --check clippy: stage: check @@ -107,20 +109,17 @@ 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 - # 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 - - 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. @@ -155,8 +154,8 @@ test-new-project-template: - cargo check --verbose - cargo test --verbose --all - - cargo fmt --verbose --all -- --check - - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings -A clippy::let-unit-value; + - cargo +nightly fmt --verbose --all -- --check + - 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 @@ -166,15 +165,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 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/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 +``` 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..08ec138b3 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, @@ -38,18 +39,25 @@ 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); match meta.channel { - Channel::Dev | Channel::Nightly => Ok(()), - Channel::Stable | Channel::Beta => { + Channel::Stable if meta.semver >= min_version => Ok(()), + Channel::Stable => { anyhow::bail!( - "cargo-contract cannot build using the {:?} channel. \ - Switch to nightly. \ - See https://github.com/paritytech/cargo-contract#build-requires-the-nightly-toolchain", + "The minimum Rust version is {}. You are using {}.", + min_version, + meta.semver + ) + } + _ => { + anyhow::bail!( + "Using the {:?} channel is not supported. \ + Contracts should be built 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 {