@ng-native/desktop 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
package/bin/host.mjs
CHANGED
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
import { spawn, spawnSync } from 'node:child_process';
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
9
|
import {
|
|
10
|
+
chmodSync,
|
|
10
11
|
cpSync,
|
|
11
12
|
existsSync,
|
|
13
|
+
lstatSync,
|
|
12
14
|
mkdirSync,
|
|
15
|
+
readdirSync,
|
|
13
16
|
readFileSync,
|
|
17
|
+
readlinkSync,
|
|
14
18
|
renameSync,
|
|
15
19
|
rmSync,
|
|
20
|
+
symlinkSync,
|
|
16
21
|
writeFileSync,
|
|
17
22
|
} from 'node:fs';
|
|
18
23
|
import { createRequire } from 'node:module';
|
|
@@ -23,7 +28,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
23
28
|
import { desktopAppConfig } from './app-config.mjs';
|
|
24
29
|
import { desktopLinks, linkWarnings } from './autolink.mjs';
|
|
25
30
|
import { choosePrebuilt, fetchPrebuilt, readManifest } from './prebuilt.mjs';
|
|
26
|
-
import { checkToolchain, FIRST_BUILD_NOTE } from './toolchain.mjs';
|
|
31
|
+
import { checkToolchain, FIRST_BUILD_NOTE, LINUX_FIRST_BUILD_NOTE } from './toolchain.mjs';
|
|
27
32
|
|
|
28
33
|
export const packageDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
29
34
|
|
|
@@ -72,6 +77,8 @@ export const HOST_LIBRARIES = [
|
|
|
72
77
|
*/
|
|
73
78
|
export const system = {
|
|
74
79
|
platform: process.platform,
|
|
80
|
+
/** This machine's architecture, as Node names it (`x64`, `arm64`). */
|
|
81
|
+
arch: process.arch,
|
|
75
82
|
env: /** @type {Record<string, string | undefined>} */ (process.env),
|
|
76
83
|
cwd: () => process.cwd(),
|
|
77
84
|
/** @param {string} from */
|
|
@@ -97,12 +104,14 @@ export const system = {
|
|
|
97
104
|
/**
|
|
98
105
|
* @param {string} command
|
|
99
106
|
* @param {string[]} args
|
|
100
|
-
* @param {{ capture?: boolean, env?: Record<string, string> }} [options] `env`
|
|
101
|
-
* this process's environment
|
|
107
|
+
* @param {{ capture?: boolean, quiet?: boolean, env?: Record<string, string> }} [options] `env`
|
|
108
|
+
* is added to this process's environment; `quiet` drops the command's stderr, for a probe
|
|
109
|
+
* whose answer is its status and stdout
|
|
102
110
|
*/
|
|
103
|
-
run(command, args, { capture = false, env } = {}) {
|
|
111
|
+
run(command, args, { capture = false, quiet = false, env } = {}) {
|
|
112
|
+
const stderr = quiet ? 'ignore' : 'inherit';
|
|
104
113
|
const result = spawnSync(command, args, {
|
|
105
|
-
stdio: capture ? ['inherit', 'pipe',
|
|
114
|
+
stdio: capture ? ['inherit', 'pipe', stderr] : ['inherit', 'inherit', stderr],
|
|
106
115
|
encoding: 'utf8',
|
|
107
116
|
...(env && { env: { ...process.env, ...env } }),
|
|
108
117
|
});
|
|
@@ -188,6 +197,39 @@ export const system = {
|
|
|
188
197
|
},
|
|
189
198
|
/** @param {string} file */
|
|
190
199
|
readFile: (file) => readFileSync(file, 'utf8'),
|
|
200
|
+
/** @param {string} dir */
|
|
201
|
+
mkdir: (dir) => mkdirSync(dir, { recursive: true }),
|
|
202
|
+
/** @param {string} file */
|
|
203
|
+
readBytes: (file) => new Uint8Array(readFileSync(file)),
|
|
204
|
+
/**
|
|
205
|
+
* Every file and symbolic link under `dir`, by its path from there with `/` between parts, in
|
|
206
|
+
* order: a file with its permissions, a link with what it points to.
|
|
207
|
+
*
|
|
208
|
+
* @param {string} dir
|
|
209
|
+
* @returns {{ path: string, mode: number, link?: string }[]}
|
|
210
|
+
*/
|
|
211
|
+
files(dir) {
|
|
212
|
+
return readdirSync(dir, { recursive: true, encoding: 'utf8' })
|
|
213
|
+
.sort()
|
|
214
|
+
.flatMap((name) => {
|
|
215
|
+
const file = path.join(dir, name);
|
|
216
|
+
const stat = lstatSync(file);
|
|
217
|
+
const at = name.split(path.sep).join('/');
|
|
218
|
+
if (stat.isSymbolicLink()) return [{ path: at, mode: 0o777, link: readlinkSync(file) }];
|
|
219
|
+
return stat.isFile() ? [{ path: at, mode: stat.mode & 0o7777 }] : [];
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* Makes `file` a symbolic link to `target`, making the folder it goes in.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} target
|
|
226
|
+
* @param {string} file
|
|
227
|
+
*/
|
|
228
|
+
symlink(target, file) {
|
|
229
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
230
|
+
rmSync(file, { force: true });
|
|
231
|
+
symlinkSync(target, file);
|
|
232
|
+
},
|
|
191
233
|
/** @param {string} file the file's SHA-256, in hex */
|
|
192
234
|
sha256: (file) => createHash('sha256').update(readFileSync(file)).digest('hex'),
|
|
193
235
|
/**
|
|
@@ -199,7 +241,7 @@ export const system = {
|
|
|
199
241
|
},
|
|
200
242
|
/**
|
|
201
243
|
* @param {string} file
|
|
202
|
-
* @param {string} text
|
|
244
|
+
* @param {string | Uint8Array} text
|
|
203
245
|
*/
|
|
204
246
|
writeFile(file, text) {
|
|
205
247
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
@@ -211,24 +253,27 @@ export const system = {
|
|
|
211
253
|
},
|
|
212
254
|
};
|
|
213
255
|
|
|
214
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* @typedef {import('./app-config.mjs').ExpoConfig} ExpoConfig
|
|
258
|
+
*/
|
|
215
259
|
|
|
216
260
|
/**
|
|
217
|
-
* Throws a usage error naming the fix when the app's Expo config cannot run on
|
|
218
|
-
*
|
|
219
|
-
*
|
|
261
|
+
* Throws a usage error naming the fix when the app's Expo config cannot run on a desktop OS:
|
|
262
|
+
* without the OS in `expo.platforms`, Metro does not bundle for it, and without the experiment Expo
|
|
263
|
+
* drops it from the list without a word.
|
|
220
264
|
*
|
|
221
265
|
* @param {ExpoConfig} config
|
|
266
|
+
* @param {import('./autolink.mjs').DesktopOs} [os]
|
|
222
267
|
*/
|
|
223
|
-
export function checkExpoConfig(config) {
|
|
224
|
-
if (!config.platforms?.includes(
|
|
268
|
+
export function checkExpoConfig(config, os = 'macos') {
|
|
269
|
+
if (!config.platforms?.includes(os)) {
|
|
225
270
|
throw new UsageError(
|
|
226
|
-
|
|
271
|
+
`The app's Expo config does not list ${os}. Add "${os}" to expo.platforms in app.json and set expo.experiments.outOfTreePlatforms to true.`,
|
|
227
272
|
);
|
|
228
273
|
}
|
|
229
274
|
if (!config.experiments?.outOfTreePlatforms) {
|
|
230
275
|
throw new UsageError(
|
|
231
|
-
|
|
276
|
+
`The app's Expo config lists ${os} without expo.experiments.outOfTreePlatforms, so Expo ignores it. Set expo.experiments.outOfTreePlatforms to true in app.json.`,
|
|
232
277
|
);
|
|
233
278
|
}
|
|
234
279
|
}
|
|
@@ -237,7 +282,7 @@ export function checkExpoConfig(config) {
|
|
|
237
282
|
* @param {typeof system} sys
|
|
238
283
|
* @param {string} cwd
|
|
239
284
|
*/
|
|
240
|
-
function resolveReactNative(sys, cwd) {
|
|
285
|
+
export function resolveReactNative(sys, cwd) {
|
|
241
286
|
try {
|
|
242
287
|
return sys.resolveReactNative(cwd);
|
|
243
288
|
} catch {
|
|
@@ -248,12 +293,13 @@ function resolveReactNative(sys, cwd) {
|
|
|
248
293
|
}
|
|
249
294
|
|
|
250
295
|
/**
|
|
251
|
-
* The app's Expo config, checked for
|
|
296
|
+
* The app's Expo config, checked for a desktop OS.
|
|
252
297
|
*
|
|
253
298
|
* @param {typeof system} sys
|
|
254
299
|
* @param {string} cwd
|
|
300
|
+
* @param {import('./autolink.mjs').DesktopOs} [os]
|
|
255
301
|
*/
|
|
256
|
-
export function readExpoConfig(sys, cwd) {
|
|
302
|
+
export function readExpoConfig(sys, cwd, os = 'macos') {
|
|
257
303
|
/** @type {ExpoConfig} */
|
|
258
304
|
let config;
|
|
259
305
|
try {
|
|
@@ -263,7 +309,7 @@ export function readExpoConfig(sys, cwd) {
|
|
|
263
309
|
`Could not read the app's Expo config in ${cwd}: ${error instanceof Error ? error.message : error}`,
|
|
264
310
|
);
|
|
265
311
|
}
|
|
266
|
-
checkExpoConfig(config);
|
|
312
|
+
checkExpoConfig(config, os);
|
|
267
313
|
return config;
|
|
268
314
|
}
|
|
269
315
|
|
|
@@ -282,19 +328,25 @@ export function linkFile(appDir) {
|
|
|
282
328
|
* for the build, a warning for each dependency the build leaves without its native code, and the
|
|
283
329
|
* host built (a no-op when nothing changed).
|
|
284
330
|
*
|
|
331
|
+
* The macOS host builds on a Mac. A Linux host comes prebuilt for its architecture, or builds on
|
|
332
|
+
* Linux of that architecture.
|
|
333
|
+
*
|
|
285
334
|
* @param {typeof system} sys
|
|
286
|
-
* @param {{ universal: boolean, release?: boolean, expo?: ExpoConfig }} options
|
|
287
|
-
* the
|
|
288
|
-
*
|
|
289
|
-
*
|
|
335
|
+
* @param {{ universal: boolean, release?: boolean, expo?: ExpoConfig, os?: import('./autolink.mjs').DesktopOs, arch?: LinuxArch }} options
|
|
336
|
+
* `os` is the desktop OS the host is for (macos unless said), which picks the native code the app
|
|
337
|
+
* links (`autolink.mjs`); `arch` a Linux host's architecture, this machine's unless said;
|
|
338
|
+
* `release` builds the host as a packaged app ships it, without the core tests or the debugger,
|
|
339
|
+
* and takes the release prebuilt host where one fits (the debug one otherwise); `expo` is the
|
|
340
|
+
* app's config when the caller has read it already
|
|
290
341
|
*/
|
|
291
342
|
export function prepareHost(sys, options) {
|
|
292
|
-
|
|
343
|
+
const os = options.os ?? 'macos';
|
|
344
|
+
if (os === 'macos' && sys.platform !== 'darwin') {
|
|
293
345
|
throw new UsageError('The desktop host runs on macOS only for now.');
|
|
294
346
|
}
|
|
295
347
|
const cwd = sys.cwd();
|
|
296
348
|
const reactNative = resolveReactNative(sys, cwd);
|
|
297
|
-
const expo = options.expo ?? readExpoConfig(sys, cwd);
|
|
349
|
+
const expo = options.expo ?? readExpoConfig(sys, cwd, os);
|
|
298
350
|
const config = desktopAppConfig(expo);
|
|
299
351
|
if (/[/\\]/.test(config.name) || config.name === '.' || config.name === '..') {
|
|
300
352
|
throw new UsageError(
|
|
@@ -303,12 +355,33 @@ export function prepareHost(sys, options) {
|
|
|
303
355
|
);
|
|
304
356
|
}
|
|
305
357
|
const deny = config.options.deny ?? [];
|
|
306
|
-
const
|
|
358
|
+
const { file, linked, hostLibraries } = writeLinks(sys, { cwd, os, deny });
|
|
359
|
+
const { dir: buildDir, prebuilt } = hostBuildDir(sys, reactNative, {
|
|
360
|
+
...options,
|
|
361
|
+
os,
|
|
362
|
+
arch: options.arch ?? linuxArch(sys),
|
|
363
|
+
deny,
|
|
364
|
+
linked,
|
|
365
|
+
hostLibraries,
|
|
366
|
+
link: file,
|
|
367
|
+
});
|
|
368
|
+
return { cwd, expo, config, buildDir, prebuilt, reactNative };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Finds the native code the app links for `os`, warns about each dependency the build leaves
|
|
373
|
+
* without its own, and writes the links for the build (`linkFile`), every time, so a library
|
|
374
|
+
* removed or denied leaves the build with the rest.
|
|
375
|
+
*
|
|
376
|
+
* @param {typeof system} sys
|
|
377
|
+
* @param {{ cwd: string, os: import('./autolink.mjs').DesktopOs, deny: readonly string[] }} app
|
|
378
|
+
*/
|
|
379
|
+
function writeLinks(sys, { cwd, os, deny }) {
|
|
380
|
+
const links = sys.links(cwd, { os, deny: [...deny], builtIn: HOST_LIBRARIES });
|
|
307
381
|
for (const line of linkWarnings(links)) sys.warn(line);
|
|
308
|
-
// Written every time, so a library removed or denied leaves the build with the rest.
|
|
309
382
|
const file = linkFile(cwd);
|
|
310
383
|
const { libraries, appModules } = links;
|
|
311
|
-
sys.writeFile(file, `${JSON.stringify({ version: 1, libraries, appModules }, null, 2)}\n`);
|
|
384
|
+
sys.writeFile(file, `${JSON.stringify({ version: 1, os, libraries, appModules }, null, 2)}\n`);
|
|
312
385
|
// Where autolinking found each host library, under a dependency's node_modules too, else where
|
|
313
386
|
// it resolves from the app (a peer dependency the package manager installed, which the walk
|
|
314
387
|
// does not follow).
|
|
@@ -317,22 +390,143 @@ export function prepareHost(sys, options) {
|
|
|
317
390
|
const dir = found.get(name) ?? sys.resolvePackage(cwd, name);
|
|
318
391
|
return dir === null ? [] : [{ name, dir }];
|
|
319
392
|
});
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
393
|
+
return { file, linked: libraries.length + appModules.length, hostLibraries };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The prebuilt host that fits, or the one built from source, and which it is. A Linux host builds
|
|
398
|
+
* only on Linux of its own architecture, so it throws for another.
|
|
399
|
+
*
|
|
400
|
+
* @param {typeof system} sys
|
|
401
|
+
* @param {string} reactNative
|
|
402
|
+
* @param {{ universal: boolean, release?: boolean, os: import('./autolink.mjs').DesktopOs, arch: LinuxArch, deny: readonly string[], linked: number, hostLibraries: { name: string, dir: string }[], link: string }} build
|
|
403
|
+
*/
|
|
404
|
+
function hostBuildDir(sys, reactNative, build) {
|
|
405
|
+
const { os, arch, hostLibraries } = build;
|
|
406
|
+
const prebuilt = prebuiltHost(sys, reactNative, {
|
|
407
|
+
// A packaged app ships the Release host; a dev run gets the one with the debugger.
|
|
408
|
+
flavour: build.release ? 'release' : 'debug',
|
|
409
|
+
deny: build.deny,
|
|
410
|
+
linked: build.linked,
|
|
411
|
+
hostLibraries,
|
|
412
|
+
os,
|
|
413
|
+
arch,
|
|
414
|
+
});
|
|
415
|
+
if (prebuilt.dir) return { dir: prebuilt.dir, prebuilt: true };
|
|
416
|
+
if (os === 'linux' && !buildsLinuxHere(sys, arch)) {
|
|
417
|
+
throw new UsageError(
|
|
418
|
+
`The Linux desktop host builds on Linux only for now, on the architecture it is for, and no ` +
|
|
419
|
+
`prebuilt Linux ${arch} host fits this app (${prebuilt.reason}). Run this on Linux on ${arch}.`,
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
dir: buildHost(
|
|
329
424
|
sys,
|
|
330
425
|
reactNative,
|
|
331
426
|
hostLibraries.map(({ dir }) => dir),
|
|
332
|
-
|
|
333
|
-
|
|
427
|
+
build,
|
|
428
|
+
build.link,
|
|
429
|
+
),
|
|
430
|
+
prebuilt: false,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* @typedef {'x64' | 'arm64'} LinuxArch
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Whether this machine builds the Linux host for `arch`: Linux, on that architecture, which is
|
|
440
|
+
* one of the two a host is built for (a RISC-V machine is not x64).
|
|
441
|
+
*
|
|
442
|
+
* @param {typeof system} sys
|
|
443
|
+
* @param {LinuxArch} arch
|
|
444
|
+
*/
|
|
445
|
+
function buildsLinuxHere(sys, arch) {
|
|
446
|
+
return (
|
|
447
|
+
sys.platform === 'linux' && (sys.arch === 'x64' || sys.arch === 'arm64') && sys.arch === arch
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* This machine's architecture as a Linux host is built for it.
|
|
453
|
+
*
|
|
454
|
+
* @param {typeof system} sys
|
|
455
|
+
* @returns {LinuxArch}
|
|
456
|
+
*/
|
|
457
|
+
export function linuxArch(sys) {
|
|
458
|
+
return sys.arch === 'arm64' ? 'arm64' : 'x64';
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The `hermesc` that compiles a Linux app's bundle, which runs on this machine: on Linux the one
|
|
463
|
+
* beside the host built for this machine's architecture, and on a Mac the one in the prebuilt macOS
|
|
464
|
+
* release host. Both are built from the Hermes the Linux host links, and Hermes bytecode does not
|
|
465
|
+
* depend on the architecture, so one compile serves every package.
|
|
466
|
+
*
|
|
467
|
+
* @param {typeof system} sys
|
|
468
|
+
* @param {{ reactNative: string, hosts: { arch: LinuxArch, buildDir: string }[], expo: ExpoConfig }} build
|
|
469
|
+
* `hosts` are the Linux hosts already prepared for the packages
|
|
470
|
+
*/
|
|
471
|
+
export function linuxHermesCompiler(sys, { reactNative, hosts, expo }) {
|
|
472
|
+
if (sys.platform === 'linux') {
|
|
473
|
+
const native = linuxArch(sys);
|
|
474
|
+
const buildDir =
|
|
475
|
+
hosts.find((host) => host.arch === native)?.buildDir ??
|
|
476
|
+
prepareHost(sys, { os: 'linux', arch: native, release: true, universal: false, expo })
|
|
477
|
+
.buildDir;
|
|
478
|
+
const hermesc = path.join(buildDir, 'gtk', 'hermesc');
|
|
479
|
+
if (!sys.exists(hermesc)) {
|
|
480
|
+
throw new Error(
|
|
481
|
+
`The desktop host in ${buildDir} has no hermesc beside it, so the bundle cannot be ` +
|
|
482
|
+
'compiled to Hermes bytecode. Delete that folder and package again to rebuild it.',
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
return hermesc;
|
|
486
|
+
}
|
|
487
|
+
const version = versionIn(sys, reactNative);
|
|
488
|
+
const manifest = readManifest(readPrebuiltManifest(sys));
|
|
489
|
+
const choice = version
|
|
490
|
+
? choosePrebuilt(manifest, {
|
|
491
|
+
reactNative: version,
|
|
492
|
+
flavour: 'release',
|
|
493
|
+
// hermesc is the same whatever the host links.
|
|
494
|
+
linked: 0,
|
|
495
|
+
libraries: {},
|
|
496
|
+
deny: [],
|
|
497
|
+
env: {},
|
|
498
|
+
os: 'macos',
|
|
499
|
+
})
|
|
500
|
+
: { reason: 'react-native has no version' };
|
|
501
|
+
const dir =
|
|
502
|
+
'host' in choice
|
|
503
|
+
? fetchPrebuilt(
|
|
504
|
+
sys,
|
|
505
|
+
choice.host,
|
|
506
|
+
cacheDir(String(version), { env: sys.env, platform: sys.platform }),
|
|
507
|
+
)
|
|
508
|
+
: null;
|
|
509
|
+
if (!dir) {
|
|
510
|
+
throw new UsageError(
|
|
511
|
+
`Packaging for Linux on a Mac compiles the bundle with the prebuilt macOS host's hermesc, ` +
|
|
512
|
+
`and there is none to use (${'reason' in choice ? choice.reason : 'it did not download'}). ` +
|
|
513
|
+
'Package on Linux instead.',
|
|
334
514
|
);
|
|
335
|
-
|
|
515
|
+
}
|
|
516
|
+
return path.join(dir, 'appkit', 'hermesc');
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* `prebuilt.json`'s text, or nothing when the package has none.
|
|
521
|
+
*
|
|
522
|
+
* @param {typeof system} sys
|
|
523
|
+
*/
|
|
524
|
+
function readPrebuiltManifest(sys) {
|
|
525
|
+
try {
|
|
526
|
+
return sys.readFile(path.join(packageDir, 'prebuilt.json'));
|
|
527
|
+
} catch {
|
|
528
|
+
return '';
|
|
529
|
+
}
|
|
336
530
|
}
|
|
337
531
|
|
|
338
532
|
/**
|
|
@@ -351,23 +545,21 @@ function versionIn(sys, dir) {
|
|
|
351
545
|
}
|
|
352
546
|
|
|
353
547
|
/**
|
|
354
|
-
* The prebuilt host's build folder when `prebuilt.json` has one this
|
|
355
|
-
* `choosePrebuilt`), downloaded into the cache once;
|
|
548
|
+
* The prebuilt host's build folder when `prebuilt.json` has one for this OS and architecture that
|
|
549
|
+
* this app can run on (see `choosePrebuilt`), downloaded into the cache once; otherwise why there
|
|
550
|
+
* is none, and the host is built from source.
|
|
356
551
|
*
|
|
357
552
|
* @param {typeof system} sys
|
|
358
553
|
* @param {string} reactNative
|
|
359
|
-
* @param {{ flavour: import('./prebuilt.mjs').Flavour, deny: readonly string[], linked: number, hostLibraries: { name: string, dir: string }[] }} app
|
|
554
|
+
* @param {{ flavour: import('./prebuilt.mjs').Flavour, deny: readonly string[], linked: number, hostLibraries: { name: string, dir: string }[], os: import('./autolink.mjs').DesktopOs, arch: LinuxArch }} app
|
|
360
555
|
* `hostLibraries`: where each host library the app has is installed
|
|
556
|
+
* @returns {{ dir: string, reason?: undefined } | { dir: null, reason: string }}
|
|
361
557
|
*/
|
|
362
|
-
function prebuiltHost(sys, reactNative, { flavour, deny, linked, hostLibraries }) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
text = sys.readFile(path.join(packageDir, 'prebuilt.json'));
|
|
366
|
-
} catch {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
558
|
+
function prebuiltHost(sys, reactNative, { flavour, deny, linked, hostLibraries, os, arch }) {
|
|
559
|
+
const text = readPrebuiltManifest(sys);
|
|
560
|
+
if (!text) return { dir: null, reason: 'this package lists no prebuilt hosts' };
|
|
369
561
|
const version = versionIn(sys, reactNative);
|
|
370
|
-
if (!version) return null;
|
|
562
|
+
if (!version) return { dir: null, reason: 'react-native has no version' };
|
|
371
563
|
const libraries = Object.fromEntries(
|
|
372
564
|
hostLibraries.map(({ name, dir }) => [name, versionIn(sys, dir)]),
|
|
373
565
|
);
|
|
@@ -378,35 +570,40 @@ function prebuiltHost(sys, reactNative, { flavour, deny, linked, hostLibraries }
|
|
|
378
570
|
libraries,
|
|
379
571
|
deny,
|
|
380
572
|
env: sys.env,
|
|
573
|
+
os,
|
|
574
|
+
arch,
|
|
381
575
|
});
|
|
382
|
-
if (!('host' in choice)) return null;
|
|
383
|
-
|
|
576
|
+
if (!('host' in choice)) return { dir: null, reason: choice.reason };
|
|
577
|
+
const dir = fetchPrebuilt(
|
|
384
578
|
sys,
|
|
385
579
|
choice.host,
|
|
386
580
|
cacheDir(version, { env: sys.env, platform: sys.platform }),
|
|
387
581
|
);
|
|
582
|
+
return dir ? { dir } : { dir: null, reason: 'it did not download' };
|
|
388
583
|
}
|
|
389
584
|
|
|
390
585
|
/**
|
|
391
|
-
* Builds the host (a no-op when nothing changed) and returns its build directory
|
|
586
|
+
* Builds the host (a no-op when nothing changed) and returns its build directory: the AppKit host
|
|
587
|
+
* on a Mac, the GTK one on Linux.
|
|
392
588
|
*
|
|
393
589
|
* @param {typeof system} sys
|
|
394
590
|
* @param {string} reactNative
|
|
395
591
|
* @param {string[]} libraries
|
|
396
|
-
* @param {{ universal: boolean, release?: boolean }} options
|
|
592
|
+
* @param {{ universal: boolean, release?: boolean, os: import('./autolink.mjs').DesktopOs }} options
|
|
397
593
|
* @param {string} link the file `linkFile` names
|
|
398
594
|
*/
|
|
399
|
-
function buildHost(sys, reactNative, libraries, { universal, release }, link) {
|
|
400
|
-
checkToolchain(sys);
|
|
595
|
+
function buildHost(sys, reactNative, libraries, { universal, release, os }, link) {
|
|
596
|
+
checkToolchain(sys, os);
|
|
401
597
|
const version = versionIn(sys, reactNative);
|
|
402
598
|
if (
|
|
403
599
|
version &&
|
|
404
600
|
!sys.exists(path.join(cacheDir(version, { env: sys.env, platform: sys.platform }), 'host'))
|
|
405
601
|
) {
|
|
406
|
-
sys.warn(FIRST_BUILD_NOTE);
|
|
602
|
+
sys.warn(os === 'linux' ? LINUX_FIRST_BUILD_NOTE : FIRST_BUILD_NOTE);
|
|
407
603
|
}
|
|
408
604
|
const buildArgs = [reactNative, ...libraries.flatMap((dir) => ['--library', dir])];
|
|
409
|
-
if (
|
|
605
|
+
if (os === 'linux') buildArgs.push('--backend', 'gtk');
|
|
606
|
+
if (universal && os === 'macos') buildArgs.push('--universal');
|
|
410
607
|
// The core tests are the repo's own (`test:native`): the published package has no sources for
|
|
411
608
|
// them, so an app's build leaves them out.
|
|
412
609
|
buildArgs.push(release ? '--release' : '--no-tests');
|