[{"data":1,"prerenderedAt":707},["ShallowReactive",2],{"navigation":3,"\u002Fblog\u002Fwhy-rust-priority":46,"\u002Fblog\u002Fwhy-rust-priority-surround":703},[4],{"title":5,"path":6,"stem":7,"children":8,"page":45},"Blog","\u002Fblog","blog",[9,13,17,21,25,29,33,37,41],{"title":10,"path":11,"stem":12},"吉布斯自由能、化学势与扩散势","\u002Fblog\u002Fchemical-potential-and-diffusion-potential","blog\u002Fchemical-potential-and-diffusion-potential",{"title":14,"path":15,"stem":16},"Deploying Nuxt Static Sites with Nginx","\u002Fblog\u002Fdeploying-nuxt-static-site-with-nginx","blog\u002Fdeploying-nuxt-static-site-with-nginx",{"title":18,"path":19,"stem":20},"相变驱动力计算","\u002Fblog\u002Fphase-transformation-driving-force","blog\u002Fphase-transformation-driving-force",{"title":22,"path":23,"stem":24},"Python 环境配置完全指南：Conda 与国内镜像源","\u002Fblog\u002Fpython-environment-setup-guide","blog\u002Fpython-environment-setup-guide",{"title":26,"path":27,"stem":28},"Rust 编译与配置指南","\u002Fblog\u002Frust-compilation-and-configuration","blog\u002Frust-compilation-and-configuration",{"title":30,"path":31,"stem":32},"SSH Key Authentication Setup Guide","\u002Fblog\u002Fssh-key-authentication-setup","blog\u002Fssh-key-authentication-setup",{"title":34,"path":35,"stem":36},"Tauri + Rust 技术栈与编译说明","\u002Fblog\u002Ftauri-rust-tech-stack-and-build","blog\u002Ftauri-rust-tech-stack-and-build",{"title":38,"path":39,"stem":40},"Complete Guide to Utoipa Integration with Axum","\u002Fblog\u002Futoipa-integration-with-axum","blog\u002Futoipa-integration-with-axum",{"title":42,"path":43,"stem":44},"Rust: Code Once, Build Anywhere","\u002Fblog\u002Fwhy-rust-priority","blog\u002Fwhy-rust-priority",false,{"id":47,"title":42,"author":48,"body":53,"date":696,"description":697,"extension":698,"image":699,"meta":700,"minRead":321,"navigation":294,"path":43,"seo":701,"stem":44,"__hash__":702},"blog\u002Fblog\u002Fwhy-rust-priority.md",{"name":49,"avatar":50},"Jing Zhong",{"src":51,"alt":52},"https:\u002F\u002Fppm-sources.oss-cn-hongkong.aliyuncs.com\u002Fzj\u002Fme.jpg","Emma Thompson",{"type":54,"value":55,"toc":669},"minimark",[56,60,65,68,71,75,80,83,86,90,93,100,129,135,141,145,148,190,193,197,201,204,231,254,258,265,272,337,341,356,360,368,371,375,378,412,415,419,423,495,499,507,545,549,552,556,569,573,576,580,591,595,598,601,605,608,643,652,656,659,662,665],[57,58,59],"p",{},"In today's fragmented technology landscape, developers often face a daunting challenge: how to build applications that run seamlessly across different platforms without maintaining separate codebases for each one. Enter Rust—a systems programming language that has revolutionized cross-platform development with its powerful compilation capabilities and \"code once, build anywhere\" philosophy.",[61,62,64],"h2",{"id":63},"the-cross-platform-promise","The Cross-Platform Promise",[57,66,67],{},"The traditional approach to cross-platform development often involves trade-offs. You might use web technologies with frameworks like Electron (paying a size and performance penalty), maintain separate codebases in different languages, or rely on virtual machines and runtimes that add overhead.",[57,69,70],{},"Rust takes a different approach. Through its sophisticated compiler toolchain and support for diverse target architectures, Rust enables you to write your code once and compile it to run natively on virtually any platform—all without sacrificing performance, safety, or developer experience.",[61,72,74],{"id":73},"how-rust-makes-it-possible","How Rust Makes It Possible",[76,77,79],"h3",{"id":78},"llvm-backend-architecture","LLVM Backend Architecture",[57,81,82],{},"At the heart of Rust's cross-platform capabilities is its use of LLVM (Low-Level Virtual Machine) as its compiler backend. LLVM provides a powerful infrastructure for building compilers, supporting multiple CPU architectures and optimization strategies. When you write Rust code, the front-end parses and type-checks your code, then LLVM handles the platform-specific code generation and optimization.",[57,84,85],{},"This architecture means that adding support for a new platform often \"just works\" once LLVM supports it—the Rust team doesn't need to rebuild the entire compilation pipeline for each target.",[76,87,89],{"id":88},"tiered-platform-support","Tiered Platform Support",[57,91,92],{},"Rust organizes platforms into three tiers, each representing different levels of support and guaranteed stability:",[57,94,95,99],{},[96,97,98],"strong",{},"Tier 1 platforms"," are guaranteed to work with the latest stable Rust release. These platforms have full testing infrastructure, and the Rust team commits to maintaining them. Examples include:",[101,102,103,111,117,123],"ul",{},[104,105,106,110],"li",{},[107,108,109],"code",{},"x86_64-unknown-linux-gnu"," (64-bit Linux)",[104,112,113,116],{},[107,114,115],{},"x86_64-pc-windows-msvc"," (64-bit Windows)",[104,118,119,122],{},[107,120,121],{},"x86_64-apple-darwin"," (64-bit macOS)",[104,124,125,128],{},[107,126,127],{},"aarch64-apple-darwin"," (Apple Silicon)",[57,130,131,134],{},[96,132,133],{},"Tier 2 platforms"," are guaranteed to build but may not have full test coverage. This includes many Linux architectures and Windows variants.",[57,136,137,140],{},[96,138,139],{},"Tier 3 platforms"," are those where Rust might work but aren't officially guaranteed. This is where experimental support for new architectures often lives.",[76,142,144],{"id":143},"cross-compilation-made-simple","Cross-Compilation Made Simple",[57,146,147],{},"Rust makes cross-compilation straightforward through its target system. To compile for a different architecture, you simply add the target and specify it when building:",[149,150,155],"pre",{"className":151,"code":152,"language":153,"meta":154,"style":154},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","rustup target add x86_64-unknown-linux-musl\ncargo build --target x86_64-unknown-linux-musl\n","bash","",[107,156,157,176],{"__ignoreMap":154},[158,159,162,166,170,173],"span",{"class":160,"line":161},"line",1,[158,163,165],{"class":164},"sBMFI","rustup",[158,167,169],{"class":168},"sfazB"," target",[158,171,172],{"class":168}," add",[158,174,175],{"class":168}," x86_64-unknown-linux-musl\n",[158,177,179,182,185,188],{"class":160,"line":178},2,[158,180,181],{"class":164},"cargo",[158,183,184],{"class":168}," build",[158,186,187],{"class":168}," --target",[158,189,175],{"class":168},[57,191,192],{},"This simplicity extends to continuous integration pipelines, where you can build for multiple platforms in parallel without complex toolchain setup.",[61,194,196],{"id":195},"real-world-cross-platform-scenarios","Real-World Cross-Platform Scenarios",[76,198,200],{"id":199},"webassembly-running-rust-in-the-browser","WebAssembly: Running Rust in the Browser",[57,202,203],{},"One of Rust's most exciting cross-platform capabilities is its excellent WebAssembly (Wasm) support. You can compile Rust code to Wasm and run it in browsers at near-native speed, opening up possibilities for performance-critical web applications.",[149,205,207],{"className":151,"code":206,"language":153,"meta":154,"style":154},"cargo install wasm-pack\nwasm-pack build --target web\n",[107,208,209,219],{"__ignoreMap":154},[158,210,211,213,216],{"class":160,"line":161},[158,212,181],{"class":164},[158,214,215],{"class":168}," install",[158,217,218],{"class":168}," wasm-pack\n",[158,220,221,224,226,228],{"class":160,"line":178},[158,222,223],{"class":164},"wasm-pack",[158,225,184],{"class":168},[158,227,187],{"class":168},[158,229,230],{"class":168}," web\n",[57,232,233,234,241,242,247,248,253],{},"Projects like ",[235,236,240],"a",{"href":237,"rel":238},"https:\u002F\u002Fyew.rs\u002F",[239],"nofollow","Yew",", ",[235,243,246],{"href":244,"rel":245},"https:\u002F\u002Fleptos.dev\u002F",[239],"Leptos",", and ",[235,249,252],{"href":250,"rel":251},"https:\u002F\u002Fsycamore-rs.netlify.app\u002F",[239],"Sycamore"," enable full-stack web development with Rust, sharing code between client and server.",[76,255,257],{"id":256},"embedded-systems-from-microcontrollers-to-iot","Embedded Systems: From Microcontrollers to IoT",[57,259,260,261,264],{},"Rust's zero-cost abstractions and minimal runtime make it ideal for embedded systems. Using the ",[107,262,263],{},"embedded-hal"," (Hardware Abstraction Layer) ecosystem, you can write drivers that work across countless microcontroller families.",[57,266,267,268,271],{},"The ",[107,269,270],{},"#[no_std]"," attribute allows Rust to run without the standard library, making it suitable for bare-metal systems:",[149,273,277],{"className":274,"code":275,"language":276,"meta":154,"style":154},"language-rust shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","#![no_std]\n#![no_main]\n\nuse panic_halt as _;\n\n#[entry]\nfn main() -> ! {\n    \u002F\u002F Your embedded code here\n    loop {}\n}\n","rust",[107,278,279,284,289,296,302,307,313,319,325,331],{"__ignoreMap":154},[158,280,281],{"class":160,"line":161},[158,282,283],{},"#![no_std]\n",[158,285,286],{"class":160,"line":178},[158,287,288],{},"#![no_main]\n",[158,290,292],{"class":160,"line":291},3,[158,293,295],{"emptyLinePlaceholder":294},true,"\n",[158,297,299],{"class":160,"line":298},4,[158,300,301],{},"use panic_halt as _;\n",[158,303,305],{"class":160,"line":304},5,[158,306,295],{"emptyLinePlaceholder":294},[158,308,310],{"class":160,"line":309},6,[158,311,312],{},"#[entry]\n",[158,314,316],{"class":160,"line":315},7,[158,317,318],{},"fn main() -> ! {\n",[158,320,322],{"class":160,"line":321},8,[158,323,324],{},"    \u002F\u002F Your embedded code here\n",[158,326,328],{"class":160,"line":327},9,[158,329,330],{},"    loop {}\n",[158,332,334],{"class":160,"line":333},10,[158,335,336],{},"}\n",[76,338,340],{"id":339},"mobile-development-ios-and-android","Mobile Development: iOS and Android",[57,342,343,344,349,350,355],{},"While Rust doesn't have a mobile UI framework in its standard library, tools like ",[235,345,348],{"href":346,"rel":347},"https:\u002F\u002Fkotlinlang.org\u002F",[239],"Kotlin"," (Android) and ",[235,351,354],{"href":352,"rel":353},"https:\u002F\u002Fwww.swift.org\u002F",[239],"Swift"," (iOS) provide Foreign Function Interfaces (FFI) that make it easy to call Rust code. This pattern allows you to write performance-critical or shared business logic in Rust while using platform-native UI frameworks.",[76,357,359],{"id":358},"desktop-applications-with-tauri-and-wry","Desktop Applications with Tauri and Wry",[57,361,233,362,367],{},[235,363,366],{"href":364,"rel":365},"https:\u002F\u002Ftauri.app\u002F",[239],"Tauri"," demonstrate Rust's cross-platform prowess for desktop applications. Tauri lets you build desktop apps using a web frontend while Rust handles the backend, resulting in dramatically smaller bundle sizes compared to Electron.",[57,369,370],{},"A typical Tauri app might be 3-5 MB, whereas an equivalent Electron app could easily exceed 100 MB—all because Rust compiles to native code rather than bundling an entire Chromium browser.",[61,372,374],{"id":373},"the-power-of-cargo-universal-dependency-management","The Power of Cargo: Universal Dependency Management",[57,376,377],{},"Cargo, Rust's package manager and build system, plays a crucial role in the \"code once\" philosophy. Cargo handles:",[101,379,380,386,396,402],{},[104,381,382,385],{},[96,383,384],{},"Cross-platform dependency resolution",": Libraries declare their supported platforms, and Cargo handles the rest",[104,387,388,391,392,395],{},[96,389,390],{},"Conditional compilation",": Use ",[107,393,394],{},"#[cfg(target_os = \"windows\")]"," to include platform-specific code",[104,397,398,401],{},[96,399,400],{},"Automatic feature flags",": Enable or disable functionality based on target platform",[104,403,404,407,408,411],{},[96,405,406],{},"Build scripts",": ",[107,409,410],{},"build.rs"," files can run platform-specific build logic",[57,413,414],{},"This means you can write a library that abstracts platform differences internally while exposing a consistent API to users.",[61,416,418],{"id":417},"practical-examples","Practical Examples",[76,420,422],{"id":421},"platform-specific-code","Platform-Specific Code",[149,424,426],{"className":274,"code":425,"language":276,"meta":154,"style":154},"#[cfg(target_os = \"windows\")]\nfn get_system_info() -> String {\n    format!(\"Windows {}\", windows_version())\n}\n\n#[cfg(target_os = \"linux\")]\nfn get_system_info() -> String {\n    fs::read_to_string(\"\u002Fetc\u002Fos-release\").unwrap()\n}\n\n#[cfg(target_os = \"macos\")]\nfn get_system_info() -> String {\n    \"macOS\".to_string()\n}\n",[107,427,428,433,438,443,447,451,456,460,465,469,473,479,484,490],{"__ignoreMap":154},[158,429,430],{"class":160,"line":161},[158,431,432],{},"#[cfg(target_os = \"windows\")]\n",[158,434,435],{"class":160,"line":178},[158,436,437],{},"fn get_system_info() -> String {\n",[158,439,440],{"class":160,"line":291},[158,441,442],{},"    format!(\"Windows {}\", windows_version())\n",[158,444,445],{"class":160,"line":298},[158,446,336],{},[158,448,449],{"class":160,"line":304},[158,450,295],{"emptyLinePlaceholder":294},[158,452,453],{"class":160,"line":309},[158,454,455],{},"#[cfg(target_os = \"linux\")]\n",[158,457,458],{"class":160,"line":315},[158,459,437],{},[158,461,462],{"class":160,"line":321},[158,463,464],{},"    fs::read_to_string(\"\u002Fetc\u002Fos-release\").unwrap()\n",[158,466,467],{"class":160,"line":327},[158,468,336],{},[158,470,471],{"class":160,"line":333},[158,472,295],{"emptyLinePlaceholder":294},[158,474,476],{"class":160,"line":475},11,[158,477,478],{},"#[cfg(target_os = \"macos\")]\n",[158,480,482],{"class":160,"line":481},12,[158,483,437],{},[158,485,487],{"class":160,"line":486},13,[158,488,489],{},"    \"macOS\".to_string()\n",[158,491,493],{"class":160,"line":492},14,[158,494,336],{},[76,496,498],{"id":497},"cross-platform-networking-with-tokio","Cross-Platform Networking with Tokio",[57,500,267,501,506],{},[235,502,505],{"href":503,"rel":504},"https:\u002F\u002Ftokio.rs\u002F",[239],"Tokio"," runtime provides asynchronous networking that works across platforms:",[149,508,510],{"className":274,"code":509,"language":276,"meta":154,"style":154},"use tokio::net::TcpListener;\n\n#[tokio::main]\nasync fn main() -> Result\u003C(), Box\u003Cdyn std::error::Error>> {\n    let listener = TcpListener::bind(\"0.0.0.0:8080\").await?;\n    \u002F\u002F Same code works on Linux, Windows, and macOS\n}\n",[107,511,512,517,521,526,531,536,541],{"__ignoreMap":154},[158,513,514],{"class":160,"line":161},[158,515,516],{},"use tokio::net::TcpListener;\n",[158,518,519],{"class":160,"line":178},[158,520,295],{"emptyLinePlaceholder":294},[158,522,523],{"class":160,"line":291},[158,524,525],{},"#[tokio::main]\n",[158,527,528],{"class":160,"line":298},[158,529,530],{},"async fn main() -> Result\u003C(), Box\u003Cdyn std::error::Error>> {\n",[158,532,533],{"class":160,"line":304},[158,534,535],{},"    let listener = TcpListener::bind(\"0.0.0.0:8080\").await?;\n",[158,537,538],{"class":160,"line":309},[158,539,540],{},"    \u002F\u002F Same code works on Linux, Windows, and macOS\n",[158,542,543],{"class":160,"line":315},[158,544,336],{},[61,546,548],{"id":547},"challenges-and-considerations","Challenges and Considerations",[57,550,551],{},"While Rust makes cross-platform development remarkably smooth, it's not without challenges:",[76,553,555],{"id":554},"platform-specific-apis","Platform-Specific APIs",[57,557,558,559,241,562,247,565,568],{},"Some functionality inherently differs across platforms. File paths, permissions, threading behavior, and system calls may vary. Crates like ",[107,560,561],{},"dirs",[107,563,564],{},"sys-info",[107,566,567],{},"whoami"," help abstract these differences.",[76,570,572],{"id":571},"testing-burden","Testing Burden",[57,574,575],{},"Cross-platform code needs testing on all target platforms. Continuous integration with multiple test runners is essential. Services like GitHub Actions make this manageable with matrix builds.",[76,577,579],{"id":578},"binary-size-considerations","Binary Size Considerations",[57,581,582,583,586,587,590],{},"While Rust produces optimized binaries, static linking (common for portability) can increase size. Techniques like using ",[107,584,585],{},"musl-gc"," for Linux or enabling link-time optimization (",[107,588,589],{},"lto = true"," in Cargo.toml) help reduce footprint.",[61,592,594],{"id":593},"the-ecosystem-effect","The Ecosystem Effect",[57,596,597],{},"Rust's cross-platform capabilities have catalyzed an ecosystem of portable libraries. When you publish a crate, you're implicitly contributing to a codebase that can run everywhere. Network protocols, serialization formats, data structures, algorithms—these all work identically across platforms.",[57,599,600],{},"This ecosystem effect creates a virtuous cycle: developers build portable libraries because the toolchain makes it easy, which makes Rust more attractive for cross-platform projects, which drives more portable library development.",[61,602,604],{"id":603},"getting-started","Getting Started",[57,606,607],{},"Ready to build cross-platform Rust applications? Here's how to start:",[609,610,611,619,627,635],"ol",{},[104,612,613,407,616],{},[96,614,615],{},"Install Rust",[107,617,618],{},"curl --proto '=https' --tlsv1.2 -sSf https:\u002F\u002Fsh.rustup.rs | sh",[104,620,621,407,624],{},[96,622,623],{},"List available targets",[107,625,626],{},"rustup target list",[104,628,629,407,632],{},[96,630,631],{},"Add a cross-compilation target",[107,633,634],{},"rustup target add aarch64-apple-ios",[104,636,637,407,640],{},[96,638,639],{},"Build for your target",[107,641,642],{},"cargo build --target aarch64-apple-ios",[57,644,645,646,651],{},"For more advanced cross-compilation scenarios, check out ",[235,647,650],{"href":648,"rel":649},"https:\u002F\u002Fgithub.com\u002Fcross-rs\u002Fcross",[239],"cross",", a tool that simplifies cross-compilation using Docker containers.",[61,653,655],{"id":654},"conclusion","Conclusion",[57,657,658],{},"Rust's \"code once, build anywhere\" capability isn't just a nice-to-have—it's a fundamental shift in how we think about cross-platform development. By combining the safety of a high-level language with the performance of low-level code and the portability of a sophisticated compiler toolchain, Rust enables developers to build software that truly runs everywhere without compromise.",[57,660,661],{},"Whether you're building web applications with WebAssembly, embedded systems on microcontrollers, mobile apps with native UIs, or desktop applications with Tauri, Rust provides a unified foundation that adapts to your needs.",[57,663,664],{},"The future of software development is cross-platform, and Rust is leading the way.",[666,667,668],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":154,"searchDepth":178,"depth":178,"links":670},[671,672,677,683,684,688,693,694,695],{"id":63,"depth":178,"text":64},{"id":73,"depth":178,"text":74,"children":673},[674,675,676],{"id":78,"depth":291,"text":79},{"id":88,"depth":291,"text":89},{"id":143,"depth":291,"text":144},{"id":195,"depth":178,"text":196,"children":678},[679,680,681,682],{"id":199,"depth":291,"text":200},{"id":256,"depth":291,"text":257},{"id":339,"depth":291,"text":340},{"id":358,"depth":291,"text":359},{"id":373,"depth":178,"text":374},{"id":417,"depth":178,"text":418,"children":685},[686,687],{"id":421,"depth":291,"text":422},{"id":497,"depth":291,"text":498},{"id":547,"depth":178,"text":548,"children":689},[690,691,692],{"id":554,"depth":291,"text":555},{"id":571,"depth":291,"text":572},{"id":578,"depth":291,"text":579},{"id":593,"depth":178,"text":594},{"id":603,"depth":178,"text":604},{"id":654,"depth":178,"text":655},"2025-12-28","Explore how Rust's powerful cross-platform compilation capabilities enable developers to build once and deploy everywhere—from embedded systems to webAssembly.","md","https:\u002F\u002Fppm-sources.oss-cn-hongkong.aliyuncs.com\u002Fzj\u002Frust-.crab.jpg",{},{"title":42,"description":697},"ffeHvdY73BN95vATCxpqcJyzYOl4BdwKqcFFRIy39AE",[704,706],{"title":38,"path":39,"stem":40,"description":705,"children":-1},"Learn how to integrate utoipa and Swagger UI in Rust Axum projects to enable OpenAPI documentation with JWT, Cookie, and API Key authentication.",null,1792686186194]