CRITICAL: Use for Makepad cross-platform support. Triggers on: makepad platform, makepad os, makepad macos, makepad windows, makepad linux, makepad android, makepad ios, makepad web, makepad wasm, makepad metal, makepad d3d11, makepad opengl, makepad webgl, OsType, CxOs, makepad 跨平台, makepad 平台支持
Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19
Check for updates: https://crates.io/crates/makepad-widgets
You are an expert at Makepad cross-platform development. Help users by:
Refer to the local files for detailed documentation:
./references/platform-support.md - Platform details and OsTypeBefore answering questions, Claude MUST:
/sync-crate-skills makepad --force 更新文档"| Platform | Graphics Backend | OS Module |
|---|---|---|
| macOS | Metal | apple/metal_*.rs, apple/cocoa_*.rs |
| iOS | Metal | apple/metal_*.rs, apple/ios_*.rs |
| Windows | D3D11 | mswindows/d3d11_*.rs, mswindows/win32_*.rs |
| Linux | OpenGL | linux/opengl_*.rs, linux/x11*.rs, linux/wayland*.rs |
| Web | WebGL2 | web/*.rs, web_browser/*.rs |
| Android | OpenGL ES | android/*.rs |
| OpenHarmony | OHOS | open_harmony/*.rs |
| OpenXR | VR/AR | open_xr/*.rs |
pub enum OsType {
Unknown,
Windows,
Macos,
Linux { custom_window_chrome: bool },
Ios,
Android(AndroidParams),
OpenHarmony,
Web(WebParams),
OpenXR,
}
// Check platform in code
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
match cx.os_type() {
OsType::Macos => { /* macOS-specific */ }
OsType::Windows => { /* Windows-specific */ }
OsType::Web(_) => { /* Web-specific */ }
_ => {}
}
}
// In Cx
impl Cx {
pub fn os_type(&self) -> OsType;
pub fn gpu_info(&self) -> &GpuInfo;
pub fn xr_capabilities(&self) -> &XrCapabilities;
pub fn cpu_cores(&self) -> usize;
}
// Compile-time platform detection
#[cfg(target_os = "macos")]
fn macos_only() { }
#[cfg(target_os = "windows")]
fn windows_only() { }
#[cfg(target_os = "linux")]
fn linux_only() { }
#[cfg(target_arch = "wasm32")]
fn web_only() { }
#[cfg(target_os = "android")]
fn android_only() { }
#[cfg(target_os = "ios")]
fn ios_only() { }
// App entry macro
app_main!(App);
pub struct App {
ui: WidgetRef,
}
impl LiveRegister for App {
fn live_register(cx: &mut Cx) {
// Register components
crate::makepad_widgets::live_design(cx);
}
}
impl AppMain for App {
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
// Handle app events
self.ui.handle_event(cx, event, &mut Scope::empty());
}
}
platform/src/os/ directorycx.os_type() for runtime platform detection#[cfg(target_os = "...")] for compile-time platform detection