@ng-native/desktop 0.24.0 → 0.26.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.
Files changed (85) hide show
  1. package/bin/package.mjs +65 -9
  2. package/bin/prebuilt.mjs +25 -4
  3. package/native/CMakeLists.txt +51 -4
  4. package/native/appkit/CMakeLists.txt +16 -2
  5. package/native/appkit/appkit-backend.mm +28 -3
  6. package/native/appkit/cg-canvas.h +5 -0
  7. package/native/appkit/cg-canvas.mm +21 -6
  8. package/native/appkit/desktop-expo.h +6 -0
  9. package/native/appkit/desktop-expo.mm +5 -0
  10. package/native/appkit/host-view.mm +32 -0
  11. package/native/appkit/image-request.h +2 -10
  12. package/native/appkit/image-request.mm +0 -22
  13. package/native/appkit/image-view.mm +121 -4
  14. package/native/appkit/main.mm +130 -185
  15. package/native/appkit/scroll-view.mm +57 -16
  16. package/native/appkit/scrollers.h +22 -2
  17. package/native/appkit/scrollers.mm +221 -2
  18. package/native/appkit/split-view.h +4 -0
  19. package/native/appkit/split-view.mm +60 -12
  20. package/native/appkit/system-access.mm +3 -0
  21. package/native/appkit/system.mm +33 -48
  22. package/native/appkit/text-layout.h +6 -0
  23. package/native/appkit/text-layout.mm +147 -24
  24. package/native/appkit/view-effects.h +27 -0
  25. package/native/appkit/view-effects.mm +90 -0
  26. package/native/cmake/react-native.cmake +9 -0
  27. package/native/cmake/runtime-dependencies.cmake +32 -1
  28. package/native/core/include/ngn/app-info.h +3 -2
  29. package/native/core/include/ngn/app-menus.h +5 -11
  30. package/native/core/include/ngn/default-menu.h +16 -6
  31. package/native/core/include/ngn/desktop-expo.h +0 -5
  32. package/native/core/include/ngn/desktop-modules.h +144 -0
  33. package/native/core/include/ngn/dev-server.h +12 -3
  34. package/native/core/include/ngn/host-os.h +45 -0
  35. package/native/core/include/ngn/host-views.h +25 -0
  36. package/native/core/include/ngn/image-source.h +18 -0
  37. package/native/core/include/ngn/launch-settings.h +9 -7
  38. package/native/core/include/ngn/module-registry.h +2 -0
  39. package/native/core/include/ngn/notifications.h +6 -0
  40. package/native/core/include/ngn/runtime.h +4 -1
  41. package/native/core/include/ngn/scrollers.h +5 -0
  42. package/native/core/include/ngn/spawn-rules.h +3 -2
  43. package/native/core/include/ngn/split-view.h +12 -0
  44. package/native/core/include/ngn/system.h +47 -0
  45. package/native/core/include/ngn/text-measurer.h +11 -0
  46. package/native/core/include/ngn/undo.h +27 -0
  47. package/native/core/include/ngn/updates.h +3 -2
  48. package/native/core/include/ngn/view-filter.h +33 -0
  49. package/native/core/src/app-menus.cpp +9 -11
  50. package/native/core/src/default-menu.cpp +6 -2
  51. package/native/core/src/dev-server-helper.cpp +3 -2
  52. package/native/core/src/dev-server.cpp +22 -5
  53. package/native/core/src/host-os.cpp +20 -0
  54. package/native/core/src/host-views.cpp +25 -0
  55. package/native/core/src/image-source.cpp +30 -0
  56. package/native/core/src/launch-settings.cpp +10 -6
  57. package/native/core/src/module-registry.cpp +9 -0
  58. package/native/core/src/modules/app-info.cpp +4 -4
  59. package/native/core/src/modules/app-modules.cpp +4 -2
  60. package/native/core/src/modules/desktop-expo.cpp +0 -5
  61. package/native/core/src/modules/desktop-modules.cpp +132 -0
  62. package/native/core/src/modules/notifications.cpp +4 -4
  63. package/native/core/src/runtime.cpp +2 -0
  64. package/native/core/src/scrollers.cpp +11 -0
  65. package/native/core/src/spawn-rules.cpp +1 -4
  66. package/native/core/src/split-view.cpp +10 -0
  67. package/native/core/src/system.cpp +52 -0
  68. package/native/core/src/text-layout-manager.cpp +13 -0
  69. package/native/core/src/undo-stacks.cpp +71 -0
  70. package/native/core/src/view-filter.cpp +114 -0
  71. package/native/scripts/build-hermes.sh +19 -7
  72. package/native/scripts/build-icu.sh +36 -0
  73. package/native/scripts/build-lock.sh +21 -0
  74. package/native/scripts/build.sh +46 -7
  75. package/native/scripts/fetch-hermes.sh +70 -0
  76. package/native/scripts/fetch.sh +24 -2
  77. package/native/scripts/hermes-built.sh +5 -4
  78. package/native/scripts/hermes-target.sh +18 -0
  79. package/native/scripts/icu-filter.json +22 -0
  80. package/native/scripts/make-prebuilt.mjs +13 -6
  81. package/native/scripts/prebuilt-host-cache.mjs +1 -1
  82. package/native/shim/openssl/sha.h +108 -3
  83. package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
  84. package/package.json +2 -2
  85. package/prebuilt.json +6 -6
