From bc7ab82f801f17514c67b2166f7f62040f9036e1 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 28 Jan 2025 19:00:35 -0500 Subject: [PATCH] fix build on 1.82+ --- platform/rust/Cargo.toml | 3 ++- platform/rust/build.rs | 9 ++++++++- platform/rust/src/lib.rs | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/platform/rust/Cargo.toml b/platform/rust/Cargo.toml index 19741b52319..566fc294065 100644 --- a/platform/rust/Cargo.toml +++ b/platform/rust/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" cxx = "1.0" [build-dependencies] -cxx-build = "1.0" cmake = "0.1" +cxx-build = "1.0" +rustversion = "1.0.19" diff --git a/platform/rust/build.rs b/platform/rust/build.rs index d97b99e21a7..2db9c70696f 100644 --- a/platform/rust/build.rs +++ b/platform/rust/build.rs @@ -1,6 +1,7 @@ use std::env; use std::path::PathBuf; +//noinspection RsConstantConditionIf fn main() { let project_root = { let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -25,7 +26,13 @@ fn main() { let lib_dir = build_dir.join("build"); println!("cargo:rustc-link-search=native={}", lib_dir.display()); - println!("cargo:rustc-link-lib=static=mbgl-core"); + if rustversion::cfg!(since(1.82)) { + // `cargo test` wouldn't work with Rust v1.82+ without this + // FIXME: this MIGHT significantly increase the size of the final binary, needs to be tested + println!("cargo:rustc-link-lib=static:+whole-archive=mbgl-core"); + } else { + println!("cargo:rustc-link-lib=static=mbgl-core"); + } // cxx build let mut cxx = cxx_build::bridge("src/lib.rs"); diff --git a/platform/rust/src/lib.rs b/platform/rust/src/lib.rs index e47d74f11c2..110d6cc99b7 100644 --- a/platform/rust/src/lib.rs +++ b/platform/rust/src/lib.rs @@ -17,7 +17,7 @@ mod ffi { } /// A safe Rust wrapper so you can call `ceil_log2` from your code: -pub fn ceil_log2(x: u64) -> u32 { +pub fn our_log(x: u64) -> u32 { ffi::ceil_log2(x) } @@ -26,13 +26,13 @@ mod tests { use super::*; #[test] fn test_log2() { - let result = ceil_log2(1); + let result = our_log(1); assert_eq!(result, 0, "log2(1) = 0 bits needed"); - let result = ceil_log2(2); + let result = our_log(2); assert_eq!(result, 1, "log2(2) = 1 bit needed"); - let result = ceil_log2(3); + let result = our_log(3); assert_eq!(result, 2, "log2(3) -> 2 bits needed"); } }