Skip to content

Commit 79cb2bf

Browse files
committed
docs: add Linux platform documentation
1 parent fe3d252 commit 79cb2bf

49 files changed

Lines changed: 1348 additions & 17 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎content/best-practices/platform-file-split-or-not.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ Using platform files:
2323

2424
- `file.ios.ts`
2525
- `file.android.ts`
26+
- `file.linux.ts` (when targeting [Linux](/guide/linux/))
2627

2728
The advent of tree shaking and webpack builds does away with quite a bit of worry in this area however there's a few things to consider here.
2829

2930
## Conditional with tree shaking
3031

31-
When speaking of tree shaking ever since NativeScript 7, you've been able to use `__ANDROID__` or `global.isIOS` and anytime those are used as conditional splits in your code, only the applicable code for the platform that's being built would actually end up in your compiled code alleviating a lot of concern here.
32+
When speaking of tree shaking ever since NativeScript 7, you've been able to use `__ANDROID__`, `__LINUX__` or `global.isIOS` and anytime those are used as conditional splits in your code, only the applicable code for the platform that's being built would actually end up in your compiled code alleviating a lot of concern here.
3233

3334
## Future maintenance
3435

‎content/configuration/nativescript.md‎

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
id: string = 'com.mycompany.myapp'
3838
```
3939

40-
Controls the Application ID of your app, this setting can be overridden per platform via [ios.id](#ios-id) and [android.id](#android-id).
40+
Controls the Application ID of your app, this setting can be overridden per platform via [ios.id](#ios-id), [android.id](#android-id) and [linux.id](#linux-id).
4141

4242
### main
4343

@@ -163,6 +163,14 @@ ios: Object = {}
163163

164164
See [iOS Configuration Reference](#ios-configuration-reference)
165165

166+
### linux
167+
168+
```ts
169+
linux: Object = {}
170+
```
171+
172+
See [Linux Configuration Reference](#linux-configuration-reference)
173+
166174
### hooks
167175

168176
```ts
@@ -508,6 +516,109 @@ ios: {
508516
}
509517
```
510518

519+
## Linux Configuration Reference
520+
521+
::: warning Experimental
522+
The Linux platform is experimental. See [Developing for Linux](/guide/linux/).
523+
:::
524+
525+
### <span>linux.id</span>
526+
527+
```ts
528+
linux.id: string = 'org.mycompany.MyApp';
529+
```
530+
531+
Controls the app id on Linux, this setting overrides the value set in [id](#id). It names the app's desktop entry (`<id>.desktop`), icon and install folder, and must be a reverse DNS name (letters, digits, `_` and `-`, separated by dots).
532+
533+
### linux.window
534+
535+
```ts
536+
linux.window: {
537+
width?: number
538+
height?: number
539+
minWidth?: number
540+
minHeight?: number
541+
resizable?: boolean
542+
title?: string
543+
} = {}
544+
```
545+
546+
The initial size of the app's windows, in logical pixels, and their minimum size. Defaults to `1024` by `768`, resizable, with the app name as the title.
547+
548+
```ts
549+
export default {
550+
// ...
551+
linux: {
552+
window: {
553+
width: 1280,
554+
height: 800,
555+
minWidth: 480,
556+
minHeight: 360,
557+
},
558+
},
559+
} as NativeScriptConfig
560+
```
561+
562+
### linux.appearance
563+
564+
```ts
565+
linux.appearance: 'system' | 'light' | 'dark' = 'system';
566+
```
567+
568+
Keeps the app's native controls light or dark, whatever the desktop uses. Defaults to `'system'`, which follows the desktop.
569+
570+
### linux.v8Flags
571+
572+
```ts
573+
linux.v8Flags: string = '--expose_gc';
574+
```
575+
576+
V8 flags set before the runtime starts. During development, the `NS_V8_FLAGS` environment variable adds to them.
577+
578+
### linux.bundle
579+
580+
```ts
581+
linux.bundle: boolean = true;
582+
```
583+
584+
When enabled, **release** builds pack the app's files into one read-only `app.nsbundle` next to the executable. App code reads it with the usual file APIs, and writing to app files fails. Debug builds always use a plain folder. Defaults to `true`.
585+
586+
### linux.bundleUnpack
587+
588+
```ts
589+
linux.bundleUnpack: string[] = ['fonts/**'];
590+
```
591+
592+
Globs, relative to the app folder, of files that are kept as real files in `app.nsbundle.unpacked`, for code that opens them by path. Native addons (`.node` and `.so` files) are always unpacked. Defaults to `['fonts/**']`.
593+
594+
### linux.sourceProtect
595+
596+
```ts
597+
linux.sourceProtect: boolean = true;
598+
```
599+
600+
When enabled, **release** builds encrypt the `app.nsbundle` with a key generated for each build and embedded in the executable, so the app's sources aren't shipped readable. Defaults to `false`.
601+
602+
This can be overridden per build with `--source-protect` or `--no-source-protect`. The encryption key can be provided with `--source-protect-key-hex <key>` or the `NS_LINUX_BUNDLE_KEY` environment variable. If source protection is requested and can't be applied, the build fails.
603+
604+
### linux.fuses
605+
606+
```ts
607+
linux.fuses: {
608+
bundleIntegrity?: boolean
609+
onlyLoadAppFromBundle?: boolean
610+
inspector?: boolean
611+
envOverrides?: boolean
612+
} = {}
613+
```
614+
615+
Settings written into the executable of **release** builds:
616+
617+
- `bundleIntegrity` - refuse an `app.nsbundle` that doesn't match the build. Defaults to `true` when the app is bundled.
618+
- `onlyLoadAppFromBundle` - only run the app from `app.nsbundle`, never from a plain app folder. Defaults to `true` when the app is bundled.
619+
- `inspector` - allow attaching a debugger with `--inspect`. Defaults to `false`.
620+
- `envOverrides` - honor the runtime's command line flags and environment variables (such as `NS_V8_FLAGS`). Defaults to `false`.
621+
511622
## Hooks Configuration Reference
512623

513624
```ts

