Skip to content

Commit

Permalink
fix: Fix system parsing from WASM.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 1, 2023
1 parent 5807d85 commit 8cf75a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions crates/pdk-api/src/host_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ json_struct!(
/// Environment variables to pass to the command.
pub env_vars: HashMap<String, String>,

/// Mark the command as executable before executing.
#[doc(hidden)]
pub set_executable: bool,

/// Stream the output instead of capturing it.
pub stream: bool,
}
Expand All @@ -54,8 +58,7 @@ impl ExecCommandInput {
ExecCommandInput {
command: command.as_ref().to_string(),
args: args.into_iter().map(|a| a.as_ref().to_owned()).collect(),
env_vars: HashMap::new(),
stream: false,
..ExecCommandInput::default()
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/system-env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl SystemArch {
}

impl Default for SystemArch {
#[cfg(target_arch = "wasm32")]
fn default() -> Self {
SystemArch::X64
}

#[cfg(not(target_arch = "wasm32"))]
fn default() -> Self {
SystemArch::from_env()
}
Expand Down Expand Up @@ -105,6 +111,12 @@ impl SystemOS {
}

impl Default for SystemOS {
#[cfg(target_arch = "wasm32")]
fn default() -> Self {
SystemOS::Linux
}

#[cfg(not(target_arch = "wasm32"))]
fn default() -> Self {
SystemOS::from_env()
}
Expand Down
1 change: 1 addition & 0 deletions crates/wasm-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ repository = "https://github.com/moonrepo/proto"
proto_pdk_api = { version = "0.7.3", path = "../pdk-api" }
extism = { workspace = true }
serde_json = { workspace = true }
starbase_utils = { workspace = true }
tracing = { workspace = true }
6 changes: 6 additions & 0 deletions crates/wasm-plugin/src/host_funcs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use extism::{CurrentPlugin, Error, Function, InternalExt, UserData, Val, ValType};
use proto_pdk_api::{ExecCommandInput, ExecCommandOutput, HostLogInput};
use starbase_utils::fs;
use std::env;
use std::path::PathBuf;
use std::process::Command;
Expand Down Expand Up @@ -74,6 +75,11 @@ fn exec_command(
"Executing command from plugin"
);

// This is temporary since WASI does not support updating file permissions yet!
if input.set_executable {
fs::update_perms(&input.command, None)?;
}

// let data = user_data.any().unwrap();
// let data = data.downcast_ref::<HostData>().unwrap();

Expand Down

0 comments on commit 8cf75a4

Please sign in to comment.