@@ -0,0 +1,114 @@
1
+ #include "ngn/view-filter.h"
2
+
3
+ #include "ngn/svg.h"
4
+
5
+ #include <react/renderer/graphics/Color.h>
6
+
7
+ #include <algorithm>
8
+ #include <cmath>
9
+ #include <optional>
10
+ #include <variant>
11
+
12
+ using namespace facebook::react;
13
+
14
+ namespace ngn {
15
+
16
+ namespace {
17
+
18
+ using Matrix = std::array<double, 20>;
19
+
20
+ constexpr Matrix kIdentity{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0};
21
+
22
+ // Each colour channel times `slope` plus `intercept`: feComponentTransfer's linear function.
23
+ Matrix linear(double slope, double intercept) {
24
+ return {slope, 0, 0, 0, intercept, 0, slope, 0, 0, intercept, 0, 0, slope, 0, intercept, 0, 0, 0, 1, 0};
25
+ }
26
+
27
+ // The Filter Effects spec's grayscale and sepia matrices, at `amount` from 0 to 1.
28
+ Matrix grayscale(double amount) {
29
+ double s = 1 - amount;
30
+ return {0.2126 + 0.7874 * s, 0.7152 - 0.7152 * s, 0.0722 - 0.0722 * s, 0, 0,
31
+ 0.2126 - 0.2126 * s, 0.7152 + 0.2848 * s, 0.0722 - 0.0722 * s, 0, 0,
32
+ 0.2126 - 0.2126 * s, 0.7152 - 0.7152 * s, 0.0722 + 0.9278 * s, 0, 0,
33
+ 0, 0, 0, 1, 0};
34
+ }
35
+
36
+ Matrix sepia(double amount) {
37
+ double s = 1 - amount;
38
+ return {0.393 + 0.607 * s, 0.769 - 0.769 * s, 0.189 - 0.189 * s, 0, 0,
39
+ 0.349 - 0.349 * s, 0.686 + 0.314 * s, 0.168 - 0.168 * s, 0, 0,
40
+ 0.272 - 0.272 * s, 0.534 - 0.534 * s, 0.131 + 0.869 * s, 0, 0,
41
+ 0, 0, 0, 1, 0};
42
+ }
43
+
44
+ std::optional<Matrix> colorMatrix(FilterType type, double value) {
45
+ double unit = std::clamp(value, 0.0, 1.0);
46
+ switch (type) {
47
+ case FilterType::Brightness:
48
+ return linear(value, 0);
49
+ case FilterType::Contrast:
50
+ return linear(value, 0.5 - 0.5 * value);
51
+ case FilterType::Grayscale:
52
+ return grayscale(unit);
53
+ case FilterType::Sepia:
54
+ return sepia(unit);
55
+ case FilterType::Invert:
56
+ return linear(1 - 2 * unit, unit);
57
+ case FilterType::Saturate:
58
+ return svgColorMatrix(1, {value});
59
+ case FilterType::HueRotate:
60
+ return svgColorMatrix(2, {value});
61
+ case FilterType::Opacity: {
62
+ Matrix m = kIdentity;
63
+ m[18] = unit;
64
+ return m;
65
+ }
66
+ default:
67
+ return std::nullopt;
68
+ }
69
+ }
70
+
71
+ } // namespace
72
+
73
+ std::vector<FilterStep> filterSteps(const std::vector<FilterFunction> &filter) {
74
+ std::vector<FilterStep> steps;
75
+ for (const auto &function : filter) {
76
+ if (function.type == FilterType::DropShadow) {
77
+ const auto *shadow = std::get_if<DropShadowParams>(&function.parameters);
78
+ if (!shadow) {
79
+ continue;
80
+ }
81
+ FilterStep step{.type = FilterStep::Type::DropShadow};
82
+ step.offsetX = shadow->offsetX;
83
+ step.offsetY = shadow->offsetY;
84
+ step.standardDeviation = std::max<double>(0, shadow->standardDeviation);
85
+ if (shadow->color) {
86
+ auto c = colorComponentsFromColor(shadow->color);
87
+ auto byte = [](float v) { return static_cast<uint32_t>(std::clamp(v, 0.0f, 1.0f) * 255 + 0.5f); };
88
+ step.argb = byte(c.alpha) << 24 | byte(c.red) << 16 | byte(c.green) << 8 | byte(c.blue);
89
+ }
90
+ steps.push_back(step);
91
+ continue;
92
+ }
93
+ const auto *value = std::get_if<Float>(&function.parameters);
94
+ if (!value) {
95
+ continue;
96
+ }
97
+ if (function.type == FilterType::Blur) {
98
+ if (*value > 0) {
99
+ steps.push_back({.type = FilterStep::Type::Blur, .standardDeviation = *value});
100
+ }
101
+ continue;
102
+ }
103
+ auto matrix = colorMatrix(function.type, *value);
104
+ bool identity = matrix && std::equal(matrix->begin(), matrix->end(), kIdentity.begin(), [](double a, double b) {
105
+ return std::abs(a - b) < 1e-9;
106
+ });
107
+ if (matrix && !identity) {
108
+ steps.push_back({.type = FilterStep::Type::ColorMatrix, .matrix = *matrix});
109
+ }
110
+ }
111
+ return steps;
112
+ }
113
+
114
+ } // namespace ngn
@@ -4,7 +4,9 @@
4
4
  #