‎content/configuration/vite.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ Additional env flags that are passed by the CLI automatically
381381
- `--env.android` - `true` when running on Android
382382
- `--env.ios` - `true` when running on iOS
383383
- `--env.visionos` - `true` when running on visionOS
384-
- `--env.platform=<platform>` - for specifying the platform to use. Can be `android`, `ios`, or `visionos`.
384+
- `--env.linux` - `true` when running on Linux
385+
- `--env.platform=<platform>` - for specifying the platform to use. Can be `android`, `ios`, `visionos`, or `linux`.
385386
- `--env.hmr` - `true` when building with HMR enabled
386387

387388
## Global "magic" variables
@@ -418,6 +419,12 @@ We define a few useful globally available variables that you can use to alter lo
418419
// we are running on an Apple platform
419420
}
420421
```
422+
- `__LINUX__`, `true` when the platform is Linux
423+
```ts
424+
if (__LINUX__) {
425+
// we are running on Linux
426+
}
427+
```
421428

422429
::: details The following variables are also defined, but are primarily intended to be used by NativeScript Core internally, or plugins that wish to use these.
423430

‎content/configuration/webpack.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ Additional env flags that are usually passed by the CLI automatically
9696
- `--env.nativescriptLibPath` - path to the currently running CLI's library.
9797
- `--env.android` - `true` when running on android
9898
- `--env.ios` - `true` when running on ios
99-
- `--env.platform=<platform>` - for specifying the platform to use. Can be `android` or `ios`, or a custom platform in the future.
99+
- `--env.linux` - `true` when running on Linux
100+
- `--env.platform=<platform>` - for specifying the platform to use. Can be `android`, `ios`, `linux`, or a custom platform.
100101
- `--env.hmr` - `true` when building with HMR enabled
101102

102103
## Global "magic" variables
@@ -121,6 +122,12 @@ We define a few useful globally available variables that you can use to alter lo
121122
// we are running on iOS
122123
}
123124
```
125+
- `__LINUX__` (also available as `global.isLinux`) - `true` when the platform is Linux
126+
```ts
127+
if (__LINUX__) {
128+
// we are running on Linux
129+
}
130+
```
124131

125132
::: details The following variables are also defined, but are primarily intended to be used by NativeScript Core internally, or plugins that wish to use these.
126133

‎content/guide/adding-native-code.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ns native add java com.company.OtherAwesomeClass
3030
1. You can also manually add native code to [App_Resources](/project-structure/app-resources):
3131
- [Adding Java/Kotlin code to an application](/guide/native-code/android)
3232
- [Adding ObjectiveC/Swift Code to an application](/guide/native-code/ios)
33+
- [Adding C/C++ code to a Linux application](/guide/native-code/linux)
3334
2. Optionally [generate TypeScript types for the added APIs](/guide/native-code/generate-typings)
3435

3536
Additionally, NativeScript also supports Jetpack Compose and SwiftUI through plugins.

