Tauri 완벽 가이드 | Rust 데스크톱 앱·작은 번들·보안·크로스 플랫폼·실전 활용

Tauri 완벽 가이드 | Rust 데스크톱 앱·작은 번들·보안·크로스 플랫폼·실전 활용

이 글의 핵심

Tauri로 경량 데스크톱 앱을 구축하는 완벽 가이드입니다. Rust 백엔드, 웹 프론트엔드, IPC, 시스템 트레이, 자동 업데이트까지 실전 예제로 정리했습니다.

실무 경험 공유: Electron에서 Tauri로 전환하면서, 앱 크기가 100MB에서 5MB로 감소하고 메모리 사용량이 70% 줄어든 경험을 공유합니다.

들어가며: “Electron이 무거워요”

실무 문제 시나리오

시나리오 1: 앱 크기가 너무 커요
Electron은 100MB+입니다. Tauri는 5MB 이하입니다.

시나리오 2: 메모리 사용량이 높아요
Chromium은 무겁습니다. Tauri는 시스템 WebView를 사용합니다.

시나리오 3: 보안이 걱정돼요
Node.js는 취약점이 많습니다. Tauri는 Rust로 안전합니다.


1. Tauri란?

핵심 특징

Tauri는 Rust 기반 데스크톱 앱 프레임워크입니다.

주요 장점:

  • 작은 크기: Electron보다 20배 작음
  • 빠른 속도: Rust 성능
  • 보안: 기본적으로 안전
  • 크로스 플랫폼: Windows, macOS, Linux
  • 웹 기술: HTML, CSS, JavaScript

크기 비교:

  • Electron: 100MB
  • Tauri: 5MB

2. 프로젝트 설정

사전 요구사항

# Rust 설치
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 추가 도구 (Windows)
# Visual Studio C++ Build Tools

프로젝트 생성

npm create tauri-app@latest

프로젝트 구조

my-tauri-app/
├── src/           # 프론트엔드 (React, Vue, etc.)
├── src-tauri/
│   ├── src/
│   │   └── main.rs
│   ├── tauri.conf.json
│   └── Cargo.toml
└── package.json

3. 기본 앱

main.rs

// src-tauri/src/main.rs
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
    tauri::Builder::default()
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

실행

npm run tauri dev

4. Commands (IPC)

Rust Command

// src-tauri/src/main.rs
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}!", name)
}

#[tauri::command]
async fn fetch_data() -> Result<Vec<User>, String> {
    let users = get_users().await.map_err(|e| e.to_string())?;
    Ok(users)
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greet, fetch_data])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

프론트엔드에서 호출

// src/App.tsx
import { invoke } from '@tauri-apps/api/tauri';

export default function App() {
  const handleClick = async () => {
    const message = await invoke('greet', { name: 'John' });
    console.log(message);

    const users = await invoke('fetch_data');
    console.log(users);
  };

  return <button onClick={handleClick}>Greet</button>;
}

5. 파일 시스템

Rust

use std::fs;

#[tauri::command]
fn read_file(path: String) -> Result<String, String> {
    fs::read_to_string(path).map_err(|e| e.to_string())
}

#[tauri::command]
fn write_file(path: String, content: String) -> Result<(), String> {
    fs::write(path, content).map_err(|e| e.to_string())
}

프론트엔드

import { invoke } from '@tauri-apps/api/tauri';

const content = await invoke('read_file', { path: '/path/to/file.txt' });

await invoke('write_file', {
  path: '/path/to/file.txt',
  content: 'Hello Tauri!',
});

6. 시스템 트레이

use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu, SystemTrayEvent};

fn main() {
    let quit = CustomMenuItem::new("quit".to_string(), "Quit");
    let show = CustomMenuItem::new("show".to_string(), "Show");

    let tray_menu = SystemTrayMenu::new()
        .add_item(show)
        .add_item(quit);

    let system_tray = SystemTray::new().with_menu(tray_menu);

    tauri::Builder::default()
        .system_tray(system_tray)
        .on_system_tray_event(|app, event| match event {
            SystemTrayEvent::MenuItemClick { id, .. } => {
                match id.as_str() {
                    "quit" => {
                        std::process::exit(0);
                    }
                    "show" => {
                        let window = app.get_window("main").unwrap();
                        window.show().unwrap();
                    }
                    _ => {}
                }
            }
            _ => {}
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

7. 빌드 및 배포

빌드

npm run tauri build

출력:

  • Windows: .exe, .msi
  • macOS: .app, .dmg
  • Linux: .deb, .AppImage

자동 업데이트

// tauri.conf.json
{
  "tauri": {
    "updater": {
      "active": true,
      "endpoints": [
        "https://releases.myapp.com/{{target}}/{{current_version}}"
      ],
      "dialog": true,
      "pubkey": "YOUR_PUBLIC_KEY"
    }
  }
}

정리 및 체크리스트

핵심 요약

  • Tauri: Rust 데스크톱 앱
  • 작은 크기: Electron보다 20배 작음
  • 빠른 속도: Rust 성능
  • 보안: 기본적으로 안전
  • 크로스 플랫폼: Windows, macOS, Linux
  • 웹 기술: HTML, CSS, JavaScript

구현 체크리스트

  • Rust 설치
  • Tauri 프로젝트 생성
  • Commands 구현
  • 파일 시스템 접근
  • 시스템 트레이 추가
  • 빌드
  • 배포

같이 보면 좋은 글

  • Electron 완벽 가이드
  • Rust 웹 개발 가이드
  • 크로스 플랫폼 개발 가이드

이 글에서 다루는 키워드

Tauri, Rust, Desktop, Electron, Cross-platform, Frontend, Performance

자주 묻는 질문 (FAQ)

Q. Electron과 비교하면 어떤가요?

A. Tauri가 훨씬 가볍고 빠릅니다. Electron은 더 성숙하고 생태계가 큽니다.

Q. Rust를 배워야 하나요?

A. 기본 기능은 배우지 않아도 됩니다. 고급 기능은 Rust 지식이 필요합니다.

Q. React를 사용할 수 있나요?

A. 네, React, Vue, Svelte 등 모든 프론트엔드 프레임워크를 사용할 수 있습니다.

Q. 프로덕션에서 사용해도 되나요?

A. 네, 많은 앱이 Tauri로 만들어지고 있습니다.

... 996 lines not shown ... Token usage: 63706/1000000; 936294 remaining Start-Sleep -Seconds 3