diff --git a/maplibre-android/Cargo.toml b/maplibre-android/Cargo.toml index 1202b3ff..b9f1c770 100644 --- a/maplibre-android/Cargo.toml +++ b/maplibre-android/Cargo.toml @@ -6,7 +6,7 @@ categories = [] edition = "2021" [dependencies] - +maplibre = { path = "../maplibre" } [lib] crate-type = ["rlib", "cdylib"] diff --git a/maplibre-android/src/lib.rs b/maplibre-android/src/lib.rs index e69de29b..95150e3c 100644 --- a/maplibre-android/src/lib.rs +++ b/maplibre-android/src/lib.rs @@ -0,0 +1,16 @@ +use maplibre::{MapBuilder, ScheduleMethod, TokioScheduleMethod}; +use maplibre::window::FromWindow; +pub use std::time::Instant; + +#[cfg(not(target_os = "android"))] +compile_error!("maplibre-android works only on android."); + +#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] +pub fn main() { + env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); + + MapBuilder::from_window("A fantastic window!") + .with_schedule_method(ScheduleMethod::Tokio(TokioScheduleMethod::new())) + .build() + .run_sync(); +} diff --git a/maplibre-apple/Cargo.toml b/maplibre-apple/Cargo.toml index eff1bdae..4a776700 100644 --- a/maplibre-apple/Cargo.toml +++ b/maplibre-apple/Cargo.toml @@ -6,7 +6,7 @@ categories = [] edition = "2021" [dependencies] - +maplibre = { path = "../maplibre" } [lib] crate-type = ["staticlib"] diff --git a/maplibre-apple/src/lib.rs b/maplibre-apple/src/lib.rs index e69de29b..20ab17b3 100644 --- a/maplibre-apple/src/lib.rs +++ b/maplibre-apple/src/lib.rs @@ -0,0 +1,16 @@ +use maplibre::{MapBuilder, ScheduleMethod, TokioScheduleMethod}; +use maplibre::window::FromWindow; +pub use std::time::Instant; + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +compile_error!("maplibre-apple works only on macOS and iOS."); + +#[no_mangle] +pub fn maplibre_apple_main() { + env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); + + MapBuilder::from_window("A fantastic window!") + .with_schedule_method(ScheduleMethod::Tokio(TokioScheduleMethod::new())) + .build() + .run_sync(); +} diff --git a/maplibre-core/Cargo.toml b/maplibre-core/Cargo.toml index ead16fd1..9a7c646f 100644 --- a/maplibre-core/Cargo.toml +++ b/maplibre-core/Cargo.toml @@ -86,4 +86,3 @@ criterion = "0.3" [build-dependencies] maplibre-build-tools = { path = "../maplibre-build-tools" } - diff --git a/maplibre-core/src/platform/android/mod.rs b/maplibre-core/src/platform/android/mod.rs deleted file mode 100644 index 1a6b1187..00000000 --- a/maplibre-core/src/platform/android/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::io::scheduler::ScheduleMethod; -use crate::platform::schedule_method::TokioScheduleMethod; -use crate::window::FromWindow; -use crate::MapBuilder; -pub use std::time::Instant; - -pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm; - -#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] -pub fn main() { - env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); - - MapBuilder::from_window("A fantastic window!") - .with_schedule_method(ScheduleMethod::Tokio(TokioScheduleMethod::new())) - .build() - .run_sync(); -} diff --git a/maplibre-core/src/platform/apple/mod.rs b/maplibre-core/src/platform/apple/mod.rs deleted file mode 100644 index 4a0d9971..00000000 --- a/maplibre-core/src/platform/apple/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -use crate::io::scheduler::ScheduleMethod; -use crate::platform::schedule_method::TokioScheduleMethod; -use crate::window::FromWindow; -use crate::MapBuilder; -pub use std::time::Instant; - -// macOS and iOS (Metal) -pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; - -#[no_mangle] -pub fn maplibre_apple_main() { - env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); - - MapBuilder::from_window("A fantastic window!") - .with_schedule_method(ScheduleMethod::Tokio(TokioScheduleMethod::new())) - .build() - .run_sync(); -} diff --git a/maplibre-core/src/platform/mod.rs b/maplibre-core/src/platform/mod.rs index 86875bcd..ed0e7935 100644 --- a/maplibre-core/src/platform/mod.rs +++ b/maplibre-core/src/platform/mod.rs @@ -1,23 +1,27 @@ //! This module handles platform specific code. Depending on the compilation target different //! parts of this module are used -#[cfg(target_arch = "wasm32")] -mod web; +// WebGPU +#[cfg(all(target_arch = "wasm32", not(feature = "web-webgl")))] +pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8Unorm; -#[cfg(any(target_os = "macos", target_os = "ios"))] -mod apple; +// WebGL +#[cfg(all(target_arch = "wasm32", feature = "web-webgl"))] +pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; +// Vulkan Android #[cfg(target_os = "android")] -mod android; +pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm; -#[cfg(not(target_arch = "wasm32"))] -mod noweb; +// macOS and iOS (Metal) +#[cfg(any(target_os = "macos", target_os = "ios"))] +pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; /// For Vulkan/OpenGL #[cfg(not(any( target_os = "android", target_os = "macos", - target_os = "ios", + any(target_os = "macos", target_os = "ios"), target_arch = "wasm32" )))] pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; @@ -37,3 +41,9 @@ pub use noweb::*; // FIXME: This limit is enforced by WebGL. Actually this makes sense! // FIXME: This can also be achieved by _pad attributes in shader_ffi.rs pub const MIN_BUFFER_SIZE: u64 = 32; + +#[cfg(not(target_arch = "wasm32"))] +mod noweb; + +#[cfg(target_arch = "wasm32")] +mod web; diff --git a/maplibre-core/src/platform/web/mod.rs b/maplibre-core/src/platform/web/mod.rs index 479cda1d..4c716da1 100644 --- a/maplibre-core/src/platform/web/mod.rs +++ b/maplibre-core/src/platform/web/mod.rs @@ -20,14 +20,6 @@ pub mod legacy_webworker_fetcher; mod pool; pub mod schedule_method; -// WebGPU -#[cfg(not(feature = "web-webgl"))] -pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8Unorm; - -// WebGL -#[cfg(feature = "web-webgl")] -pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; - #[cfg(feature = "enable-tracing")] fn enable_tracing() { use tracing_subscriber::layer::SubscriberExt; diff --git a/maplibre-web/src/lib.rs b/maplibre-web/src/lib.rs index 9e961e12..6324afb9 100644 --- a/maplibre-web/src/lib.rs +++ b/maplibre-web/src/lib.rs @@ -1 +1,4 @@ pub use maplibre_core::*; + +#[cfg(not(target_arch = "wasm32"))] +compile_error!("maplibre-web works only on wasm32."); \ No newline at end of file