From 6774f341092da2f22c04998bf2fb8bd99961d90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 21 Apr 2021 16:53:32 +0200 Subject: [PATCH] Add CI for Windows (#261) * Add CI for building contract template under Windows * Disable `unix` specific tests * Remove build warnings due to `dead_code` with default features * Remove unused `binaryen` dependency * Ensure path is always canonicalized for comparison * Apply auto-formatting to yml * CI: optimize caching Co-authored-by: Denis P --- .github/workflows/windows.yml | 58 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 4 +++ src/cmd/build.rs | 10 +++++- src/workspace/manifest.rs | 2 ++ src/workspace/mod.rs | 14 +++++++-- 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 000000000..ab7b40338 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,58 @@ +name: continuous-intergration/windows + +on: + pull_request: + push: + branches: + - master + tags: + - v* + paths-ignore: + - 'README.md' + +jobs: + check: + name: build-contract-template + strategy: + matrix: + platform: + - windows-latest + toolchain: + - nightly + runs-on: ${{ matrix.platform }} + env: + RUST_BACKTRACE: full + steps: + + - uses: engineerd/configurator@v0.0.6 + with: + name: "wasm-opt.exe" + url: "https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-windows.tar.gz" + pathInArchive: "binaryen-version_101/bin/wasm-opt.exe" + + - name: Checkout sources & submodules + uses: actions/checkout@master + with: + fetch-depth: 1 + submodules: recursive + + - name: Install toolchain + id: toolchain + uses: actions-rs/toolchain@master + with: + profile: minimal + toolchain: ${{ matrix.toolchain }} + components: rust-src + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@v1.2.0 + + - name: Build contract template on ${{ matrix.platform }}-${{ matrix.toolchain }} + run: | + wasm-opt --version + cargo -vV + cargo run -- contract --version + cargo run -- contract new foobar + echo "[workspace]" >> foobar/Cargo.toml + cargo run -- contract build --manifest-path=foobar/Cargo.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e0d7330..52818626d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed `ERROR: The workspace root package should be a workspace member` when building a contract + under Windows - [#261](https://github.com/paritytech/cargo-contract/pull/261) + ### Removed - Remove support for `--binaryen-as-dependency` - [#251](https://github.com/paritytech/cargo-contract/pull/251) - Remove support for the deprecated `cargo contract generate-metadata` command - [#265](https://github.com/paritytech/cargo-contract/pull/265) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index c29f590a3..3e87c5afa 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -596,9 +596,10 @@ mod tests_ci_only { BuildArtifacts, ManifestPath, OptimizationPasses, UnstableFlags, UnstableOptions, Verbosity, VerbosityFlags, }; + #[cfg(unix)] + use std::os::unix::fs::PermissionsExt; use std::{ io::Write, - os::unix::fs::PermissionsExt, path::{Path, PathBuf}, }; @@ -623,6 +624,9 @@ mod tests_ci_only { /// "wasm-opt version `version`". /// /// Returns the path to this file. + /// + /// Currently works only on `unix`. + #[cfg(unix)] fn mock_wasm_opt_version(tmp_dir: &Path, version: &str) -> PathBuf { let path = tmp_dir.join("wasm-opt-mocked"); { @@ -820,6 +824,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn incompatible_wasm_opt_version_must_be_detected_if_built_from_repo() { with_tmp_dir(|path| { @@ -840,6 +845,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn compatible_wasm_opt_version_must_be_detected_if_built_from_repo() { with_tmp_dir(|path| { @@ -856,6 +862,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn incompatible_wasm_opt_version_must_be_detected_if_installed_as_package() { with_tmp_dir(|path| { @@ -876,6 +883,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn compatible_wasm_opt_version_must_be_detected_if_installed_as_package() { with_tmp_dir(|path| { diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 5a439926b..fc2a52ed2 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -177,6 +177,7 @@ impl Manifest { } /// Set `optimization-passes` in `[package.metadata.contract]` + #[cfg(feature = "test-ci-only")] #[cfg(test)] pub fn set_profile_optimization_passes( &mut self, @@ -205,6 +206,7 @@ impl Manifest { } /// Set the dependency version of `package` to `version`. + #[cfg(feature = "test-ci-only")] #[cfg(test)] pub fn set_dependency_version( &mut self, diff --git a/src/workspace/mod.rs b/src/workspace/mod.rs index 7f242d2a0..733e8700f 100644 --- a/src/workspace/mod.rs +++ b/src/workspace/mod.rs @@ -108,14 +108,24 @@ impl Workspace { .members .iter_mut() .find_map(|(_, (_, manifest))| { - if manifest.path().directory() == Some(package_path) { + // `package_path` is always absolute and canonicalized. Thus we need to + // canonicalize the manifest's directory path as well in order to compare + // both of them. + let manifest_path = manifest.path().directory()?; + let manifest_path = manifest_path + .canonicalize() + .unwrap_or_else(|_| panic!("Cannot canonicalize {}", manifest_path.display())); + if manifest_path == package_path { Some(manifest) } else { None } }) .ok_or_else(|| { - anyhow::anyhow!("The workspace root package should be a workspace member") + anyhow::anyhow!( + "Cannot find package with package path {} in workspace members", + package_path.display(), + ) })?; f(manifest)?; Ok(self)