Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Feb 5, 2025
1 parent 63774c6 commit a45e009
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion platform/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ fn main() {

println!("cargo:rerun-if-changed=src/lib.rs");
println!("cargo:rerun-if-changed=src/wrapper.cc");
println!("cargo:rerun-if-changed=include/wrapper.h");
println!("cargo:rerun-if-changed=include/tile_server_options.h");
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#pragma once
#include "rust/cxx.h"
#include "mbgl/math/log2.hpp"
#include "mbgl/util/tile_server_options.hpp"

namespace ml {
namespace bridge {

uint32_t get_42();

using namespace mbgl;

// TileServerOptions constructor helpers
Expand Down
2 changes: 1 addition & 1 deletion platform/rust/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ docs:
cargo doc --no-deps --open

# Print Rust version information
rust-info:
@rust-info:
rustc --version
cargo --version

Expand Down
35 changes: 17 additions & 18 deletions platform/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ pub use tile_server_options::TileServerOptions;

#[cxx::bridge(namespace = "ml::bridge")]
mod ffi {
// C++ types exposed to Rust.
unsafe extern "C++" {
include!("maplibre-native/include/wrapper.h");
include!("maplibre-native/include/tile_server_options.h");

#[namespace = "mbgl"]
type TileServerOptions;
Expand All @@ -16,70 +15,70 @@ mod ffi {
fn TileServerOptions_maptiler() -> UniquePtr<TileServerOptions>;

fn TileServerOptions_withBaseURL(obj: Pin<&mut TileServerOptions>, value: &str);
fn baseURL(self: &TileServerOptions) -> &CxxString;
fn baseURL(&self) -> &CxxString;
fn TileServerOptions_withUriSchemeAlias(obj: Pin<&mut TileServerOptions>, value: &str);
fn uriSchemeAlias(self: &TileServerOptions) -> &CxxString;
fn uriSchemeAlias(&self) -> &CxxString;
unsafe fn TileServerOptions_withSourceTemplate(
obj: Pin<&mut TileServerOptions>,
source_template: &str,
domain_name: &str,
version_prefix: *const i8,
);
fn sourceTemplate(self: &TileServerOptions) -> &CxxString;
fn sourceDomainName(self: &TileServerOptions) -> &CxxString;
fn sourceTemplate(&self) -> &CxxString;
fn sourceDomainName(&self) -> &CxxString;
unsafe fn TileServerOptions_sourceVersionPrefix(value: &TileServerOptions) -> *const i8;
unsafe fn TileServerOptions_withStyleTemplate(
obj: Pin<&mut TileServerOptions>,
style_template: &str,
domain_name: &str,
version_prefix: *const i8,
);
fn styleTemplate(self: &TileServerOptions) -> &CxxString;
fn styleDomainName(self: &TileServerOptions) -> &CxxString;
fn styleTemplate(&self) -> &CxxString;
fn styleDomainName(&self) -> &CxxString;
unsafe fn TileServerOptions_styleVersionPrefix(value: &TileServerOptions) -> *const i8;
unsafe fn TileServerOptions_withSpritesTemplate(
obj: Pin<&mut TileServerOptions>,
sprites_template: &str,
domain_name: &str,
version_prefix: *const i8,
);
fn spritesTemplate(self: &TileServerOptions) -> &CxxString;
fn spritesDomainName(self: &TileServerOptions) -> &CxxString;
fn spritesTemplate(&self) -> &CxxString;
fn spritesDomainName(&self) -> &CxxString;
unsafe fn TileServerOptions_spritesVersionPrefix(value: &TileServerOptions) -> *const i8;
unsafe fn TileServerOptions_withGlyphsTemplate(
obj: Pin<&mut TileServerOptions>,
glyphs_template: &str,
domain_name: &str,
version_prefix: *const i8,
);
fn glyphsTemplate(self: &TileServerOptions) -> &CxxString;
fn glyphsDomainName(self: &TileServerOptions) -> &CxxString;
fn glyphsTemplate(&self) -> &CxxString;
fn glyphsDomainName(&self) -> &CxxString;
unsafe fn TileServerOptions_glyphsVersionPrefix(value: &TileServerOptions) -> *const i8;
unsafe fn TileServerOptions_withTileTemplate(
obj: Pin<&mut TileServerOptions>,
tile_template: &str,
domain_name: &str,
version_prefix: *const i8,
);
fn tileTemplate(self: &TileServerOptions) -> &CxxString;
fn tileDomainName(self: &TileServerOptions) -> &CxxString;
fn tileTemplate(&self) -> &CxxString;
fn tileDomainName(&self) -> &CxxString;
unsafe fn TileServerOptions_tileVersionPrefix(value: &TileServerOptions) -> *const i8;
unsafe fn TileServerOptions_withApiKeyParameterName(
obj: Pin<&mut TileServerOptions>,
value: &str,
);
fn apiKeyParameterName(self: &TileServerOptions) -> &CxxString;
fn apiKeyParameterName(&self) -> &CxxString;
fn TileServerOptions_setRequiresApiKey(obj: Pin<&mut TileServerOptions>, value: bool);
fn requiresApiKey(self: &TileServerOptions) -> bool;
fn requiresApiKey(&self) -> bool;

// /// Gets the default styles.
// const std::vector<mbgl::util::DefaultStyle> defaultStyles() const;

// /// Sets the collection default styles.
// TileServerOptions& withDefaultStyles(std::vector<mbgl::util::DefaultStyle> styles);

// fn withDefaultStyle(self: &TileServerOptions);
// fn withDefaultStyle(&self);
unsafe fn TileServerOptions_withDefaultStyle(obj: Pin<&mut TileServerOptions>, value: &str);
fn defaultStyle(self: &TileServerOptions) -> &CxxString;
fn defaultStyle(&self) -> &CxxString;
}
}
4 changes: 2 additions & 2 deletions platform/rust/src/tile_server_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct TileServerOptions(UniquePtr<ffi::TileServerOptions>);
/// # Safety
/// * as_ptr() inside C++ std::string is guaranteed to be null-terminated.
/// * The &CStr will remain valid as long as the TileServerOptions `&self` remains valid.
/// If some code tries to modify self, it will need to use &mut self,
/// which will not compile unless there are no &CStr references, as they use the same lifetime.
/// If some code tries to modify self, it will need to use &mut self,
/// which will not compile unless there are no &CStr references, as they use the same lifetime.
unsafe fn to_c_str(value: &CxxString) -> &CStr {
CStr::from_ptr(value.as_ptr().cast())
}
Expand Down
6 changes: 1 addition & 5 deletions platform/rust/src/wrapper.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "maplibre-native/include/wrapper.h"
#include "maplibre-native/include/tile_server_options.h"
#include "maplibre-native/src/lib.rs.h"

namespace ml {
namespace bridge {

uint32_t get_42() {
return 42;
}

} // namespace bridge
} // namespace ml

0 comments on commit a45e009

Please sign in to comment.