Skip to content

Commit

Permalink
Verify Windows builds at CI (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MOZGIII authored Nov 11, 2022
1 parent a39150f commit e3b8679
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/detection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name = "humanode-distribution-detection"
version = "0.1.0"
edition = "2021"

[dependencies]
[target.'cfg(not(windows))'.dependencies]
libc = "0.2"
26 changes: 26 additions & 0 deletions crates/detection/src/implementation/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! The default implementation.

use std::ffi::{c_char, CStr};

use crate::Info;

/// Obtain the system information.
#[allow(unsafe_code)]
pub fn detect() -> std::io::Result<Info> {
let mut value = unsafe { std::mem::zeroed() };
if unsafe { libc::uname(&mut value) } != 0 {
return Err(std::io::Error::last_os_error());
}
Ok(Info {
platform: to_string(&value.sysname[..]),
arch: to_string(&value.machine[..]),
})
}

/// Assume a valid C string and copy it into a new Rust string with a lossy
/// UTF-8 conversion.
#[allow(unsafe_code)]
fn to_string(buf: &[c_char]) -> String {
let c_str = unsafe { CStr::from_ptr(buf.as_ptr()) };
c_str.to_string_lossy().into_owned()
}
15 changes: 15 additions & 0 deletions crates/detection/src/implementation/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Windows specific implementation.

use crate::Info;

/// Obtain the system information.
pub fn detect() -> std::io::Result<Info> {
#[cfg(target_arch = "x86_64")]
let arch = "x86_64";
#[cfg(target_arch = "aarch64")]
let arch = "aarch64";
Ok(Info {
platform: "Windows".into(),
arch: arch.into(),
})
}
26 changes: 8 additions & 18 deletions crates/detection/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//! The detection machinery.

use std::ffi::{c_char, CStr};
#[cfg(not(windows))]
#[path = "implementation/default.rs"]
mod implementation;

#[cfg(windows)]
#[path = "implementation/windows.rs"]
mod implementation;

/// Info about the system.
#[derive(Debug)]
Expand All @@ -12,22 +18,6 @@ pub struct Info {
}

/// Obtain the system information.
#[allow(unsafe_code)]
pub fn detect() -> std::io::Result<Info> {
let mut value = unsafe { std::mem::zeroed() };
if unsafe { libc::uname(&mut value) } != 0 {
return Err(std::io::Error::last_os_error());
}
Ok(Info {
platform: to_string(&value.sysname[..]),
arch: to_string(&value.machine[..]),
})
}

/// Assume a valid C string and copy it into a new Rust string with a lossy
/// UTF-8 conversion.
#[allow(unsafe_code)]
fn to_string(buf: &[c_char]) -> String {
let c_str = unsafe { CStr::from_ptr(buf.as_ptr()) };
c_str.to_string_lossy().into_owned()
self::implementation::detect()
}
5 changes: 3 additions & 2 deletions crates/installer/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Installation logic.

use std::{fs::Permissions, path::PathBuf};
use std::path::PathBuf;

use digest::Digest;
use humanode_distribution_schema::manifest::Binary;
Expand Down Expand Up @@ -190,7 +190,8 @@ pub async fn install(params: Params) -> Result<(), InstallationError> {
];
for executable in executables {
let path = base_path.join(executable.0);
use std::os::unix::prelude::PermissionsExt;

use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
tokio::fs::set_permissions(&path, Permissions::from_mode(0o755))
.await
.map_err(|error| InstallationError::SetFilePermissions { path, error })?;
Expand Down

0 comments on commit e3b8679

Please sign in to comment.