Skip to content

Commit

Permalink
fix: set OS_TYPE,ARCH_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 11, 2024
1 parent 7b6a78b commit 9851ae2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env::consts::{ARCH, OS};
use std::path::PathBuf;
use std::sync::{Mutex, MutexGuard};

Expand Down Expand Up @@ -27,3 +28,18 @@ impl Config {
config
}
}

pub fn os() -> String {
match OS {
"macos" => "darwin".to_string(),
os => os.to_string(),
}
}

pub fn arch() -> String {
match ARCH {
"aarch64" => "arm64".to_string(),
"x86_64" => "amd64".to_string(),
arch => arch.to_string(),
}
}
4 changes: 3 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::Result;
use crate::metadata::Metadata;
use crate::runtime::Runtime;
use crate::sdk_info::SdkInfo;
use crate::{error, lua_mod, VfoxError};
use crate::{config, error, lua_mod, VfoxError};

#[derive(Debug)]
pub struct Plugin {
Expand Down Expand Up @@ -125,6 +125,8 @@ impl Plugin {
let metadata = self.load_metadata()?;
self.set_global("PLUGIN", metadata.clone())?;
self.set_global("RUNTIME", Runtime::get())?;
self.set_global("OS_TYPE", config::os())?;
self.set_global("ARCH_TYPE", config::arch())?;

let mut metadata: Metadata = metadata.try_into()?;

Expand Down
17 changes: 1 addition & 16 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::{arch, os};
use mlua::{UserData, UserDataFields};
use std::env::consts::{ARCH, OS};
use std::sync::{Mutex, MutexGuard};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -54,18 +54,3 @@ impl UserData for Runtime {
// fields.add_field_method_get("version", |_, t| Ok(t.version.clone()));
}
}

fn os() -> String {
match OS {
"macos" => "darwin".to_string(),
os => os.to_string(),
}
}

fn arch() -> String {
match ARCH {
"aarch64" => "arm64".to_string(),
"x86_64" => "amd64".to_string(),
arch => arch.to_string(),
}
}

0 comments on commit 9851ae2

Please sign in to comment.