Skip to content

Commit

Permalink
Merge pull request #9 from mattsse/matt/windows-support
Browse files Browse the repository at this point in the history
  • Loading branch information
roynalnaruto authored Dec 13, 2021
2 parents 81689c6 + c480fd3 commit 71b4775
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,57 @@ jobs:
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo test --verbose

windows-build:
runs-on: windows-latest
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env:
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
strategy:
max-parallel: 2
fail-fast: false
matrix:
target: [
i686-pc-windows-gnu,
i686-pc-windows-msvc,
x86_64-pc-windows-gnu,
x86_64-pc-windows-msvc,
]
cfg_release_channel: [nightly]

steps:
- name: checkout
uses: actions/checkout@v2

# Run build
- name: Install Rustup using win.rustup.rs
run: |
# disable download progress bar
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
del rustup-init.exe
rustup target add ${{ matrix.target }}
shell: powershell

- name: Add mingw32 to path for i686-gnu
run: |
echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH
if: matrix.target == 'i686-pc-windows-gnu' && matrix.channel == 'nightly'
shell: bash

- name: Add mingw64 to path for x86_64-gnu
run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly'
shell: bash

- name: build
run: |
rustc -Vv
cargo -V
cargo build
shell: cmd

- name: test
run: cargo test
shell: cmd
31 changes: 29 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use sha2::Digest;

use std::{
ffi::OsString,
fs::{self, Permissions},
fs,
io::{Cursor, Write},
os::unix::fs::PermissionsExt,
path::PathBuf,
};

/// Use permissions extensions on unix
#[cfg(target_family = "unix")]
use std::{fs::Permissions, os::unix::fs::PermissionsExt};

mod error;
pub use error::SolcVmError;

Expand Down Expand Up @@ -133,7 +136,10 @@ pub async fn install(version: &Version) -> Result<(), SolcVmError> {
setup_version(version.to_string().as_str())?;
let fname = version_path(version.to_string().as_str()).join(&format!("solc-{}", version));
let f = fs::File::create(fname)?;

#[cfg(target_family = "unix")]
f.set_permissions(Permissions::from_mode(0o777))?;

f
};
let mut content = Cursor::new(binbytes);
Expand Down Expand Up @@ -176,6 +182,8 @@ fn setup_version(version: &str) -> Result<(), SolcVmError> {
mod tests {
use crate::releases::all_releases;
use rand::seq::SliceRandom;
use std::process::Command;
use std::process::Stdio;

use super::*;

Expand All @@ -190,4 +198,23 @@ mod tests {
let rand_version = versions.choose(&mut rand::thread_rng()).unwrap();
assert!(install(&rand_version).await.is_ok());
}

#[tokio::test]
async fn test_version() {
let version = "0.8.10".parse().unwrap();
install(&version).await.unwrap();
let solc_path =
version_path(version.to_string().as_str()).join(&format!("solc-{}", version));
let output = Command::new(&solc_path)
.arg("--version")
.stdin(Stdio::piped())
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.output()
.unwrap();

assert!(String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.8.10"));
}
}
9 changes: 9 additions & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::env;
pub enum Platform {
LinuxAmd64,
MacOsAmd64,
WindowsAmd64,
Unsupported,
}

Expand All @@ -13,6 +14,7 @@ impl ToString for Platform {
match self {
Platform::LinuxAmd64 => "linux-amd64".to_string(),
Platform::MacOsAmd64 => "macosx-amd64".to_string(),
Platform::WindowsAmd64 => "windows-amd64".to_string(),
Platform::Unsupported => "Unsupported-platform".to_string(),
}
}
Expand All @@ -23,6 +25,7 @@ pub fn platform() -> Platform {
match env::consts::OS {
"linux" => Platform::LinuxAmd64,
"macos" => Platform::MacOsAmd64,
"windows" => Platform::WindowsAmd64,
_ => Platform::Unsupported,
}
}
Expand All @@ -42,4 +45,10 @@ mod tests {
fn get_platform() {
assert_eq!(platform(), Platform::MacOsAmd64);
}

#[test]
#[cfg(target_os = "windows")]
fn get_platform() {
assert_eq!(platform(), Platform::WindowsAmd64);
}
}

0 comments on commit 71b4775

Please sign in to comment.