5
5
  # build-hermes.sh <node_modules/react-native> [architectures, default: this Mac's]
6
6
  #
7
- # Release, debugger on, Intl on (as React Native's Apple builds are), HV32 heap. The flags follow
7
+ # Release, debugger on, HV32 heap. Intl on macOS (as React Native's Apple builds are), over
8
+ # Foundation; elsewhere Intl is off, and the Unicode layer links the static ICU build-icu.sh builds
9
+ # into <out>/icu, which cmake/runtime-dependencies.cmake links the host against. The flags follow
8
10
  # Basalt's bootstrap.sh (Basalt 0.2.9, MIT, Copyright (c) 2026 Vince Vella), which mirrors React
9
11
  # Native's own host build. jsi is not in the archive: the host compiles React Native's copy once.
10
12
  set -euo pipefail
@@ -15,12 +17,21 @@ RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_
15
17
  CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
16
18
  JOBS="${NGN_JOBS:-8}"
17
19
  OUT="$CACHE/hermes-${ARCHS//;/-}"
18
- TARGET="$("$here/macos-target.sh")"
20
+ MACOS_TARGET="$("$here/macos-target.sh")"
21
+ TARGET="$("$here/hermes-target.sh")"
19
22
 
20
23
  [ -d "$CACHE/src/hermes" ] || { echo "build-hermes.sh: run fetch.sh first" >&2; exit 1; }
24
+ # Unfinished until the stamp is written again at the end.
25
+ rm -f "$OUT/target"
21
26
 
22
27
  intl=OFF
23
- [ "$(uname -s)" = "Darwin" ] && intl=ON
28
+ icu_args=()
29
+ if [ "$(uname -s)" = "Darwin" ]; then
30
+ intl=ON
31
+ else
32
+ "$here/build-icu.sh" "$CACHE" "$OUT/icu"
33
+ icu_args=(-DHERMES_USE_STATIC_ICU=ON -DICU_ROOT="$OUT/icu")
34
+ fi
24
35
  launcher_args=()
25
36
  while IFS= read -r arg; do
26
37
  launcher_args+=("$arg")
@@ -29,16 +40,17 @@ cmake --log-level=ERROR -G Ninja -S "$CACHE/src/hermes" -B "$OUT" \
29
40
  -DJSI_DIR="$RN_PKG/ReactCommon/jsi" \
30
41
  -DCMAKE_BUILD_TYPE=Release \
31
42
  -DCMAKE_OSX_ARCHITECTURES="$ARCHS" \
32
- -DCMAKE_OSX_DEPLOYMENT_TARGET="$TARGET" \
43
+ -DCMAKE_OSX_DEPLOYMENT_TARGET="$MACOS_TARGET" \
33
44
  -DHERMES_ENABLE_DEBUGGER=ON \
34
45
  -DHERMES_ENABLE_INTL="$intl" \
35
46
  -DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32 \
36
47
  -DHERMES_ENABLE_TEST_SUITE=OFF \
37
48
  -DHERMES_BUILD_APPLE_FRAMEWORK=OFF \
38
49
  -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
39
- ${launcher_args[@]+"${launcher_args[@]}"}
50
+ ${launcher_args[@]+"${launcher_args[@]}"} \
51
+ ${icu_args[@]+"${icu_args[@]}"}
40
52
  # hermesc too, which compiles a packaged app's bundle to this Hermes's bytecode.
41
53
  nice -n 10 cmake --build "$OUT" --target hermesvm_a hermesc -j "$JOBS"
