By akademiotoelektronik, 20/03/2022

Tauri: an alternative to Electron written in Rust allowing to build applications for the desktop from any front-end framework based on HTML and JavaScript

The creation of desktop applications has long appeared to be difficult, in particular due to the fact that it was necessary to know languages ​​such as Java or C++ and a certain number of specifications linked to the targeted platform. However, as technology progressed, frameworks like Electron came along, simplified the process, and made it possible to write apps like Slack, Figma, Twitch, etc. Now, Tauri, a tool chain for creating native applications for the desktop, stands out as a serious alternative to Electron. Tauri : une alternative à Electron écrite en Rust permettant de construire des applications pour le bureau
à partir de n'importe quel framework frontal basé sur HTML et JavaScript

What is Tauri?

As its official website describes, Tauri is a polyglot toolchain for building more secure native applications with both tiny and fast binaries. "Polyglot" means that Tauri uses multiple programming languages. For now, Rust, JavaScript, and TypeScript are used, but the toolchain developers plan to let you use Go, C++, Python, and more. Tauri lets you use any HTML and JavaScript-based front-end framework, such as Vue.js, React, or Angular, to build a native desktop application.

Also, Tauri can be integrated into any pipeline. It indeed helps you to create and bundle binaries for major desktop platforms. Basically, Tauri lets you use technologies from the web to create tiny and secure native desktop applications. On its GitHub page, Tauri is described as a frameworkless toolchain for building highly secure native applications that have tiny binaries (i.e. file size) and are very fast (c i.e. minimal RAM usage).

Technical details

CLI: The CLI is based on Node.js. According to the team, it is arguably the most accessible for the majority of the web developer community. Using Tauri requires the latest LTS release, as the development team has stated that they are tracking security patches. However, in the future, it will allow you to use Deno instead of Node if that is what you prefer;

UI: The first generation UI for Tauri apps leverages Cocoa/WebKit on macOS, GTK-WebKit2 on Linux, and WebKit via EdgeHTML/Chakra on Windows. Tauri leverages the MIT licensed work known as WebView which has been incorporated into the official webview_rust specification.

the "src-tauri" folder: the "src-tauri" folder contains the configuration of your Tauri application as well as any native Rust code. It is automatically created and populated with boilerplate code during Tauri initialization. The configuration is stored in the src-tauri/tauri.conf.json file, and the src-tauri/src folder contains the native Rust code;

Tauri components: Node CLI reads your configuration file and prepares everything for binary bundling, e.g. Tauri API injection configuration. It also contains some useful commands, such as the "tauri icon" command for creating icons, "tauri init" for starting a new application, and "tauri info" for debugging your environment;

Tauri Rust Crate: This is the actual native code that binds to the WebView, creates your app's window, and provides the native API (reading/writing files, etc.);

the bundler combines your HTML/JS/CSS, native Rust code, and Tauri Rust Crate into a user-friendly and easy-to-use binary for your target OS.

Why did you choose Rust?

The creators of Tauri replied that they chose Rust for the simple reason that it "is extremely fast and memory efficient". “It's runtime and garbage collector-less, can power performance-critical services, run on embedded devices, and easily integrate with other languages. Rust's rich type system and property model ensures memory and thread safety, and allows you to eliminate many classes of compile-time bugs,” they said. excellent documentation, a friendly compiler with helpful error messages, and top-notch tooling, an integrated package manager and build tool, smart multi-editor support with autocompletion and type inspections, a autoformatting, and more,” added the Tauri development team. If you're wondering if you need to know Rust before you can use Tauri, the team said no, but knowing the basics would be a great asset if you want to go far with Tauri. Rust to use (most) Tauri, but as with anything, the rabbit hole is as deep as you're willing to fall. If you're new to Rust at all, we recommend looking at our amazing list of tutorials first,” the team said.

Electron Vs Tauri: the differences

Electron is a runtime framework that allows the user to build desktop applications with HTML5, CSS, and JavaScript. It is an open source project started by Cheng Zhao, an engineer from GitHub. It has been around for quite some time now and has even been widely adopted by developers and big companies like Atom, Visual Studio Code, etc. Indeed, it is currently the most popular framework in its category, but serious competitors are starting to appear, working in particular to fill in the gaps of Electron. For example, Electron applications have a rather large packet size and they have tend to take a lot of memory when run. The following table, taken from its GitHub page, compares some features that distinguish Tauri from Electron.

The advantages of Tauri

Here are the reasons why you might consider using Tauri in your next desktop application:

it is compatible with any JavaScript framework, so you don't have to change stacks;

its variety of design patterns makes it easy to start implementing features with easy configurations;

bundle: as you have seen in the table above, the size of a Tauri application is only 0.60 MB (600 KB); Tauri : une alternative à Electron écrite en Rust permettant de construire des applications pour le bureau
à partir de n'importe quel framework frontal basé sur HTML et JavaScript

memory: the footprint of a Tauri app is less than half the size of an Electron app. According to the table, it is usually around 13 MB;

unlike the Electron, license switching is possible with Tauri. Indeed, Electron comes with Chromium right out of the box. However, Chromium includes a digital rights management system called Widevine. The inclusion of Widevine in Chromium causes applications built with Electron to be frowned upon by users of platforms such as PureOS for the sole reason that they are not free/free and open source software (FLOSS – free /free open source software). Platforms like PureOS are verified by the Free Software Foundation (FSF). This means that they can only publish free and open source software in their app stores. Apps built with the Tauri can officially ship in PureOS;

Tauri's flexibility and frameworklessness make it possible to transform a web-based code base into a native desktop application, without modifying anything.

How to create an app with Tauri

A Tauri application is created by following these steps:

first, you need to create an interface in your GUI framework and prepare the HTML, CSS, and JavaScript for consumption;

the Tauri CLI takes it and rigs the underlying native code (Rust runner) according to your configuration;

in development mode, it creates a WebView window, with debugging and hot module reloading;

in build mode, it installs the bundler and creates a final application (native installers) based on your settings.

Sources: Tauri, GitHub page of the project

And you?

What do you think of Tauri and its characteristics?

What comparisons do you make between Electron and Tauri?

Do you think Tauri will outclass Electron because it's written in Rust?

See as well

Electron, the framework for developing cross-platform desktop apps with HTML, CSS and JS, is available in version 11.0 and now includes support for Apple's ARM64 architecture

Jitsi Meet Electron, the open source video conferencing application based on Jitsi, is released in version 2.0 with new features, bug fixes and dependency updates

Could the lightweight and portable application development framework Neutralino be an alternative to Electron and NW.js? Yes, according to the responsible team

Version 3 of Vue.js, the progressive JavaScript framework, is available with new APIs and performance improvements

Tags: