Skip to content

Commit

Permalink
Build contracts and dylint driver with stable (#698)
Browse files Browse the repository at this point in the history
* Build contracts and dylint driver with stable

* Make CI use stable

* Set toolchain to stable and install components

* Fmt still needs nightly

* Remove useless before_script

* Allow clippy::extra-unused-lifetimes

* Fix UI tests to specific toolchain version

* Update src/util.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Updated docs

* Fix syntax err

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
  • Loading branch information
athei and HCastano authored Aug 23, 2022
1 parent 50f8045 commit cc69f67
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
platform:
- macos-latest
toolchain:
- nightly
- stable
runs-on: ${{ matrix.platform }}
env:
RUST_BACKTRACE: full
Expand All @@ -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
Expand All @@ -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
cargo run -- contract test --manifest-path=foobar/Cargo.toml
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
platform:
- windows-latest
toolchain:
- nightly
- stable
runs-on: ${{ matrix.platform }}
env:
RUST_BACKTRACE: full
Expand All @@ -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
Expand Down
29 changes: 13 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -91,7 +93,7 @@ fmt:
stage: check
<<: *docker-env
script:
- cargo fmt --verbose --all -- --check
- cargo +nightly fmt --verbose --all -- --check

clippy:
stage: check
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions ink_linting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
--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
```
6 changes: 0 additions & 6 deletions ink_linting/rust-toolchain.toml

This file was deleted.

25 changes: 18 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use anyhow::{
};
use heck::ToUpperCamelCase as _;
use rustc_version::Channel;
use semver::Version;
use std::{
ffi::OsStr,
fs,
Expand All @@ -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(),
);
)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cc69f67

Please sign in to comment.