42
- # What hermes-built.sh checks: the macOS this build is for.
43
- echo "$TARGET" > "$OUT/macos-target"
54
+ # What hermes-built.sh checks: what this build is for (hermes-target.sh).
55
+ echo "$TARGET" > "$OUT/target"
44
56
  echo "$OUT"
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+ # Builds the ICU fetch.sh pinned as static archives with their data linked in, for Hermes off
3
+ # macOS: its Unicode layer (case mapping, normalize, localeCompare, dates' toLocaleString) needs ICU
4
+ # even with Intl off, and a static copy ties the host to no distribution's ICU.
5
+ #
6
+ # build-icu.sh <cache> <out-prefix>
7
+ #
8
+ # The data is built from its sources through icu-filter.json: English only, without the conversion
9
+ # tables, transliteration, break iterators and display-name trees Hermes never reads.
10
+ set -euo pipefail
11
+ here="$(cd "$(dirname "$0")" && pwd)"
12
+ CACHE="${1:?usage: build-icu.sh <cache> <out-prefix>}"
13
+ OUT="${2:?usage: build-icu.sh <cache> <out-prefix>}"
14
+ JOBS="${NGN_JOBS:-8}"
15
+ # Absolute, since the build runs from its work directory.
16
+ case "$CACHE" in /*) ;; *) CACHE="$PWD/$CACHE" ;; esac
17
+ case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac
18
+ [ -x "$CACHE/src/icu/source/configure" ] || { echo "build-icu.sh: run fetch.sh first" >&2; exit 1; }
19
+
20
+ work="$OUT.build"
21
+ rm -rf "$work" "$OUT"
22
+ mkdir -p "$work"
23
+ cd "$work"
24
+ # Read when configure lays out the data build.
25
+ export ICU_DATA_FILTER_FILE="$here/icu-filter.json"
26
+ CC=clang CXX=clang++ CFLAGS="-O2 -fPIC" CXXFLAGS="-O2 -fPIC -std=c++17" \
27
+ "$CACHE/src/icu/source/configure" --prefix="$OUT" --enable-static --disable-shared \
28
+ --with-data-packaging=static --disable-tests --disable-samples --disable-extras \
29
+ --disable-icuio --disable-layoutex > configure.log 2>&1 || { tail -40 configure.log >&2; exit 1; }
30
+ nice -n 10 make -j "$JOBS" > make.log 2>&1 || { tail -40 make.log >&2; exit 1; }
31
+ make install > install.log 2>&1 || { tail -40 install.log >&2; exit 1; }
32
+ for lib in icuuc icui18n icudata; do
33
+ [ -f "$OUT/lib/lib$lib.a" ] || { echo "build-icu.sh: no lib$lib.a in $OUT/lib" >&2; exit 1; }
34
+ done
35
+ cd /
36
+ rm -rf "$work"
@@ -0,0 +1,21 @@
1
+ # shellcheck shell=bash
2
+ # Sourced by build.sh: one build at a time in a build directory.
3
+ #
4
+ # lock_build <build dir>
5
+ #
6
+ # Two ninja processes in one build directory both append to its .ninja_deps, and the next build
7
+ # finds the log corrupt ("premature end of file; recovering"), drops every record after the
8
+ # clash and compiles those objects again: a run beside another, or beside one a killed command
9
+ # left running, recompiles hundreds of objects on the run after it. The lock is the kernel's flock
10
+ # on <build dir>/.ngn-build-lock, held through the calling shell's descriptor 7 (Perl takes it,
11
+ # since macOS has no flock command) until that shell exits, and by the cmake and ninja it starts,
12
+ # which inherit the descriptor, so a build whose script was killed still holds it until ninja
13
+ # stops. A second build waits for it, then finds nothing left to do.
14
+ lock_build() {
15
+ mkdir -p "$1"
16
+ exec 7>> "$1/.ngn-build-lock"
17
+ if ! perl -MFcntl=:flock -e 'open(my $fd, ">&=", 7) or die "build.sh: $!\n"; exit(flock($fd, LOCK_EX | LOCK_NB) ? 0 : 1)'; then
18
+ echo "build.sh: waiting for another build in $1" >&2
19
+ perl -MFcntl=:flock -e 'open(my $fd, ">&=", 7) or die "build.sh: $!\n"; flock($fd, LOCK_EX) or die "build.sh: $!\n"'
20
+ fi
21
+ }
@@ -2,13 +2,15 @@
2
2
  # Builds the desktop host (or only the core and its tests) in the per-user cache, fetching the
3
3
  # pinned sources and building Hermes first when they are missing. Prints the build directory.
4
4
  #
5
- # build.sh [node_modules/react-native] [--backend appkit|none] [--universal] [--debug|--release]
6
- # [--test | --no-tests] [--no-debug-info] [--library <node_modules/library>]...
7
- # [--build-dir <dir>]
5
+ # build.sh [node_modules/react-native] [--backend appkit|none] [--runtime] [--universal]
6
+ # [--debug|--release] [--test | --no-tests] [--no-debug-info]
7
+ # [--library <node_modules/library>]... [--build-dir <dir>]
8
8
  #
9
9
  # Without a path, react-native is resolved from the current directory.
10
10
  #
11
11
  # --backend none the toolkit-free core and its tests only: any OS, no Hermes
12
+ # --runtime with --backend none, the core's runtime half too: Hermes, ReactHost and the
13
+ # runtime tests, still with no toolkit (what Linux builds until it has a backend)
12
14
  # --universal arm64 and x86_64 in one binary (default: this machine's architecture)
13
15
  # --debug a Debug build (default: RelWithDebInfo)
14
16
  # --release a Release build without the core tests, as a packaged app ships it
@@ -49,12 +51,14 @@ config=RelWithDebInfo
49
51
  run_tests=0
50
52
  tests=ON
51
53
  no_tests=0
54
+ runtime=0
52
55
  libraries=()
53
56
  build_dir=""
54
57
  debug_info=1
55
58
  while [ $# -gt 0 ]; do
56
59
  case "$1" in
57
60
  --backend) backend="$2"; shift ;;
61
+ --runtime) runtime=1 ;;
58
62
  --universal) archs="arm64;x86_64" ;;
59
63
  --debug) config=Debug ;;
60
64
  --release) config=Release; tests=OFF ;;
@@ -72,6 +76,8 @@ if [ "$run_tests" = 1 ] && [ "$tests" = OFF ]; then
72
76
  echo "build.sh: --test needs the core tests, which $left_out leaves out" >&2
73
77
  exit 2
74
78
  fi
79
+ # A backend always has the runtime half.
80
+ [ "$backend" = "none" ] || runtime=1
75
81
  # CMAKE_OSX_ARCHITECTURES means nothing off macOS.
76
82
  [ "$(uname -s)" = "Darwin" ] || archs=""
77
83
 
@@ -140,22 +146,47 @@ if [ "$config" = RelWithDebInfo ]; then
140
146
  done
141
147
  fi
142
148
 
149
+ # Off macOS archs is blank, and Hermes is built for this machine's architecture, under the same
150
+ # name as on macOS.
143
151
  arch_key="${archs//;/-}"
152
+ [ -n "$arch_key" ] || arch_key="$(uname -m)"
144
153
  hermes_args=()
145
- if [ "$backend" != "none" ]; then
154
+ if [ "$backend" = "appkit" ]; then
155
+ # React Native's own prebuilt Hermes, universal: with the debugger for a dev build, as React
156
+ # Native's Debug builds have it, and without for Release.
157
+ hermes_flavour=debug
158
+ [ "$config" = Release ] && hermes_flavour=release
159
+ hermes_args=(-DNGN_HERMES_PREBUILT="$("$here/fetch-hermes.sh" "$RN_PKG" "$hermes_flavour")")
160
+ elif [ "$runtime" = 1 ]; then
146
161
  hermes="$CACHE/hermes-$arch_key"
147
162
  # Built again when missing, or built for another macOS than the host's.
148
163
  if ! "$here/hermes-built.sh" "$hermes"; then
149
- "$here/build-hermes.sh" "$RN_PKG" "$archs" >&2
164
+ # One Hermes build at a time for this cache and architecture: build-hermes.sh (and, off macOS,
165
+ # build-icu.sh) clears and refills one output directory, which a second build would delete from
166
+ # under the first. Locked as fetch.sh locks (the kernel's flock through this shell's descriptor
167
+ # 8, taken by Perl since macOS has no flock command), and checked again once held, so a build
168
+ # that waited uses the Hermes the first one finished.
169
+ exec 8>> "$CACHE/.hermes-$arch_key-lock"
170
+ perl -MFcntl=:flock -e 'open(my $fd, ">&=", 8) or die "build.sh: $!\n"; flock($fd, LOCK_EX) or die "build.sh: $!\n"'
171
+ if ! "$here/hermes-built.sh" "$hermes"; then
172
+ "$here/build-hermes.sh" "$RN_PKG" "$archs" >&2
173
+ fi
174
+ exec 8>&-
150
175
  fi
151
176
  hermes_args=(-DNGN_HERMES_BUILD="$hermes")
152
177
  fi
153
178
 
154
- BUILD="${build_dir:-$host_dir/$backend-${arch_key:-native}-$config}"
179
+ variant="$backend"
180
+ [ "$backend" = "none" ] && [ "$runtime" = 1 ] && variant=none-runtime
181
+ BUILD="${build_dir:-$host_dir/$variant-$arch_key-$config}"
182
+ # One build at a time in it (build-lock.sh), held until this script and the ninja it runs end.
183
+ . "$here/build-lock.sh"
184
+ lock_build "$BUILD"
155
185
  cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
156
186
  -DCMAKE_BUILD_TYPE="$config" \
157
187
  -DCMAKE_OSX_ARCHITECTURES="$archs" \
158
188
  -DNGN_BACKEND="$backend" \
189
+ -DNGN_RUNTIME="$([ "$runtime" = 1 ] && echo ON || echo OFF)" \
159
190
  -DRN_DIR="$RN_PKG" \
160
191
  -DNGN_SOURCES="$CACHE/src" \
161
192
  -DNGN_LIBRARIES="$library_dirs" \
@@ -164,9 +195,17 @@ cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
164
195
  ${launcher_args[@]+"${launcher_args[@]}"} \
165
196
  ${flags_args[@]+"${flags_args[@]}"} \
166
197
  ${hermes_args[@]+"${hermes_args[@]}"} >&2
167
- nice -n 10 cmake --build "$BUILD" -j "$JOBS" >&2
198
+ # Ninja itself, as CMake chose it, rather than through `cmake --build`: CMake starts its build tool
199
+ # with none of this shell's descriptors, so a ninja left running after a killed `cmake --build`
200
+ # would build on without the lock. Started from here it holds descriptor 7 until it ends.
201
+ ninja=$(sed -n 's/^CMAKE_MAKE_PROGRAM:[A-Z]*=//p' "$BUILD/CMakeCache.txt")
202
+ nice -n 10 "${ninja:-ninja}" -C "$BUILD" -j "$JOBS" >&2
168
203
  if [ "$run_tests" = 1 ]; then
169
204
  "$BUILD/ngn_core_tests" >&2
205
+ # Hermes and the runtime half, which a build with the runtime has.
206
+ if [ -x "$BUILD/ngn_runtime_tests" ]; then
207
+ "$BUILD/ngn_runtime_tests" >&2
208
+ fi
170
209
  # The AppKit view tests, which a build with the AppKit backend has.
171
210
  if [ -x "$BUILD/appkit/ngn_appkit_tests" ]; then
172
211
  "$BUILD/appkit/ngn_appkit_tests" >&2
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+ # Fetches React Native's own prebuilt Hermes for Apple platforms, the one its iOS apps run, and
3
+ # prints the folder with its universal macOS hermesvm.framework, hermesc and headers.
4
+ #
5
+ # fetch-hermes.sh <node_modules/react-native> <debug|release>
6
+ #
7
+ # debug carries Hermes's debugger (CDP), as React Native's Debug builds do; release leaves it out.
8
+ # The tarball comes from Maven Central and is checked against the SHA-1 published beside it.
9
+ set -euo pipefail
10
+ here="$(cd "$(dirname "$0")" && pwd)"
11
+ RN_PKG="$(cd "${1:?usage: fetch-hermes.sh <node_modules/react-native> <debug|release>}" && pwd)"
12
+ FLAVOUR="${2:?usage: fetch-hermes.sh <node_modules/react-native> <debug|release>}"
13
+ case "$FLAVOUR" in debug | release) ;; *) echo "fetch-hermes.sh: debug or release, not $FLAVOUR" >&2; exit 2 ;; esac
14
+
15
+ RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
16
+ CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
17
+ tag="$(cat "$RN_PKG/sdks/.hermesv1version")"
18
+ version="${tag#hermes-v}"
19
+ OUT="$CACHE/hermes-prebuilt-$version-$FLAVOUR"
20
+ framework="$OUT/destroot/Library/Frameworks/macosx/hermesvm.framework"
21
+
22
+ if [ ! -d "$framework" ] || [ ! -x "$OUT/destroot/bin/hermesc" ]; then
23
+ base="${NGN_HERMES_MAVEN:-https://repo1.maven.org/maven2}/com/facebook/hermes/hermes-ios/$version"
24
+ url="$base/hermes-ios-$version-hermes-ios-$FLAVOUR.tar.gz"
25
+ tmp="$(mktemp -d)"
26
+ trap 'rm -rf "$tmp"' EXIT
27
+ curl -fsSL --retry 3 -o "$tmp/hermes.tar.gz" "$url"
28
+ expected="$(curl -fsSL --retry 3 "$url.sha1" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')"
29
+ actual="$(shasum -a 1 "$tmp/hermes.tar.gz" | cut -d' ' -f1)"
30
+ if [ "${#expected}" != 40 ] || [ "$expected" != "$actual" ]; then
31
+ echo "fetch-hermes.sh: $url has SHA-1 $actual, Maven publishes '$expected'" >&2
32
+ exit 1
33
+ fi
34
+ mkdir -p "$tmp/x"
35
+ tar -xzf "$tmp/hermes.tar.gz" -C "$tmp/x"
36
+ [ -d "$tmp/x/destroot/Library/Frameworks/macosx/hermesvm.framework" ] ||
37
+ { echo "fetch-hermes.sh: $url has no macOS hermesvm.framework" >&2; exit 1; }
38
+ # Another build may fetch the same Hermes at once: publish under a lock, and keep a complete
39
+ # copy it published rather than remove a folder it is reading.
40
+ mkdir -p "$(dirname "$OUT")"
41
+ # A held lock is waited on for at most ten minutes. One left by a build killed before its trap ran
42
+ # is not taken over, since two builds taking it over at once could each remove the other's.
43
+ lock="$OUT.lock"
44
+ acquired=0
45
+ absent=0
46
+ for _ in $(seq 600); do
47
+ if mkdir "$lock" 2>/dev/null; then
48
+ acquired=1
49
+ break
50
+ fi
51
+ # No lock, yet mkdir failed: its holder may have just released it, so retry, a few times.
52
+ if [ ! -d "$lock" ]; then
53
+ absent=$((absent + 1))
54
+ [ "$absent" -lt 5 ] && continue
55
+ echo "fetch-hermes.sh: cannot create $lock" >&2
56
+ exit 1
57
+ fi
58
+ sleep 1
59
+ done
60
+ if [ "$acquired" != 1 ]; then
61
+ echo "fetch-hermes.sh: $lock is still held after ten minutes; delete it if no build is running" >&2
62
+ exit 1
63
+ fi
64
+ trap 'rm -rf "$tmp" "$lock"' EXIT
65
+ if [ ! -d "$framework" ] || [ ! -x "$OUT/destroot/bin/hermesc" ]; then
66
+ rm -rf "$OUT"
67
+ mv "$tmp/x" "$OUT"
68
+ fi
69
+ fi
70
+ echo "$OUT/destroot"
@@ -7,8 +7,9 @@
7
7
  # ReactCommon comes from the installed react-native package; everything else is fetched here:
8
8
  # ReactCxxPlatform (in the git tag, not the npm package), Hermes, folly and the libraries React
9
9
  # Native's Android build would normally download (glog, fmt, double-conversion, boost headers,
10
- # fast_float), nlohmann_json for the dev-server client, doctest for the core tests, and on macOS
11
- # Sparkle's framework, which `package --format dmg` embeds for whole-app updates.
10
+ # fast_float), nlohmann_json for the dev-server client, doctest for the core tests, on macOS
11
+ # Sparkle's framework, which `package --format dmg` embeds for whole-app updates, and elsewhere ICU,
12
+ # which Hermes's Unicode layer needs there (build-icu.sh builds it).
12
13
  # Each source records what it was fetched at, so a changed pin fetches it again. A download whose
13
14
  # checksum or commit does not match fails the script; nothing is ever used unverified.
14
15
  #
@@ -49,6 +50,11 @@ DOCTEST_URL=https://raw.githubusercontent.com/doctest/doctest/v2.4.12/doctest/do
49
50
  DOCTEST_SHA256=94029a7d32da24a56249658147dbd2b33ff0b9ed665295cbbaf19aafff5b0ced
50
51
  SPARKLE_URL=https://github.com/sparkle-project/Sparkle/releases/download/2.6.4/Sparkle-2.6.4.tar.xz
51
52
  SPARKLE_SHA256=50612a06038abc931f16011d7903b8326a362c1074dabccb718404ce8e585f0b
53
+ # ICU's sources and, to build its data filtered (build-icu.sh), the data's sources.
54
+ ICU_URL=https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-src.tgz
55
+ ICU_SHA256=588e431f77327c39031ffbb8843c0e3bc122c211374485fa87dc5f3faff24061
56
+ ICU_DATA_URL=https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-data.zip
57
+ ICU_DATA_SHA256=1e08bfafa442260ccabf9a872d4eab12de813d42b90769df056bab032b37e1d3
52
58
 
53
59
  if [ "$(cat "$RN_PKG/sdks/.hermesv1version")" != "$HERMES_TAG" ]; then
54
60
  echo "fetch.sh: react-native names Hermes $(cat "$RN_PKG/sdks/.hermesv1version"), pinned $HERMES_TAG" >&2
@@ -151,6 +157,22 @@ if [ "$(uname -s)" = "Darwin" ] && ! fresh sparkle "$SPARKLE_SHA256"; then
151
157
  rm -rf "$SRC/.sparkle.tmp"
152
158
  stamp sparkle "$SPARKLE_SHA256"
153
159
  fi
160
+
161
+ # ICU, with its data's sources in place of the prebuilt data, so build-icu.sh can filter them.
162
+ if [ "$(uname -s)" != "Darwin" ] && ! fresh icu "$ICU_SHA256-$ICU_DATA_SHA256"; then
163
+ echo "==> icu"
164
+ rm -rf "$SRC/icu" "$SRC/.icu.tmp"
165
+ mkdir -p "$SRC/.icu.tmp"
166
+ download "$ICU_URL" "$ICU_SHA256" "$SRC/.icu.tmp/icu.tgz"
167
+ download "$ICU_DATA_URL" "$ICU_DATA_SHA256" "$SRC/.icu.tmp/data.zip"
168
+ tar -xzf "$SRC/.icu.tmp/icu.tgz" -C "$SRC/.icu.tmp"
169
+ rm -rf "$SRC/.icu.tmp/icu/source/data"
170
+ unzip -q "$SRC/.icu.tmp/data.zip" -d "$SRC/.icu.tmp/icu/source"
171
+ [ -d "$SRC/.icu.tmp/icu/source/data/locales" ] || { echo "fetch.sh: ICU's data archive has no data/locales" >&2; exit 1; }
172
+ mv "$SRC/.icu.tmp/icu" "$SRC/icu"
173
+ rm -rf "$SRC/.icu.tmp"
174
+ stamp icu "$ICU_SHA256-$ICU_DATA_SHA256"
175
+ fi
154
176
  t1=$(date +%s)
155
177
 
156
178
  # React Native's own component codegen (FBReactNativeSpec), from the installed package.
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env bash
2
- # Succeeds when <dir> holds a Hermes build-hermes.sh finished for the macOS the host is built for
3
- # now (macos-target.sh); build.sh builds it again otherwise, so a raised target reaches Hermes too.
2
+ # Succeeds when <dir> holds a Hermes build-hermes.sh finished for what the host is built for now
3
+ # (hermes-target.sh: the macOS, or off macOS the C library and the ICU); build.sh builds it again
4
+ # otherwise, so a raised target or a new ICU reaches Hermes too.
4
5
  #
5
6
  # hermes-built.sh <dir>
6
7
  set -euo pipefail
7
8
  here="$(cd "$(dirname "$0")" && pwd)"
8
9
  dir="${1:?usage: hermes-built.sh <dir>}"
9
- [ -f "$dir/lib/libhermesvm_a.a" ] && [ -f "$dir/macos-target" ] &&
10
- [ "$(cat "$dir/macos-target")" = "$("$here/macos-target.sh")" ]
10
+ [ -f "$dir/lib/libhermesvm_a.a" ] && [ -f "$dir/target" ] &&
11
+ [ "$(cat "$dir/target")" = "$("$here/hermes-target.sh")" ]
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # Prints what a Hermes build is for, which build-hermes.sh records beside it and hermes-built.sh
3
+ # compares, so a change to any of it builds Hermes again: on macOS the oldest macOS the host runs on
4
+ # (macos-target.sh); elsewhere the C library it links against and the ICU it links in (fetch.sh's
5
+ # pin, and how build-icu.sh builds it).
6
+ set -euo pipefail
7
+ here="$(cd "$(dirname "$0")" && pwd)"
8
+ if [ "$(uname -s)" = "Darwin" ]; then
9
+ echo "macos $("$here/macos-target.sh")"
10
+ exit 0
11
+ fi
12
+ sha256() {
13
+ if command -v sha256sum > /dev/null; then sha256sum; else shasum -a 256; fi | cut -d' ' -f1
14
+ }
15
+ glibc="$(getconf GNU_LIBC_VERSION | cut -d' ' -f2)"
16
+ icu="$(sed -n 's/^ICU\(_DATA\)\{0,1\}_SHA256=\([0-9a-f]*\)$/\2/p' "$here/fetch.sh" | tr '\n' ' ')"
17
+ [ -n "$glibc" ] && [ "$(wc -w <<< "$icu")" -eq 2 ] || { echo "hermes-target.sh: no glibc version or ICU pin" >&2; exit 1; }
18
+ echo "linux glibc $glibc icu ${icu% } build $(cat "$here/build-icu.sh" "$here/icu-filter.json" | sha256)"
@@ -0,0 +1,22 @@
1
+ {
2
+ "localeFilter": {
3
+ "filterType": "language",
4
+ "includelist": ["en"]
5
+ },
6
+ "featureFilters": {
7
+ "conversion_mappings": "exclude",
8
+ "cnvalias": "exclude",
9
+ "confusables": "exclude",
10
+ "translit": "exclude",
11
+ "brkitr_dictionaries": "exclude",
12
+ "brkitr_rules": "exclude",
13
+ "brkitr_tree": "exclude",
14
+ "stringprep": "exclude",
15
+ "unames": "exclude",
16
+ "rbnf_tree": "exclude",
17
+ "curr_tree": "exclude",
18
+ "lang_tree": "exclude",
19
+ "region_tree": "exclude",
20
+ "unit_tree": "exclude"
21
+ }
22
+ }
@@ -40,7 +40,10 @@
40
40
  * The host has no app's linked code and is built from scratch in a directory of its own, so no other
41
41
  * build can replace it before it is archived. `ngn-macos` and `hermesc` have their local symbols
42
42
  * stripped and are signed with the hardened runtime, ad hoc (`codesign --sign -`) unless `NGN_SIGN_IDENTITY` names an identity: an
43
- * app re-signs the host when it packages, so the release needs no Developer ID. Nothing is uploaded.
43
+ * app re-signs the host when it packages, so the release needs no Developer ID. React Native's
44
+ * `hermesvm.framework`, which the binary links, is signed first with the same identity, and an ad
45
+ * hoc binary goes without library validation, which has no team to check it against (see
46
+ * AD_HOC_HOST_ENTITLEMENTS). Nothing is uploaded.
44
47
  */
