From 25dc760bd3a7497ecf39c271358c8d5b156b71bb Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:11:53 +0100 Subject: [PATCH 01/11] Include `ink_linting` folder in releases --- .gitlab-ci.yml | 1 + Cargo.toml | 5 ++- build.rs | 43 ++++++++++++++----------- ink_linting/{Cargo.toml => _Cargo.toml} | 0 4 files changed, 30 insertions(+), 19 deletions(-) rename ink_linting/{Cargo.toml => _Cargo.toml} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0129a27b..91c88b8d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,6 +87,7 @@ test-dylint: <<: *docker-env script: - cd ink_linting/ + - mv _Cargo.toml Cargo.toml # Installing these components here is necessary because # `ink_linting/` has a fixed `rust-toolchain` file. diff --git a/Cargo.toml b/Cargo.toml index 52a82c70..584f8eb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,10 @@ homepage = "https://www.parity.io/" description = "Setup and deployment tool for developing Wasm based smart contracts via ink!" keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] categories = ["command-line-utilities", "development-tools::build-utils", "development-tools::cargo-plugins"] -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "templates", "src/**/*.scale"] +include = [ + "Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "templates", "src/**/*.scale", + "ink_linting", "!ink_linting/target/", "!ink_linting/ui/" +] [dependencies] env_logger = "0.9.0" diff --git a/build.rs b/build.rs index f7085a3b..a47a49d1 100644 --- a/build.rs +++ b/build.rs @@ -122,24 +122,26 @@ fn build_and_zip_dylint_driver( out_dir: PathBuf, dylint_driver_dst_file: PathBuf, ) -> Result<()> { - let mut ink_dylint_driver_dir = manifest_dir.join("ink_linting"); - - // The following condition acocunts for the case when `cargo package` or - // `cargo publish` is used. In that case the `CARGO_MANIFEST_DIR` is actually - // of the form `cargo-contract/target/package/cargo-contract-0.18.0/`. - // But since the `ink_linting/` folder is not part of the `cargo-contract` - // project it would not be found in this `CARGO_MANIFEST_DIR`. - if !ink_dylint_driver_dir.exists() { - println!( - "Folder `ink_linting` not found at {:?}", - ink_dylint_driver_dir - ); - ink_dylint_driver_dir = manifest_dir.join("../../../ink_linting/"); - println!( - "Added a relative path to reference the `ink_linting` folder at: {:?}", - ink_dylint_driver_dir - ); - } + let ink_dylint_driver_dir = manifest_dir.join("ink_linting"); + + // The `ink_linting/Cargo.toml` file is named `_Cargo.toml` in the repository. + // This is because we need to have the `ink_linting` folder part of the release, + // so that when somebody installs `cargo-contract` the `ink_linting` crate is + // build locally as part of that installation process. + // But if the file were named `Cargo.toml` then `cargo publish` would ignore + // the whole `ink_linting` folder and we wouldn't be able to specify the folder + // in the `cargo-contract/Cargo.toml` section of `[include]`. + // + // This is intended behavior: + // + // > Regardless of whether exclude or include is specified, the following files are always excluded: + // > * Any sub-packages will be skipped (any subdirectory that contains a Cargo.toml file). + // + // (from https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields) + std::fs::rename( + ink_dylint_driver_dir.join("_Cargo.toml"), + ink_dylint_driver_dir.join("Cargo.toml"), + ); let mut cmd = Command::new("cargo"); @@ -183,6 +185,11 @@ fn build_and_zip_dylint_driver( .spawn()?; let output = child.wait_with_output()?; + std::fs::rename( + ink_dylint_driver_dir.join("Cargo.toml"), + ink_dylint_driver_dir.join("_Cargo.toml"), + ); + if !output.status.success() { anyhow::bail!( "`{:?}` failed with exit code: {:?}", diff --git a/ink_linting/Cargo.toml b/ink_linting/_Cargo.toml similarity index 100% rename from ink_linting/Cargo.toml rename to ink_linting/_Cargo.toml -- GitLab From 6bfb9aa0b9349cc861bc11178ae61d0e336f6832 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:18:25 +0100 Subject: [PATCH 02/11] Add CI stage to test if publishing/installing works --- .gitlab-ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 91c88b8d..a505bd7d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -132,6 +132,24 @@ test-new-project-template: - cargo fmt --verbose --all -- --check - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings; +test-publish-install: + stage: test + <<: *docker-env + before_script: + - 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: + - cargo publish --registry estuary + - cargo install --registry estuary cargo-contract --index http://0.0.0.0:7878/git/index + + - cargo run -- contract new new_project + - echo "[workspace]" >> new_project/Cargo.toml + - cargo run --all-features -- contract check --manifest-path new_project/Cargo.toml + + #### stage: build (default features) build: -- GitLab From da134108a62ebb0e6ff38f613f138d3a7063c5f3 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:19:24 +0100 Subject: [PATCH 03/11] Revert me: Skip most CI stages --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a505bd7d..638fcef4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -68,13 +68,13 @@ workflow: #### stage: check # be aware that the used image has cargo-contract installed -fmt: +.fmt: stage: check <<: *docker-env script: - cargo fmt --verbose --all -- --check -clippy: +.clippy: stage: check <<: *docker-env script: @@ -82,7 +82,7 @@ clippy: #### stage: test (all features) -test-dylint: +.test-dylint: stage: test <<: *docker-env script: @@ -106,13 +106,13 @@ test-dylint: - cargo test --verbose --all-features -test: +.test: stage: test <<: *docker-env script: - cargo test --verbose --workspace --all-features -test-new-project-template: +.test-new-project-template: stage: test <<: *docker-env script: @@ -152,7 +152,7 @@ test-publish-install: #### stage: build (default features) -build: +.build: stage: build <<: *docker-env <<: *collect-artifacts -- GitLab From 73dd4d99f9c36ff0dfc32f93f904d5f93703ceb8 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:29:21 +0100 Subject: [PATCH 04/11] Remove unneeded `--registry` --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 638fcef4..9cf5204c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -143,7 +143,7 @@ test-publish-install: - echo 0000 | cargo login --registry estuary script: - cargo publish --registry estuary - - cargo install --registry estuary cargo-contract --index http://0.0.0.0:7878/git/index + - cargo install cargo-contract --index http://0.0.0.0:7878/git/index - cargo run -- contract new new_project - echo "[workspace]" >> new_project/Cargo.toml -- GitLab From 6c96456a7dd045a94261cc362c2d653576dfe860 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:39:54 +0100 Subject: [PATCH 05/11] Revert "Revert me: Skip most CI stages" This reverts commit da134108a62ebb0e6ff38f613f138d3a7063c5f3. --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9cf5204c..dc40e841 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -68,13 +68,13 @@ workflow: #### stage: check # be aware that the used image has cargo-contract installed -.fmt: +fmt: stage: check <<: *docker-env script: - cargo fmt --verbose --all -- --check -.clippy: +clippy: stage: check <<: *docker-env script: @@ -82,7 +82,7 @@ workflow: #### stage: test (all features) -.test-dylint: +test-dylint: stage: test <<: *docker-env script: @@ -106,13 +106,13 @@ workflow: - cargo test --verbose --all-features -.test: +test: stage: test <<: *docker-env script: - cargo test --verbose --workspace --all-features -.test-new-project-template: +test-new-project-template: stage: test <<: *docker-env script: @@ -152,7 +152,7 @@ test-publish-install: #### stage: build (default features) -.build: +build: stage: build <<: *docker-env <<: *collect-artifacts -- GitLab From 68384786d1929b747768dd252da54eb3330393ec Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:43:13 +0100 Subject: [PATCH 06/11] Make CI code clearer --- .gitlab-ci.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc40e841..46c999c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -132,12 +132,16 @@ test-new-project-template: - cargo fmt --verbose --all -- --check - cargo clippy --verbose --manifest-path Cargo.toml -- -D warnings; -test-publish-install: +# With the introduction of `ink_linting` in `build.rs` the installation process +# is more elaborate now and as part of it the `ink_linting` crate is built locally. +# We introduced this CI job to make sure that publishing to a registry and installing +# from it will work correctly. +test-registry-publish-install: stage: test <<: *docker-env before_script: - - mkdir -p estuary/crates/ estuary/indices/ - - estuary --base-url=http://0.0.0.0:7878 --crate-dir ./estuary/crates --index-dir ./estuary/indices & + - 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 @@ -145,6 +149,7 @@ test-publish-install: - cargo publish --registry estuary - cargo install cargo-contract --index http://0.0.0.0:7878/git/index + # Simple smoke testing to check if basic `check` functionality works. - cargo run -- contract new new_project - echo "[workspace]" >> new_project/Cargo.toml - cargo run --all-features -- contract check --manifest-path new_project/Cargo.toml -- GitLab From 4e598dddd030d556dd4c7d503eb3fc40c4e23967 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:43:55 +0100 Subject: [PATCH 07/11] Remove superfluous newline --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 46c999c1..172d1753 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -154,7 +154,6 @@ test-registry-publish-install: - echo "[workspace]" >> new_project/Cargo.toml - cargo run --all-features -- contract check --manifest-path new_project/Cargo.toml - #### stage: build (default features) build: -- GitLab From 3ce0b29fbee3b5c0066d42e2b1b02a4e91a18be6 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 05:48:12 +0100 Subject: [PATCH 08/11] Improve comments --- Cargo.toml | 2 ++ build.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 584f8eb4..b200d895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,8 @@ keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] categories = ["command-line-utilities", "development-tools::build-utils", "development-tools::cargo-plugins"] include = [ "Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "templates", "src/**/*.scale", + # We need to include `ink_linting` in the releases, so that the dylint driver which + # is contained in that crate is build locally as part of the installation. "ink_linting", "!ink_linting/target/", "!ink_linting/ui/" ] diff --git a/build.rs b/build.rs index a47a49d1..33b644db 100644 --- a/build.rs +++ b/build.rs @@ -180,16 +180,19 @@ fn build_and_zip_dylint_driver( println!("Invoking cargo: {:?}", cmd); let child = cmd - // capture the stdout to return from this function as bytes + // Capture the stdout to return from this function as bytes .stdout(std::process::Stdio::piped()) - .spawn()?; - let output = child.wait_with_output()?; + .spawn(); + // We need to name back to the original `_Cargo.toml` name, otherwise `cargo publish` + // would fail with `Source directory was modified by build.rs during cargo publish`. std::fs::rename( ink_dylint_driver_dir.join("Cargo.toml"), ink_dylint_driver_dir.join("_Cargo.toml"), ); + let output = child?.wait_with_output()?; + if !output.status.success() { anyhow::bail!( "`{:?}` failed with exit code: {:?}", -- GitLab From b262c47590cae3788e4af55fd06efe708748c350 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 06:23:11 +0100 Subject: [PATCH 09/11] Refactor `build.rs` --- build.rs | 79 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/build.rs b/build.rs index 33b644db..23def952 100644 --- a/build.rs +++ b/build.rs @@ -68,9 +68,43 @@ fn zip_template_and_build_dylint_driver(manifest_dir: PathBuf, out_dir: PathBuf) // `libink_linting@nightly-2021-11-04-x86_64-unknown-linux-gnu.so`. This file is obtained // by building the crate in `ink_linting/`. let dylint_driver_dst_file = out_dir.join("ink-dylint-driver.zip"); - build_and_zip_dylint_driver(manifest_dir, out_dir, dylint_driver_dst_file)?; - Ok(()) + let ink_dylint_driver_dir = manifest_dir.join("ink_linting"); + + // The `ink_linting/Cargo.toml` file is named `_Cargo.toml` in the repository. + // This is because we need to have the `ink_linting` folder part of the release, + // so that when somebody installs `cargo-contract` the `ink_linting` crate is + // build locally as part of that installation process. + // But if the file were named `Cargo.toml` then `cargo publish` would ignore + // the whole `ink_linting` folder and we wouldn't be able to specify the folder + // in the `cargo-contract/Cargo.toml` section of `[include]`. + // + // This is intended behavior: + // + // > Regardless of whether exclude or include is specified, the following files are always excluded: + // > * Any sub-packages will be skipped (any subdirectory that contains a Cargo.toml file). + // + // (from https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields) + std::fs::rename( + ink_dylint_driver_dir.join("_Cargo.toml"), + ink_dylint_driver_dir.join("Cargo.toml"), + )?; + + let res = build_and_zip_dylint_driver( + ink_dylint_driver_dir.clone(), + out_dir, + dylint_driver_dst_file, + ); + + // After the build process of `ink_linting` happened we need to name back to the original + // `_Cargo.toml` name, otherwise the directory would be "dirty" and `cargo publish` would + // fail with `Source directory was modified by build.rs during cargo publish`. + std::fs::rename( + ink_dylint_driver_dir.join("Cargo.toml"), + ink_dylint_driver_dir.join("_Cargo.toml"), + )?; + + res } /// Creates a zip archive `template.zip` of the `new` project template in `out_dir`. @@ -94,11 +128,7 @@ fn zip_template(manifest_dir: &Path, out_dir: &Path) -> Result<()> { /// Builds the crate in `ink_linting/`. This crate contains the `dylint` driver with ink! specific /// linting rules. #[cfg(feature = "cargo-clippy")] -fn build_and_zip_dylint_driver( - _manifest_dir: PathBuf, - _out_dir: PathBuf, - dylint_driver_dst_file: PathBuf, -) -> Result<()> { +fn build_and_zip_dylint_driver(_out_dir: PathBuf, dylint_driver_dst_file: PathBuf) -> Result<()> { // For `clippy` runs it is not necessary to build the `dylint` driver. // Furthermore the fixed Rust nightly specified in `ink_linting/rust-toolchain` // contains a bug that results in an `error[E0786]: found invalid metadata files` ICE. @@ -118,31 +148,10 @@ fn build_and_zip_dylint_driver( /// linting rules. #[cfg(not(feature = "cargo-clippy"))] fn build_and_zip_dylint_driver( - manifest_dir: PathBuf, + ink_dylint_driver_dir: PathBuf, out_dir: PathBuf, dylint_driver_dst_file: PathBuf, ) -> Result<()> { - let ink_dylint_driver_dir = manifest_dir.join("ink_linting"); - - // The `ink_linting/Cargo.toml` file is named `_Cargo.toml` in the repository. - // This is because we need to have the `ink_linting` folder part of the release, - // so that when somebody installs `cargo-contract` the `ink_linting` crate is - // build locally as part of that installation process. - // But if the file were named `Cargo.toml` then `cargo publish` would ignore - // the whole `ink_linting` folder and we wouldn't be able to specify the folder - // in the `cargo-contract/Cargo.toml` section of `[include]`. - // - // This is intended behavior: - // - // > Regardless of whether exclude or include is specified, the following files are always excluded: - // > * Any sub-packages will be skipped (any subdirectory that contains a Cargo.toml file). - // - // (from https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields) - std::fs::rename( - ink_dylint_driver_dir.join("_Cargo.toml"), - ink_dylint_driver_dir.join("Cargo.toml"), - ); - let mut cmd = Command::new("cargo"); let manifest_arg = format!( @@ -182,16 +191,8 @@ fn build_and_zip_dylint_driver( let child = cmd // Capture the stdout to return from this function as bytes .stdout(std::process::Stdio::piped()) - .spawn(); - - // We need to name back to the original `_Cargo.toml` name, otherwise `cargo publish` - // would fail with `Source directory was modified by build.rs during cargo publish`. - std::fs::rename( - ink_dylint_driver_dir.join("Cargo.toml"), - ink_dylint_driver_dir.join("_Cargo.toml"), - ); - - let output = child?.wait_with_output()?; + .spawn()?; + let output = child.wait_with_output()?; if !output.status.success() { anyhow::bail!( -- GitLab From 132e207612a8cb80917dfdfcb8c65ad6b19eea46 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 06:25:17 +0100 Subject: [PATCH 10/11] Add comment --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 172d1753..e04655be 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -140,6 +140,7 @@ test-registry-publish-install: stage: test <<: *docker-env before_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 -- GitLab From ef0e4a9c2b79e6d35c1f93cd938f28089d81231d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 15 Mar 2022 06:26:13 +0100 Subject: [PATCH 11/11] Add missing argument --- build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 23def952..23b08711 100644 --- a/build.rs +++ b/build.rs @@ -128,7 +128,11 @@ fn zip_template(manifest_dir: &Path, out_dir: &Path) -> Result<()> { /// Builds the crate in `ink_linting/`. This crate contains the `dylint` driver with ink! specific /// linting rules. #[cfg(feature = "cargo-clippy")] -fn build_and_zip_dylint_driver(_out_dir: PathBuf, dylint_driver_dst_file: PathBuf) -> Result<()> { +fn build_and_zip_dylint_driver( + _ink_dylint_driver_dir: PathBuf, + _out_dir: PathBuf, + dylint_driver_dst_file: PathBuf, +) -> Result<()> { // For `clippy` runs it is not necessary to build the `dylint` driver. // Furthermore the fixed Rust nightly specified in `ink_linting/rust-toolchain` // contains a bug that results in an `error[E0786]: found invalid metadata files` ICE. -- GitLab