Skip to content

Commit

Permalink
Fix Linux issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RinLovesYou committed Nov 28, 2023
1 parent ffd821e commit 4b1a698
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[workspace]
members = ["Rust/MelonProxy", "Rust/MelonBootstrap", "Rust/MelonProxy-sys"]

[patch.crates-io]
nethost-sys = { git = "https://github.com/TrevTV/nethost-sys" }
resolver = "2"
3 changes: 3 additions & 0 deletions Rust/MelonBootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ndk = { version = "0.7", features = ["api-level-23"] }
ndk-sys = "0.4.1+23.1.7779620"
android_liblog-sys = "0.1"

[target.'cfg(target_os = "android")'.patch.crates-io]
nethost-sys = { git = "https://github.com/TrevTV/nethost-sys" }

[lib]
name = "melon_bootstrap"
crate-type = ["cdylib", "rlib"]
3 changes: 2 additions & 1 deletion Rust/MelonBootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ pub mod lib_android;
ctor::ctor
)]
#[no_mangle]
fn main() {
fn startup() {
init().unwrap_or_else(|e| internal_failure!("Failed to start MelonLoader: {}", e));
}

fn init() -> Result<(), Box<dyn Error>> {
logger::init()?;
debug!("starting up")?;

#[cfg(target_os = "windows")]
hooks::load_library::init()?;
Expand Down
6 changes: 3 additions & 3 deletions Rust/MelonProxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ readme = "../README.md"
thiserror = "1.0.48"
melon_proxy-sys = { path = "../MelonProxy-sys" }
utf16string = "0.2.0"
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_System", "Win32_System_LibraryLoader"] }
libloading = "0.8.0"
msgbox = "0.7.0"

#[target.'cfg(windows)'.dependencies]
[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_System", "Win32_System_LibraryLoader"] }

[target.'cfg(linux)'.dependencies]
[target.'cfg(target_os = "linux")'.dependencies]
ctor = "0.2.4"

[lib]
Expand Down
13 changes: 11 additions & 2 deletions Rust/MelonProxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
#![allow(clippy::inherent_to_string, clippy::type_complexity, improper_ctypes)]
#![cfg_attr(docsrs, feature(doc_cfg))]

use melon_proxy_sys::proxy;
#[cfg(target_os = "windows")]
pub use windows::Win32::Foundation::HINSTANCE;

#[cfg(target_os = "windows")]
pub mod proxy;
pub mod utils;
pub mod core;

/// this function will get called by our proxy macro. See MelonProxy-sys
#[proxy]
#[cfg_attr(
not(target_os = "windows"),
ctor::ctor
)]
#[cfg_attr(
target_os = "windows",
melon_proxy_sys::proxy
)]
#[allow(dead_code)]
fn main() {
core::init().unwrap_or_else(|e| {
internal_failure!("Failed to initialize MelonLoader: {}", e);
Expand Down
4 changes: 3 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def build(target: str):

dll_extension: str = "dll" if target == "win64" or target == "win32" else "so" if target == "linux" else "dylib"
bootstrap_name = "libmelon_bootstrap.{}".format(dll_extension)
version_name = "libversion.{}".format(dll_extension)

# ex: target/x86_64-pc-windows-msvc/release/
cargo_out_path = os.path.join("target", targets[target], "debug" if IsDebug else "release")
Expand Down Expand Up @@ -109,12 +110,13 @@ def build(target: str):

# Move Proxy/Bootstrap/Dobby/Dotnet to their right places.
if target == "win32" or target == "win64":
os.replace(os.path.join(cargo_out_path, "version.dll"), os.path.join(OutputPath, target, "version.dll"))
version_name = version_name.replace("lib", "")
bootstrap_name = bootstrap_name.replace("lib", "")

shutil.copy(os.path.join("BaseLibs", "dobby", "windows", "x86_64" if target == "win64" else "x86", "dobby.dll"), os.path.join(OutputPath, target, "dobby.dll"))

os.replace(os.path.join(cargo_out_path, bootstrap_name), os.path.join(bootstrap_destination, bootstrap_name))
os.replace(os.path.join(cargo_out_path, version_name), os.path.join(OutputPath, target, version_name))
shutil.copytree(DotnetPaths[target], os.path.join(bootstrap_destination, "dotnet"))

for arg in args:
Expand Down

0 comments on commit 4b1a698

Please sign in to comment.