Skip to content

Commit 624dffc

Browse files
committed
MacOS & ARM64 support
This is for OpenDream. macOS specifically just needs to be supported in the library loader code, by making it use the same dlopen() path as Linux. byondapi.h does not support ARM64 properly due to missing #if statements for it. This leads to DM_64BIT not being set and u4c being miscompiled as a u64. I decided to just work around this by telling bindgen to add that define if the target is aarch64, instead of modifying the header files themselves.
1 parent 6726e9a commit 624dffc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/byondapi-rs/src/static_global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn init_lib() -> byondapi_sys::ByondApi {
2323
.expect("Failed to initialize library.")
2424
}
2525

26-
#[cfg(target_os = "linux")]
26+
#[cfg(any(target_os = "linux", target_os = "macos"))]
2727
fn init_lib() -> byondapi_sys::ByondApi {
2828
for func in inventory::iter::<super::InitFunc> {
2929
func.0();

crates/byondapi-sys/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ fn copy_wrapper(lib_dir: &Path) -> PathBuf {
4444
fn generate_all() {
4545
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR not defined"));
4646

47+
let target_triple = std::env::var("TARGET").unwrap_or("".into());
48+
let is_64_bit = target_triple.starts_with("aarch64");
49+
4750
get_headers()
4851
.into_iter()
4952
.for_each(|(path, (major, minor))| {
5053
let target = out_dir.join("byondapi.h");
5154
std::fs::copy(path, target).expect("Failed to copy to out_dir");
5255
let wrapper = copy_wrapper(&out_dir);
5356

54-
let builder = bindgen::Builder::default()
57+
let mut builder = bindgen::Builder::default()
5558
.header(wrapper.to_string_lossy())
5659
.dynamic_library_name("ByondApi")
5760
.dynamic_link_require_all(true)
@@ -60,6 +63,10 @@ fn generate_all() {
6063
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
6164
.parse_callbacks(Box::new(DoxygenCallbacks));
6265

66+
if is_64_bit {
67+
builder = builder.clang_arg("-DDM_64BIT")
68+
}
69+
6370
builder
6471
.generate()
6572
.expect("Unable to generate bindings")

0 commit comments

Comments
 (0)