Skip to content

Packaging Tauri

The Cargo Packager can be used to package, bundle and update Tauri apps.

Creating a Tauri App Package

You can create a Tauri app bundle with the following steps. For this, you may Create a new Tauri app or can use an existing Tauri app.

1. Install the Cargo Packager

Cargo packager can be installed with the help of the following commands, depending on the package manager you chose in the previous step:

cargo install cargo-packager --locked

Now, Packager is installed in your application. Next you will add the configuration to use Packager.

2. Adding the Configuration

Now, you must add configuration to your application. For this, you have to edit the src-tauri/Cargo.toml file and add the following snippet to it.

src-tauri/Cargo.toml
[package.metadata.packager]
before-packaging-command = "cargo tauri build"
product-name = "Tauri example"
identifier = "com.tauri.example"
resources = [ "icons/**" ]
icons = [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico",
]

Additionally, you must configure the dependencies required by Tauri:

src-tauri/Cargo.toml
[package.metadata.packager.deb]
depends = ["libgtk-3-0", "libwebkit2gtk-4.1-0", "libayatana-appindicator3-1"]
section = "rust"
[package.metadata.packager.appimage]
bins = ["/usr/bin/xdg-open"]
libs = [
"WebKitNetworkProcess",
"WebKitWebProcess",
"libwebkit2gtkinjectedbundle.so",
"libayatana-appindicator3.so.1",
]
[package.metadata.packager.appimage.linuxdeploy-plugins]
"gtk" = "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"
[package.metadata.packager.nsis]
appdata-paths = ["$LOCALAPPDATA/$IDENTIFIER"]
preinstall-section = """
; Setup messages
; English
LangString webview2AbortError ${LANG_ENGLISH} "Failed to install WebView2! The app can't run without it. Try restarting the installer."
LangString webview2DownloadError ${LANG_ENGLISH} "Error: Downloading WebView2 Failed - $0"
LangString webview2DownloadSuccess ${LANG_ENGLISH} "WebView2 bootstrapper downloaded successfully"
LangString webview2Downloading ${LANG_ENGLISH} "Downloading WebView2 bootstrapper..."
LangString webview2InstallError ${LANG_ENGLISH} "Error: Installing WebView2 failed with exit code $1"
LangString webview2InstallSuccess ${LANG_ENGLISH} "WebView2 installed successfully"
Section PreInstall
; Check if Webview2 is already installed and skip this section
${If} ${RunningX64}
ReadRegStr $4 HKLM "SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${Else}
ReadRegStr $4 HKLM "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${EndIf}
ReadRegStr $5 HKCU "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
StrCmp $4 "" 0 webview2_done
StrCmp $5 "" 0 webview2_done
Delete "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
DetailPrint "$(webview2Downloading)"
nsis_tauri_utils::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
Pop $0
${If} $0 == 0
DetailPrint "$(webview2DownloadSuccess)"
${Else}
DetailPrint "$(webview2DownloadError)"
Abort "$(webview2AbortError)"
${EndIf}
StrCpy $6 "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
DetailPrint "$(installingWebview2)"
; $6 holds the path to the webview2 installer
ExecWait "$6 /install" $1
${If} $1 == 0
DetailPrint "$(webview2InstallSuccess)"
${Else}
DetailPrint "$(webview2InstallError)"
Abort "$(webview2AbortError)"
${EndIf}
webview2_done:
SectionEnd
"""

Be sure to replace before-packaging-command with the command you use to build the Tauri app.

For the complete list of configuration options, see the configuration page.

3. Package the App

The Tauri app can now be packaged. You can simply use the given commands as per the Package Manager you used to install Cargo Packager.

cargo packager --release

You can now see your Tauri app nicely packaged by the Packager. The app bundles and installers are generated in the target/release folder.