diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000000000000000000000000000000000000..ab7b403383dfccfd255f803981186e416f48e52f --- /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 ca1ce2f450adc0354570cc7ebbd50dc2d5f622d3..1ab49a3af61f6a4930c168453734b59264f297bd 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) diff --git a/Cargo.lock b/Cargo.lock index 21204c1ef1f4088211d57509cc9ed1f05875fd89..2fcd996e676469da9d2c7e9dd96fa6758fe11bb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,27 +307,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" -[[package]] -name = "binaryen" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9b407f52d0b918c6ea41d7a328321496b315f61da99a309b375dfbbd04bc9a" -dependencies = [ - "binaryen-sys", -] - -[[package]] -name = "binaryen-sys" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86e9636d01b92f2df45dce29c35a9e3724687c1055bb4472fb4b829cc4a5a561" -dependencies = [ - "cc", - "cmake", - "heck", - "regex", -] - [[package]] name = "bitflags" version = "1.2.1" @@ -500,7 +479,6 @@ dependencies = [ "anyhow", "assert_matches", "async-std", - "binaryen", "blake2", "cargo_metadata", "colored", diff --git a/Cargo.toml b/Cargo.toml index ddcfbff60f9f1ac81668fb05401704614f1dc50f..da3e7c228fe360495fd1e1137a8bf1aa3fe75ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,6 @@ serde = { version = "1.0.125", default-features = false, features = ["derive"] } serde_json = "1.0.64" tempfile = "3.2.0" url = { version = "2.2.1", features = ["serde"] } -binaryen = { version = "0.12.0", optional = true } impl-serde = "0.3.1" regex = "1.4" diff --git a/src/cmd/build.rs b/src/cmd/build.rs index a0a19a76172331e10cfb89968ac0393111970f77..0e12b9546d1045d0b057b34832c9971d5d51e031 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"); { @@ -829,6 +833,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn incompatible_wasm_opt_version_must_be_detected_if_built_from_repo() { with_tmp_dir(|path| { @@ -849,6 +854,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn compatible_wasm_opt_version_must_be_detected_if_built_from_repo() { with_tmp_dir(|path| { @@ -865,6 +871,7 @@ mod tests_ci_only { }) } + #[cfg(unix)] #[test] fn incompatible_wasm_opt_version_must_be_detected_if_installed_as_package() { with_tmp_dir(|path| { @@ -885,6 +892,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 5a439926bb65c43cf82319afdc7212b45c1fb685..fc2a52ed25a1e947dab0d68b451a46dae016c340 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 7f242d2a0f1c7e8435beb4100dc3196971cc2024..733e8700ffa5bfd9d6a839dcf6cf1061d0a11450 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)