More reliable method of detecting x86-64
This commit is contained in:
parent
44852b8fad
commit
efeb394826
|
@ -135,7 +135,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gmod"
|
||||
version = "10.0.0"
|
||||
version = "10.1.0"
|
||||
dependencies = [
|
||||
"cfg_table 1.0.0",
|
||||
"cstr",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "gmod"
|
||||
version = "10.0.0"
|
||||
version = "10.1.0"
|
||||
authors = ["William Venner <william@venner.io>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
|
|
@ -39,16 +39,37 @@ pub mod userdata;
|
|||
pub mod net;
|
||||
|
||||
/// Returns whether this client is running the x86-64 branch
|
||||
///
|
||||
/// Current implementation checks the contents of the bin/ directory, so this is a blocking operation and requires syscalls, use sparingly
|
||||
pub fn is_x86_64() -> bool {
|
||||
#[cfg(target_pointer_width = "64")] {
|
||||
// 64-bit can only be x86-64
|
||||
true
|
||||
}
|
||||
#[cfg(target_pointer_width = "32")] {
|
||||
lazy_static::lazy_static! {
|
||||
static ref IS_X86_64: bool = {
|
||||
use std::path::PathBuf;
|
||||
|
||||
// Check LuaJIT version
|
||||
unsafe {
|
||||
let (lib, _) = lua::LuaShared::find_lua_shared();
|
||||
if lib.get::<()>(b"luaJIT_version_2_0_4\0").is_ok() {
|
||||
false
|
||||
} else if lib.get::<()>(b"luaJIT_version_2_1_0_beta3\0").is_ok() {
|
||||
true
|
||||
} else {
|
||||
// Check bin folder
|
||||
#[cfg(target_os = "linux")] {
|
||||
PathBuf::from("bin/linux64").is_dir()
|
||||
}
|
||||
#[cfg(target_os = "windows")] {
|
||||
PathBuf::from("bin/win64").is_dir()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
*IS_X86_64
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens & returns a shared library loaded by Garry's Mod using the raw path to the module.
|
||||
|
|
|
@ -249,27 +249,27 @@ impl LuaShared {
|
|||
}
|
||||
|
||||
#[cfg(all(target_os = "windows", target_pointer_width = "64"))]
|
||||
unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
pub unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
find_library!("bin/win64/lua_shared.dll")
|
||||
.expect("Failed to load lua_shared.dll")
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "windows", target_pointer_width = "32"))]
|
||||
unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
pub unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
find_library!("garrysmod/bin/lua_shared.dll")
|
||||
.or_else(|_| find_library!("bin/lua_shared.dll"))
|
||||
.expect("Failed to load lua_shared.dll")
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", target_pointer_width = "32"))]
|
||||
unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
pub unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
find_library!("garrysmod/bin/lua_shared_srv.so")
|
||||
.or_else(|_| find_library!("bin/linux32/lua_shared.so"))
|
||||
.expect("Failed to find lua_shared.so or lua_shared_srv.so")
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", target_pointer_width = "64"))]
|
||||
unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
pub unsafe fn find_lua_shared() -> (Library, &'static str) {
|
||||
find_library!("bin/linux64/lua_shared.so")
|
||||
.expect("Failed to find lua_shared.so")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue