Skip to content

Commit

Permalink
Add funcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 6, 2023
1 parent 975ef98 commit 8595986
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 31 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

#### 🚀 Updates

- WASM API
- Added `is_musl` and `get_target_triple` helper functions.

#### ⚙️ Internal

- Now supports `.zst` (or `.zstd`) archive formats.

## 0.16.1

#### 🐞 Fixes
Expand Down
66 changes: 43 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ semver = "1.0.18"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
sha2 = "0.10.7"
starbase_archive = { version = "0.2.0", features = [
starbase_archive = { version = "0.2.1", features = [
"tar-gz",
"tar-xz",
"tar-zstd",
"zip",
"zip-deflate",
] }
starbase_sandbox = { version = "0.1.8" }
starbase_styles = "0.1.13"
starbase_utils = { version = "0.2.21", default-features = false, features = [
starbase_sandbox = { version = "0.1.9" }
starbase_styles = "0.1.14"
starbase_utils = { version = "0.2.22", default-features = false, features = [
"json",
"toml",
] }
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use regex::Regex;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sha2::{Digest, Sha256};
use starbase_archive::is_supported_archive_extension;
use starbase_utils::dirs::home_dir;
use starbase_utils::fs::{self, FsError};
use starbase_utils::json::{self, JsonError};
Expand Down Expand Up @@ -132,9 +133,8 @@ pub fn is_cache_enabled() -> bool {
}

pub fn is_archive_file<P: AsRef<Path>>(path: P) -> bool {
path.as_ref().extension().map_or(false, |ext| {
ext == "zip" || ext == "tar" || ext == "gz" || ext == "tgz" || ext == "xz" || ext == "txz"
})
dbg!(path.as_ref().extension());
is_supported_archive_extension(path.as_ref())
}

pub fn hash_file_contents<P: AsRef<Path>>(path: P) -> miette::Result<String> {
Expand Down
34 changes: 34 additions & 0 deletions crates/pdk/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,40 @@ pub fn check_supported_os_and_arch(
Ok(())
}

/// Detect whether the current OS is utilizing musl instead of gnu.
pub fn is_musl(env: &HostEnvironment) -> bool {
if !env.os.is_linux() {
return false;
}

unsafe {
match exec_command(Json(ExecCommandInput::pipe("ldd", ["--version"]))) {
Ok(res) => res.0.stdout.contains("musl"),
Err(_) => false,
}
}
}

/// Return a Rust target triple for the current host OS and architecture.
pub fn get_target_triple(env: &HostEnvironment, name: &str) -> Result<String, PluginError> {
match env.os {
HostOS::Linux => Ok(format!(
"{}-unknown-linux-{}",
env.arch.to_rust_arch(),
if is_musl(env) { "musl" } else { "gnu" }
)),
HostOS::MacOS => Ok(format!("{}-apple-darwin", env.arch.to_rust_arch())),
HostOS::Windows => Ok(format!("{}-pc-windows-msvc", env.arch.to_rust_arch())),
_ => {
return Err(PluginError::UnsupportedTarget {
tool: name.into(),
arch: env.arch.to_string(),
os: env.os.to_string(),
})
}
}
}

/// Get the active tool ID for the current WASM instance.
pub fn get_tool_id() -> String {
config::get("proto_tool_id").expect("Missing tool ID!")
Expand Down
2 changes: 1 addition & 1 deletion crates/warpgate/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn move_or_unpack_download(temp_file: &Path, dest_file: &Path) -> miette::Re
}

// Unpack archives to temp and move the wasm file
Some("tar" | "gz" | "xz" | "tgz" | "txz" | "zip") => {
Some("tar" | "gz" | "xz" | "tgz" | "txz" | "zst" | "zstd" | "zip") => {
let out_dir = temp_file.parent().unwrap().join("out");

Archiver::new(&out_dir, dest_file).unpack_from_ext()?;
Expand Down
2 changes: 2 additions & 0 deletions crates/warpgate/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ impl PluginLoader {
| asset.name.ends_with(".tgz")
| asset.name.ends_with(".tar.xz")
| asset.name.ends_with(".txz")
| asset.name.ends_with(".zst")
| asset.name.ends_with(".zstd")
| asset.name.ends_with(".zip")))
{
trace!(
Expand Down

0 comments on commit 8595986

Please sign in to comment.