From 409c7a0a173b8d7f3c773816fae618f4f39411aa Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 1 Jan 2022 18:24:59 -0500 Subject: [PATCH 1/4] Format via rustfmt --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9ab24b7..52cb43b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,19 +1,22 @@ extern crate libc; #[no_mangle] -extern "C" fn posix_memalign(memptr: *mut *mut libc::c_void, align: libc::size_t, size: libc::size_t) -> libc::c_int { +extern "C" fn posix_memalign( + memptr: *mut *mut libc::c_void, + align: libc::size_t, + size: libc::size_t, +) -> libc::c_int { unsafe { *memptr = libc::memalign(align, size); } - + 0 } - #[no_mangle] unsafe extern "C" fn realpath( - path: *const libc::c_char, - resolved_path: *mut libc::c_char + path: *const libc::c_char, + resolved_path: *mut libc::c_char, ) -> *mut libc::c_char { libc::memcpy(resolved_path as _, path as _, libc::strlen(path)); From dbfa80f9635a254ab673aeb2642b02289b1ac741 Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 1 Jan 2022 18:25:58 -0500 Subject: [PATCH 2/4] Removed staticlib crate type It's not needed, and could lead to issues (std might be duplicated if linked to other Rust code). --- Cargo.toml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 23b9282..fe76168 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,5 @@ version = "0.1.0" license = "MIT/Apache 2.0" edition = "2018" -[lib] -name = "linker_fix_3ds" -path = "src/lib.rs" -crate-type = ["staticlib", "lib"] - -[dependencies.libc] -git = "https://github.com/Meziu/libc.git" +[dependencies] +libc = { git = "https://github.com/Meziu/libc.git" } From 9069f56e05593d736d671749a249727727e26f80 Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Mon, 3 Jan 2022 21:53:52 -0800 Subject: [PATCH 3/4] Mark the crate as no_std --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 52cb43b..c44e12b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + extern crate libc; #[no_mangle] From 3220e60578c2cac07686f28ab134d8c243312039 Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Mon, 3 Jan 2022 21:54:31 -0800 Subject: [PATCH 4/4] Add init method to force linking --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c44e12b..393a7aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,12 @@ extern crate libc; +/// Call this somewhere to force Rust to link this module. +/// The call doesn't need to execute, just exist. +/// +/// See https://github.com/rust-lang/rust/issues/47384 +pub fn init() {} + #[no_mangle] extern "C" fn posix_memalign( memptr: *mut *mut libc::c_void,