45
48
  import { spawnSync } from 'node:child_process';
46
49
  import { createHash } from 'node:crypto';
@@ -62,6 +65,7 @@ import { parseArgs } from 'node:util';
62
65
 
63
66
  import { HOST_LIBRARIES, packageDir } from '../../bin/host.mjs';
64
67
  import {
68
+ AD_HOC_HOST_ENTITLEMENTS,
65
69
  FLAVOURS,
66
70
  flavourOf,
67
71
  prebuiltName,
@@ -316,11 +320,14 @@ try {
316
320
  verbatimSymlinks: true,
317
321
  });
318
322
  }
319
- signPrebuiltFiles(
320
- run,
321
- ['ngn-macos', 'hermesc'].map((file) => path.join(appkit, file)),
322
- process.env,
323
- );
323
+ // The framework first, which the binary's signature then covers with the same identity.
324
+ const framework = path.join(appkit, 'hermesvm.framework');
325
+ if (existsSync(framework)) signPrebuiltFiles(run, [framework], process.env);
326
+ const entitlements = path.join(staging, 'ad-hoc-host.entitlements');
327
+ writeFileSync(entitlements, AD_HOC_HOST_ENTITLEMENTS);
328
+ signPrebuiltFiles(run, [path.join(appkit, 'ngn-macos')], process.env, entitlements);
329
+ rmSync(entitlements);
330
+ signPrebuiltFiles(run, [path.join(appkit, 'hermesc')], process.env);
324
331
  }
325
332
  for (const file of HOST_FILES) {
326
333
  if (!existsSync(path.join(appkit, file))) throw new Error(`The host has no ${file}.`);
@@ -21,7 +21,7 @@ import {
21
21
  import path from 'node:path';
22
22
 
23
23
  /** What the cache holds, under `appkit/`: the files make-prebuilt.mjs archives. */
24
- export const HOST_FILES = ['ngn-macos', 'hermesc', 'Sparkle.framework'];
24
+ export const HOST_FILES = ['ngn-macos', 'hermesc', 'hermesvm.framework', 'Sparkle.framework'];
25
25
 
26
26
  /** Bumped when the cache's layout or what the key covers changes, so older caches miss. */
27
27
  const SCHEMA = 1;