tauri-docs icon indicating copy to clipboard operation
tauri-docs copied to clipboard

Add guide: Conditional compilation

Open JonasKruckenberg opened this issue 3 years ago • 1 comments

TODO

Tauri exposes several environment variables to the beforeDevCommand and beforeBuildCommand, allowing frontend bundlers to perform conditional compilation. You can use this to write platform-specific JS code.

Details

JavaScript

  • only available with some bundlers (but most) -> called treeshaking

  • the cli exposes a set of environment variables

    • TAURI_PLATFORM - same as target_os
    • TAURI_ARCH - same as target_arch
    • TAURI_FAMILY - same as target_family
    • TAURI_PLATFORM_VERSION - version of the OS
    • TAURI_PLATFORM_TYPE - "Linux" | "Darwin" | "Window_NT" same as nodejs os.type()
    • TAURI_DEBUG - same as debug_assertions
  • quick example

Rust

  • link to conditional compilation guide https://doc.rust-lang.org/reference/conditional-compilation.html
  • quick intro cfg! and #[cfg()]
  • quick intro features
  • target a specific OS (target_os and target_family)
  • target a specific CPU architecture
  • cfg(debug_assertions)

JonasKruckenberg avatar Feb 14 '22 11:02 JonasKruckenberg

We definitely need a guide on this one way or another, possibly under the Develop guide section. Tracking for 2.0.

simonhyll avatar Sep 15 '23 21:09 simonhyll