Skip to content

Commit

Permalink
Add CI for Windows (#261)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Michael Müller and TriplEight authored Apr 21, 2021
1 parent 7ecf8a3 commit 6774f34
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]

- 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -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");
{
Expand Down Expand Up @@ -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| {
Expand All @@ -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| {
Expand All @@ -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| {
Expand All @@ -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| {
Expand Down
2 changes: 2 additions & 0 deletions src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6774f34

Please sign in to comment.