You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/develop/sidecar.mdx
+58-37Lines changed: 58 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,17 @@ You may need to embed external binaries to add additional functionality to your
9
9
10
10
Binaries are executables written in any programming language. Common use cases are Python CLI applications or API servers bundled using `pyinstaller`.
11
11
12
-
To bundle the binaries of your choice, you can add the `externalBin` property to the `tauri > bundle` object in your `tauri.conf.json`. `externalBin` expects a list of strings targeting binaries either with absolute or relative paths.
12
+
To bundle the binaries of your choice, you can add the `externalBin` property to the `tauri > bundle` object in your `tauri.conf.json`.
13
+
The `externalBin` configuration expects a list of strings targeting binaries either with absolute or relative paths.
13
14
14
-
Here is a sample to illustrate the configuration. This is not a complete `tauri.conf.json` file:
15
+
Here is a Tauri configuration snippet to illustrate a sidecar configuration:
15
16
16
17
```json title="src-tauri/tauri.conf.json"
17
18
{
18
19
"bundle": {
19
20
"externalBin": [
20
21
"/absolute/path/to/sidecar",
21
-
"relative/path/to/binary",
22
+
"../relative/path/to/binary",
22
23
"binaries/my-sidecar"
23
24
]
24
25
}
@@ -27,13 +28,19 @@ Here is a sample to illustrate the configuration. This is not a complete `tauri.
27
28
28
29
:::note
29
30
30
-
The relative paths are relative to the `tauri.conf.json` file which is in the `src-tauri` directory. So `binaries/my-sidecar` would represent `<PROJECT ROOT>/src-tauri/binaries/my-sidecar`.
31
+
The relative paths are relative to the `tauri.conf.json` file which is in the `src-tauri` directory.
32
+
So `binaries/my-sidecar` would represent `<PROJECT ROOT>/src-tauri/binaries/my-sidecar`.
31
33
32
34
:::
33
35
34
-
To make the external binary work on each supported architecture, a binary with the same name and a `-$TARGET_TRIPLE` suffix must exist on the specified path. For instance, `"externalBin": ["binaries/my-sidecar"]` requires a `src-tauri/binaries/my-sidecar-x86_64-unknown-linux-gnu` executable on Linux or `src-tauri/binaries/my-sidecar-aarch64-apple-darwin` on Mac OS with Apple Silicon.
36
+
To make the external binary work on each supported architecture, a binary with the same name and a `-$TARGET_TRIPLE` suffix must exist on the specified path.
37
+
For instance, `"externalBin": ["binaries/my-sidecar"]` requires a `src-tauri/binaries/my-sidecar-x86_64-unknown-linux-gnu` executable on Linux or `src-tauri/binaries/my-sidecar-aarch64-apple-darwin` on Mac OS with Apple Silicon.
35
38
36
-
You can find your **current** platform's `-$TARGET_TRIPLE` suffix by looking at the `host:` property reported by the `rustc -Vv` command.
39
+
You can find your **current** platform's `-$TARGET_TRIPLE` suffix by looking at the `host:` property reported by the following command:
40
+
41
+
```sh
42
+
rustc -Vv
43
+
```
37
44
38
45
If the `grep` and `cut` commands are available, as they should on most Unix systems, you can extract the target triple directly with the following command:
The appropriate way to execute the sidecar is by calling `app.shell().sidecar(name)` where `name` is either `"app"`, `"my-sidecar"` or `"sidecar"`
126
+
instead of `"binaries/app"` for instance.
127
+
128
+
:::
129
+
113
130
You can place this code inside a Tauri command to easily pass the AppHandle or you can store a reference to the AppHandle in the builder script to access it elsewhere in your application.
114
131
115
132
## Running it from JavaScript
@@ -118,14 +135,17 @@ In the JavaScript code, import the `Command` class from the `@tauri-apps/plugin-
The string provided to `Command.sidecar` must match one of the strings defined in the `externalBin` configuration array.
144
+
:::
145
+
126
146
## Passing arguments
127
147
128
-
You can pass arguments to Sidecar commands just like you would for running normal `Command`s.
148
+
You can pass arguments to Sidecar commands just like you would for running normal [Command][std::process::Command].
129
149
130
150
Arguments can be either **static** (e.g. `-o` or `serve`) or **dynamic** (e.g. `<file_path>` or `localhost:<PORT>`). You define the arguments in the exact order in which you'd call them. Static arguments are defined as-is, while dynamic arguments can be defined using a regular expression.
131
151
@@ -157,7 +177,6 @@ First, define the arguments that need to be passed to the sidecar command in `sr
In this guide we are going to package a Node.js application to a self contained binary
12
+
to be used as a sidecar in a Tauri application without requiring the end user to have a Node.js installation.
13
+
This example tutorial is applicable for desktop operating systems only.
14
+
15
+
We recommend reading the general [sidecar guide] first for a deeper understanding of how Tauri sidecars work.
16
+
17
+
In this example we will create a Node.js application that reads input from the command line [process.argv]
18
+
and writes output to stdout using [console.log]. <br/>
19
+
You can leverage alternative inter-process communication systems such as a localhost server, stdin/stdout or local sockets.
20
+
Note that each has their own advantages, drawbacks and security concerns.
21
+
22
+
## Prerequisites
23
+
24
+
An existing Tauri application set up with the shell plugin, that compiles and runs for you locally.
25
+
26
+
:::tip[Create a lab app]
27
+
28
+
If you are not an advanced user it's **highly recommended** that you use the options and frameworks provided here. It's just a lab, you can delete the project when you're done.
29
+
30
+
<CTA />
31
+
32
+
- Project name: `node-sidecar-lab`
33
+
- Choose which language to use for your frontend: `Typescript / Javascript`
34
+
- Choose your package manager: `pnpm`
35
+
- Choose your UI template: `Vanilla`
36
+
- Choose your UI flavor: `Typescript`
37
+
- Would you like to setup the project for mobile as well? `yes`
38
+
39
+
:::
40
+
41
+
:::note
42
+
Please follow the [shell plugin guide](/plugin/shell/) first to set up and initialize the plugin correctly.
43
+
Without the plugin being initialized and configured the example won't work.
44
+
:::
45
+
46
+
## Guide
47
+
48
+
<Steps>
49
+
50
+
1.##### Initialize Sidecar Project
51
+
52
+
Let's create a new Node.js project to contain our sidecar implementation.
53
+
Create a new directory **in your Tauri application root folder** (in this example we will call it `sidecar-app`)
54
+
and run the `init` command of your preferred Node.js package manager inside the directory:
0 commit comments