Skip to content

Commit

Permalink
fix build on 1.82+
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Jan 29, 2025
1 parent 633adef commit bc7ab82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion platform/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion platform/rust/build.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions platform/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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");
}
}

0 comments on commit bc7ab82

Please sign in to comment.