‎content/guide/cli-basics.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Example output:
5757
| 3 | iPhone 14 Pro | iOS | XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | Emulator | Connected | Local |
5858
```
5959

60+
On a Linux host, the local machine is also listed as a `Linux` device. `ns run linux` runs the app on it (see [Developing for Linux](/guide/linux/)).
61+
6062
## Setting the default package manager
6163

6264
To set the default package manager that the CLI uses (unless overridden in [nativescript.config.ts](/project-structure/nativescript-config#cli-packagemanager)):

‎content/guide/debugging.md‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ contributors:
55
- rigor789
66
---
77

8-
There are multiple ways to debug issues in your apps, starting with the simplest form using `console.logs`. For more complex issues, you may need to use an actual debugger, like Chrome DevTools, XCode developer tools and instruments or the Android Studio developer tools.
8+
There are multiple ways to debug issues in your apps, starting with the simplest form using `console.logs`. For more complex issues, you may need to use an actual debugger, like Chrome DevTools, XCode developer tools and instruments, the Android Studio developer tools or GDB on Linux.
99

1010
## Console
1111

@@ -41,7 +41,7 @@ console.timeEnd('myLabel')
4141
To start a Chrome debugging session, run your app in debug mode:
4242

4343
```bash
44-
ns debug android|ios
44+
ns debug android|ios|linux
4545
```
4646

4747
The `ns debug` command builds and deploys the app on a connected device or emulator, in case you have multiple devices available you will need to pick one from a list, or pass in the `--device <id>` from `ns devices`.
@@ -163,3 +163,58 @@ Since NativeScript follows a standard gradle/android application structure, you
163163
- [Android Studio: Layout Inspector](https://developer.android.com/studio/debug/layout-inspector)
164164
- [Android Studio: view Logcat logs](https://developer.android.com/studio/debug/am-logcat)
165165
- [Androud Studio: Debug your app](https://developer.android.com/studio/debug#startdebug)
166+
167+
## Debugging on Linux
168+
169+
::: warning Experimental
170+
The Linux platform is experimental. See [Developing for Linux](/guide/linux/).
171+
:::
172+
173+
### Chrome DevTools
174+
175+
Start a debug session on the local machine with:
176+
177+
```bash
178+
ns debug linux
179+
```
180+
181+
The command builds and launches the app with the V8 inspector enabled. Once the inspector is listening, a URL is printed to the console:
182+
183+
```bash
184+
To start debugging, open the following URL in Chrome:
185+
devtools://devtools/bundled/inspector.html?ws=127.0.0.1:9229/<id>
186+
```
187+
188+
Open the printed URL in Google Chrome or Chromium to attach to the debugger session. The inspector listens on port `9229`, which can be changed with the `NS_LINUX_INSPECTOR_PORT` environment variable.
189+
190+
The app also shows up in `chrome://inspect`, and other clients that speak the Chrome DevTools Protocol, such as the VS Code JavaScript debugger, can attach to `127.0.0.1:9229`.
191+
192+
The same options as on the other platforms are supported:
193+
194+
- `--debug-brk` - pauses on the first line of JavaScript until the debugger connects.
195+
- `--start` - attaches to an app that is already running with the debugger enabled (started with `ns debug linux`), without restarting it.
196+
- `--timeout` - number of seconds the CLI waits for the inspector to start. Default is 90 seconds.
197+
198+
`ns run linux` doesn't start the inspector, use `ns debug linux` instead. The debugger is only available with the default `@nativescript/linux` (V8) runtime, and it is turned off in release builds unless the [`inspector` fuse](/configuration/nativescript#linux-fuses) is enabled.
199+
200+
The debugger, console, sources, CPU profiling and memory snapshots are provided by V8's inspector. In CPU profiles, time spent in C functions is shown under the C function's name. Network requests made with `@nativescript/core` HTTP APIs are shown in the **Network** tab.
201+
202+
### Console output
203+
204+
`ns run linux` and `ns debug linux` stream the app's standard output and standard error (including `console` calls and uncaught errors) to your terminal. Run the CLI with `--log trace` to also see when the app starts and exits, with its exit code or signal.
205+
206+
An app started from the desktop's app launcher writes its output wherever the desktop session sends it, usually the systemd journal (`journalctl --user -f`).
207+
208+
### Debugging native code with GDB
209+
210+
To debug C code (your own [native code](/guide/native-code/linux), GTK or the runtime), attach [GDB](https://www.sourceware.org/gdb/) to the running app:
211+
212+
```bash
213+
ns run linux
214+
# in another terminal
215+
gdb -p $(pgrep -n <ProjectName>)
216+
```
217+
218+
Native code in debug builds is compiled with `-O0 -g`, so GDB can show its sources and variables.
219+
220+
To debug GTK warnings and critical messages, set `G_DEBUG=fatal-criticals` in the environment before running the CLI. The app then stops at the first critical message, and GDB shows where it came from.

0 commit comments

Comments
 (0)