@ng-native/desktop 0.0.0-stage → 0.23.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/LICENSE +21 -0
- package/README.md +51 -2
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +70 -3
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#include "ngn/view-transform.h"
|
|
2
|
+
|
|
3
|
+
#include <cmath>
|
|
4
|
+
|
|
5
|
+
using namespace facebook::react;
|
|
6
|
+
|
|
7
|
+
namespace ngn {
|
|
8
|
+
|
|
9
|
+
std::optional<Transform> layerTransform(const ViewProps &props, const LayoutMetrics &layout) {
|
|
10
|
+
if (props.transform.operations.empty() && props.transform == Transform::Identity()) {
|
|
11
|
+
return std::nullopt;
|
|
12
|
+
}
|
|
13
|
+
auto matrix = props.resolveTransform(layout);
|
|
14
|
+
if (matrix == Transform::Identity()) {
|
|
15
|
+
return std::nullopt;
|
|
16
|
+
}
|
|
17
|
+
// React Native's product applies its right-hand side first, as resolveTransform's own origin
|
|
18
|
+
// shift does: a point moves to the centre's frame, transforms, and moves back.
|
|
19
|
+
const auto &size = layout.frame.size;
|
|
20
|
+
Float cx = size.width / 2;
|
|
21
|
+
Float cy = size.height / 2;
|
|
22
|
+
return Transform::Translate(cx, cy, 0) * matrix * Transform::Translate(-cx, -cy, 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::optional<Point> layerPointAt(const Transform &transform, Point point) {
|
|
26
|
+
const auto &m = transform.matrix;
|
|
27
|
+
double a = m[0], b = m[4], c = m[12];
|
|
28
|
+
double d = m[1], e = m[5], f = m[13];
|
|
29
|
+
double g = m[3], h = m[7], i = m[15];
|
|
30
|
+
double det = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
|
|
31
|
+
if (std::abs(det) < 1e-9) {
|
|
32
|
+
return std::nullopt;
|
|
33
|
+
}
|
|
34
|
+
double x = point.x;
|
|
35
|
+
double y = point.y;
|
|
36
|
+
double ix = ((e * i - f * h) * x + (c * h - b * i) * y + (b * f - c * e)) / det;
|
|
37
|
+
double iy = ((f * g - d * i) * x + (a * i - c * g) * y + (c * d - a * f)) / det;
|
|
38
|
+
double iw = ((d * h - e * g) * x + (b * g - a * h) * y + (a * e - b * d)) / det;
|
|
39
|
+
if (std::abs(iw) < 1e-12) {
|
|
40
|
+
return std::nullopt;
|
|
41
|
+
}
|
|
42
|
+
return Point{static_cast<Float>(ix / iw), static_cast<Float>(iy / iw)};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace ngn
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#include "ngn/view-tree.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/view-transform.h"
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
6
|
+
|
|
7
|
+
#include <algorithm>
|
|
8
|
+
|
|
9
|
+
using namespace facebook::react;
|
|
10
|
+
|
|
11
|
+
namespace ngn {
|
|
12
|
+
|
|
13
|
+
void ViewTree::create(const ShadowView &view) {
|
|
14
|
+
nodes_[view.tag] = Node{.view = view, .parent = -1, .children = {}};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void ViewTree::destroy(Tag tag) {
|
|
18
|
+
auto it = nodes_.find(tag);
|
|
19
|
+
if (it == nodes_.end()) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (it->second.parent != -1) {
|
|
23
|
+
remove(it->second.parent, tag);
|
|
24
|
+
}
|
|
25
|
+
scrollOffsets_.erase(tag);
|
|
26
|
+
// Fabric deletes children before their parent, so any left here were already removed.
|
|
27
|
+
for (auto child : it->second.children) {
|
|
28
|
+
if (auto c = nodes_.find(child); c != nodes_.end()) {
|
|
29
|
+
c->second.parent = -1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
containerRoots_.erase(tag);
|
|
33
|
+
covered_.erase(tag);
|
|
34
|
+
nodes_.erase(it);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void ViewTree::insert(Tag parent, Tag child, int index) {
|
|
38
|
+
auto p = nodes_.find(parent);
|
|
39
|
+
auto c = nodes_.find(child);
|
|
40
|
+
if (p == nodes_.end() || c == nodes_.end()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
auto &children = p->second.children;
|
|
44
|
+
auto at = std::min<size_t>(static_cast<size_t>(std::max(index, 0)), children.size());
|
|
45
|
+
children.insert(children.begin() + static_cast<std::ptrdiff_t>(at), child);
|
|
46
|
+
c->second.parent = parent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void ViewTree::remove(Tag parent, Tag child) {
|
|
50
|
+
if (auto p = nodes_.find(parent); p != nodes_.end()) {
|
|
51
|
+
auto &children = p->second.children;
|
|
52
|
+
children.erase(std::remove(children.begin(), children.end(), child), children.end());
|
|
53
|
+
}
|
|
54
|
+
if (auto c = nodes_.find(child); c != nodes_.end() && c->second.parent == parent) {
|
|
55
|
+
c->second.parent = -1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void ViewTree::update(const ShadowView &view) {
|
|
60
|
+
if (auto it = nodes_.find(view.tag); it != nodes_.end()) {
|
|
61
|
+
it->second.view = view;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ViewTree::Node *ViewTree::find(Tag tag) const {
|
|
66
|
+
auto it = nodes_.find(tag);
|
|
67
|
+
return it == nodes_.end() ? nullptr : &it->second;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
bool ViewTree::contains(Tag tag) const {
|
|
71
|
+
return nodes_.contains(tag);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void ViewTree::addContainerRoot(Tag root) {
|
|
75
|
+
containerRoots_.insert(root);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void ViewTree::removeContainerRoot(Tag root) {
|
|
79
|
+
containerRoots_.erase(root);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
bool ViewTree::isContainerRoot(Tag tag) const {
|
|
83
|
+
return containerRoots_.contains(tag);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void ViewTree::setCovered(Tag tag, bool covered) {
|
|
87
|
+
if (covered) {
|
|
88
|
+
covered_.insert(tag);
|
|
89
|
+
} else {
|
|
90
|
+
covered_.erase(tag);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
bool ViewTree::covered(Tag tag) const {
|
|
95
|
+
return covered_.contains(tag);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void ViewTree::setScrollOffset(Tag tag, Point offset) {
|
|
99
|
+
if (offset == Point{0, 0}) {
|
|
100
|
+
scrollOffsets_.erase(tag);
|
|
101
|
+
} else {
|
|
102
|
+
scrollOffsets_[tag] = offset;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Point ViewTree::scrollOffset(Tag tag) const {
|
|
107
|
+
auto it = scrollOffsets_.find(tag);
|
|
108
|
+
return it == scrollOffsets_.end() ? Point{0, 0} : it->second;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
std::vector<Tag> ViewTree::hitTest(Tag root, Point point) const {
|
|
112
|
+
std::vector<Tag> chain;
|
|
113
|
+
hitTest(root, root, point, chain);
|
|
114
|
+
std::reverse(chain.begin(), chain.end());
|
|
115
|
+
return chain;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// `point` is in `tag`'s own coordinates. Appends the deepest hit first, then each ancestor.
|
|
119
|
+
bool ViewTree::hitTest(Tag tag, Tag root, Point point, std::vector<Tag> &chain) const {
|
|
120
|
+
const Node *node = find(tag);
|
|
121
|
+
if (node == nullptr || (tag != root && containerRoots_.contains(tag)) || covered_.contains(tag)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const auto &layout = node->view.layoutMetrics;
|
|
125
|
+
if (layout.displayType == DisplayType::None) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
auto props = std::dynamic_pointer_cast<const ViewProps>(node->view.props);
|
|
129
|
+
auto pointerEvents = props ? props->pointerEvents : PointerEventsMode::Auto;
|
|
130
|
+
if (pointerEvents == PointerEventsMode::None) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
// The root covers its whole container: the container reports only points inside itself, and
|
|
134
|
+
// Fabric may never give a surface's root a frame of its own.
|
|
135
|
+
const auto &size = layout.frame.size;
|
|
136
|
+
bool inside = tag == root || (point.x >= 0 && point.y >= 0 && point.x < size.width && point.y < size.height);
|
|
137
|
+
// hitSlop widens where the view itself is hit, as React Native's pointInside does; its children
|
|
138
|
+
// are still found only inside it.
|
|
139
|
+
auto slop = props ? props->hitSlop : EdgeInsets{};
|
|
140
|
+
bool reached = inside ||
|
|
141
|
+
(point.x >= -slop.left && point.y >= -slop.top && point.x < size.width + slop.right &&
|
|
142
|
+
point.y < size.height + slop.bottom);
|
|
143
|
+
bool clips = (props && props->yogaStyle.overflow() != facebook::yoga::Overflow::Visible) ||
|
|
144
|
+
layout.overflowInset == EdgeInsets{};
|
|
145
|
+
if (clips && !reached) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (pointerEvents != PointerEventsMode::BoxOnly) {
|
|
149
|
+
Point scrolled = scrollOffset(tag);
|
|
150
|
+
for (auto it = node->children.rbegin(); it != node->children.rend(); ++it) {
|
|
151
|
+
const Node *child = find(*it);
|
|
152
|
+
if (child == nullptr) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
auto local = toChild(*child, {point.x + scrolled.x, point.y + scrolled.y});
|
|
156
|
+
if (local && hitTest(*it, root, *local, chain)) {
|
|
157
|
+
chain.push_back(tag);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (reached && pointerEvents != PointerEventsMode::BoxNone) {
|
|
163
|
+
chain.push_back(tag);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
std::optional<Point> ViewTree::toChild(const Node &child, Point point) {
|
|
170
|
+
const auto &layout = child.view.layoutMetrics;
|
|
171
|
+
Point local{point.x - layout.frame.origin.x, point.y - layout.frame.origin.y};
|
|
172
|
+
auto props = std::dynamic_pointer_cast<const ViewProps>(child.view.props);
|
|
173
|
+
auto transform = props ? layerTransform(*props, layout) : std::nullopt;
|
|
174
|
+
if (!transform) {
|
|
175
|
+
return local;
|
|
176
|
+
}
|
|
177
|
+
return layerPointAt(*transform, local);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
std::optional<Point> ViewTree::pointIn(Tag tag, Tag root, Point point) const {
|
|
181
|
+
auto path = chain(tag, root);
|
|
182
|
+
if (path.empty()) {
|
|
183
|
+
return std::nullopt;
|
|
184
|
+
}
|
|
185
|
+
for (size_t index = 1; index < path.size(); ++index) {
|
|
186
|
+
Point scrolled = scrollOffset(path[index - 1]);
|
|
187
|
+
auto local = toChild(*find(path[index]), {point.x + scrolled.x, point.y + scrolled.y});
|
|
188
|
+
if (!local) {
|
|
189
|
+
return std::nullopt;
|
|
190
|
+
}
|
|
191
|
+
point = *local;
|
|
192
|
+
}
|
|
193
|
+
return point;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
std::optional<Point> ViewTree::originIn(Tag tag, Tag root) const {
|
|
197
|
+
Point origin{0, 0};
|
|
198
|
+
for (Tag current = tag; current != root;) {
|
|
199
|
+
const Node *node = find(current);
|
|
200
|
+
if (node == nullptr || node->parent == -1) {
|
|
201
|
+
return std::nullopt;
|
|
202
|
+
}
|
|
203
|
+
Point scrolled = scrollOffset(node->parent);
|
|
204
|
+
origin.x += node->view.layoutMetrics.frame.origin.x - scrolled.x;
|
|
205
|
+
origin.y += node->view.layoutMetrics.frame.origin.y - scrolled.y;
|
|
206
|
+
current = node->parent;
|
|
207
|
+
}
|
|
208
|
+
if (!contains(root)) {
|
|
209
|
+
return std::nullopt;
|
|
210
|
+
}
|
|
211
|
+
return origin;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
} // namespace ngn
|
|
215
|
+
|
|
216
|
+
namespace ngn {
|
|
217
|
+
|
|
218
|
+
std::vector<Tag> ViewTree::chain(Tag tag, Tag root) const {
|
|
219
|
+
std::vector<Tag> chain;
|
|
220
|
+
for (Tag current = tag;;) {
|
|
221
|
+
const Node *node = find(current);
|
|
222
|
+
if (node == nullptr) {
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
chain.push_back(current);
|
|
226
|
+
if (current == root) {
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
current = node->parent;
|
|
230
|
+
}
|
|
231
|
+
return {chain.rbegin(), chain.rend()};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
} // namespace ngn
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#include "ngn/web-view.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/processes.h"
|
|
4
|
+
|
|
5
|
+
#include <folly/json.h>
|
|
6
|
+
|
|
7
|
+
#include <regex>
|
|
8
|
+
|
|
9
|
+
namespace ngn {
|
|
10
|
+
|
|
11
|
+
std::string webViewOrigin(const std::string &url) {
|
|
12
|
+
static const std::regex origin(R"(^[A-Za-z][A-Za-z0-9+\-.]+:(//)?[^/]*)");
|
|
13
|
+
std::smatch match;
|
|
14
|
+
return std::regex_search(url, match, origin) ? match.str(0) : "";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
bool passesOriginWhitelist(const std::vector<std::string> &whitelist, const std::string &url) {
|
|
18
|
+
if (url.rfind("about:", 0) == 0 || url.rfind("data:", 0) == 0) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
auto origin = webViewOrigin(url);
|
|
22
|
+
for (const auto &pattern : whitelist) {
|
|
23
|
+
std::string expression = "^";
|
|
24
|
+
for (char c : pattern) {
|
|
25
|
+
if (c == '*') {
|
|
26
|
+
expression += ".*";
|
|
27
|
+
} else if (std::string_view("\\^$.|?+()[]{}-").find(c) != std::string_view::npos) {
|
|
28
|
+
expression += '\\';
|
|
29
|
+
expression += c;
|
|
30
|
+
} else {
|
|
31
|
+
expression += c;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (std::regex_search(origin, std::regex(expression))) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
NavigationStep navigationStep(const WebViewConfig &config, const std::string &url, bool topFrame, std::string_view navigationType) {
|
|
42
|
+
if (topFrame && config.originWhitelist && !passesOriginWhitelist(*config.originWhitelist, url)) {
|
|
43
|
+
bool userActivated = navigationType == "click" || navigationType == "formsubmit";
|
|
44
|
+
return userActivated && externalUrlAllowed(url) ? NavigationStep::OpenExternally : NavigationStep::Cancel;
|
|
45
|
+
}
|
|
46
|
+
return NavigationStep::AskApp;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
std::string webViewMessagingScript() {
|
|
50
|
+
return "window.ReactNativeWebView = window.ReactNativeWebView || {};"
|
|
51
|
+
"window.ReactNativeWebView.postMessage = function (data) {"
|
|
52
|
+
" window.webkit.messageHandlers.ReactNativeWebView.postMessage(String(data));"
|
|
53
|
+
"};";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
std::string webViewInjectedObjectScript(const std::string &json) {
|
|
57
|
+
return "window.ReactNativeWebView = window.ReactNativeWebView || {};"
|
|
58
|
+
"window.ReactNativeWebView.injectedObjectJson = function () { return " +
|
|
59
|
+
folly::toJson(json) + "; };";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
std::string webViewPostMessageScript(const std::string &data) {
|
|
63
|
+
return "window.dispatchEvent(new MessageEvent('message', " + folly::toJson(folly::dynamic::object("data", data)) + "));";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
folly::dynamic webViewEvent(const WebViewState &state) {
|
|
67
|
+
return folly::dynamic::object("url", state.url)("title", state.title)("loading", state.loading)("canGoBack", state.canGoBack)(
|
|
68
|
+
"canGoForward", state.canGoForward);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
int NavigationLocks::hold(std::function<void(bool)> decide) {
|
|
72
|
+
std::lock_guard lock(mutex_);
|
|
73
|
+
int id = next_++;
|
|
74
|
+
held_[id] = std::move(decide);
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
bool NavigationLocks::settle(int lock, bool shouldStart) {
|
|
79
|
+
std::function<void(bool)> decide;
|
|
80
|
+
{
|
|
81
|
+
std::lock_guard guard(mutex_);
|
|
82
|
+
auto found = held_.find(lock);
|
|
83
|
+
if (found == held_.end()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
decide = std::move(found->second);
|
|
87
|
+
held_.erase(found);
|
|
88
|
+
}
|
|
89
|
+
// Outside the lock: the answer may start another navigation, which holds again.
|
|
90
|
+
decide(shouldStart);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
size_t NavigationLocks::pending() const {
|
|
95
|
+
std::lock_guard lock(mutex_);
|
|
96
|
+
return held_.size();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
std::shared_ptr<NavigationLocks> sharedNavigationLocks() {
|
|
100
|
+
static auto locks = std::make_shared<NavigationLocks>();
|
|
101
|
+
return locks;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
std::shared_ptr<NativeModule> makeWebViewModule(std::shared_ptr<NavigationLocks> locks) {
|
|
105
|
+
struct WebViewModule : NativeModule {
|
|
106
|
+
explicit WebViewModule(std::shared_ptr<NavigationLocks> locks) : NativeModule("RNCWebViewModule") {
|
|
107
|
+
sync("shouldStartLoadWithLockIdentifier", [locks](const folly::dynamic &args) -> folly::dynamic {
|
|
108
|
+
if (args.size() < 2 || !args[1].isNumber()) {
|
|
109
|
+
return nullptr;
|
|
110
|
+
}
|
|
111
|
+
locks->settle(static_cast<int>(args[1].asDouble()), args[0].isBool() && args[0].asBool());
|
|
112
|
+
return nullptr;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return std::make_shared<WebViewModule>(std::move(locks));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
std::optional<WebViewFile> webViewFile(const FileAccess *access, const std::string &uri) {
|
|
120
|
+
if (!uri.starts_with('/') && !isFileScheme(uri)) {
|
|
121
|
+
return std::nullopt;
|
|
122
|
+
}
|
|
123
|
+
auto source = readableSource(access, uri);
|
|
124
|
+
auto path = *pathOfUri(source.uri);
|
|
125
|
+
auto folder = path.substr(0, path.rfind('/'));
|
|
126
|
+
std::string readAccess = source.uri;
|
|
127
|
+
auto use = source.use;
|
|
128
|
+
if (!folder.empty()) {
|
|
129
|
+
try {
|
|
130
|
+
auto folderUse = readableFile(access, folder);
|
|
131
|
+
readAccess = fileUri(folder) + "/";
|
|
132
|
+
// The page reads its whole folder: the folder's pick is held open, which holds the file
|
|
133
|
+
// too, where the folder is a pick of its own.
|
|
134
|
+
if (folderUse && folderUse->started()) {
|
|
135
|
+
use = std::move(folderUse);
|
|
136
|
+
}
|
|
137
|
+
} catch (const FileRefused &) {
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return WebViewFile{.uri = source.uri, .readAccess = readAccess, .use = use};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
} // namespace ngn
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Builds Hermes as a static library (hermesvm_a) against React Native's jsi, and its compiler
|
|
3
|
+
# (hermesc), into the cache.
|
|
4
|
+
#
|
|
5
|
+
# build-hermes.sh <node_modules/react-native> [architectures, default: this Mac's]
|
|
6
|
+
#
|
|
7
|
+
# Release, debugger on, Intl on (as React Native's Apple builds are), HV32 heap. The flags follow
|
|
8
|
+
# Basalt's bootstrap.sh (Basalt 0.2.9, MIT, Copyright (c) 2026 Vince Vella), which mirrors React
|
|
9
|
+
# Native's own host build. jsi is not in the archive: the host compiles React Native's copy once.
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
here="$(cd "$(dirname "$0")" && pwd)"
|
|
12
|
+
RN_PKG="$(cd "${1:?usage: build-hermes.sh <node_modules/react-native> [architectures]}" && pwd)"
|
|
13
|
+
ARCHS="${2:-$(uname -m)}"
|
|
14
|
+
RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
|
|
15
|
+
CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
|
|
16
|
+
JOBS="${NGN_JOBS:-8}"
|
|
17
|
+
OUT="$CACHE/hermes-${ARCHS//;/-}"
|
|
18
|
+
TARGET="$("$here/macos-target.sh")"
|
|
19
|
+
|
|
20
|
+
[ -d "$CACHE/src/hermes" ] || { echo "build-hermes.sh: run fetch.sh first" >&2; exit 1; }
|
|
21
|
+
|
|
22
|
+
intl=OFF
|
|
23
|
+
[ "$(uname -s)" = "Darwin" ] && intl=ON
|
|
24
|
+
launcher_args=()
|
|
25
|
+
while IFS= read -r arg; do
|
|
26
|
+
launcher_args+=("$arg")
|
|
27
|
+
done < <("$here/compiler-launcher.sh" "${NGN_COMPILER_LAUNCHER:-}")
|
|
28
|
+
cmake --log-level=ERROR -G Ninja -S "$CACHE/src/hermes" -B "$OUT" \
|
|
29
|
+
-DJSI_DIR="$RN_PKG/ReactCommon/jsi" \
|
|
30
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
31
|
+
-DCMAKE_OSX_ARCHITECTURES="$ARCHS" \
|
|
32
|
+
-DCMAKE_OSX_DEPLOYMENT_TARGET="$TARGET" \
|
|
33
|
+
-DHERMES_ENABLE_DEBUGGER=ON \
|
|
34
|
+
-DHERMES_ENABLE_INTL="$intl" \
|
|
35
|
+
-DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32 \
|
|
36
|
+
-DHERMES_ENABLE_TEST_SUITE=OFF \
|
|
37
|
+
-DHERMES_BUILD_APPLE_FRAMEWORK=OFF \
|
|
38
|
+
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
|
|
39
|
+
${launcher_args[@]+"${launcher_args[@]}"}
|
|
40
|
+
# hermesc too, which compiles a packaged app's bundle to this Hermes's bytecode.
|
|
41
|
+
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"
|
|
44
|
+
echo "$OUT"
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Builds the desktop host (or only the core and its tests) in the per-user cache, fetching the
|
|
3
|
+
# pinned sources and building Hermes first when they are missing. Prints the build directory.
|
|
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>]
|
|
8
|
+
#
|
|
9
|
+
# Without a path, react-native is resolved from the current directory.
|
|
10
|
+
#
|
|
11
|
+
# --backend none the toolkit-free core and its tests only: any OS, no Hermes
|
|
12
|
+
# --universal arm64 and x86_64 in one binary (default: this machine's architecture)
|
|
13
|
+
# --debug a Debug build (default: RelWithDebInfo)
|
|
14
|
+
# --release a Release build without the core tests, as a packaged app ships it
|
|
15
|
+
# --test run the core tests after building
|
|
16
|
+
# --no-tests leave the core tests out, as an app's build does: the published package has
|
|
17
|
+
# none of their sources
|
|
18
|
+
# --no-debug-info the default RelWithDebInfo build without its debug info, for a host that is
|
|
19
|
+
# stripped anyway (make-prebuilt.mjs): the same code, compiled and linked faster
|
|
20
|
+
# --library a library whose Fabric components the host compiles in (its codegen, by
|
|
21
|
+
# scripts/codegen-library.sh); repeatable. A build without one drops them all.
|
|
22
|
+
# --build-dir build here instead of the cache's shared build directory, for a build that
|
|
23
|
+
# no other may touch before its output is copied (make-prebuilt.mjs)
|
|
24
|
+
#
|
|
25
|
+
# An app that links nothing builds in a directory keyed by this install's native sources and the
|
|
26
|
+
# libraries it compiles in (scripts/host-dir.sh), shared only with apps that build the same.
|
|
27
|
+
#
|
|
28
|
+
# NGN_DESKTOP_LINK names the app's link.json (bin/autolink.mjs): the libraries and app modules
|
|
29
|
+
# compiled in (cmake/linked-modules.cmake). An app that links any builds in a directory of its own,
|
|
30
|
+
# so its native code never rebuilds another app's host, and adding or removing one recompiles that
|
|
31
|
+
# one and relinks.
|
|
32
|
+
#
|
|
33
|
+
# NGN_JOBS caps parallel compiles (default 8).
|
|
34
|
+
#
|
|
35
|
+
# NGN_COMPILER_LAUNCHER, e.g. ccache, runs every compile of the host and of Hermes through it.
|
|
36
|
+
# Unset, the build is as it was.
|
|
37
|
+
set -euo pipefail
|
|
38
|
+
here="$(cd "$(dirname "$0")" && pwd)"
|
|
39
|
+
if [ $# -gt 0 ] && [ "${1#--}" = "$1" ]; then
|
|
40
|
+
RN_PKG="$(cd "$1" && pwd)"
|
|
41
|
+
shift
|
|
42
|
+
else
|
|
43
|
+
RN_PKG="$(node -p "require('path').dirname(require.resolve('react-native/package.json', { paths: [process.cwd()] }))")"
|
|
44
|
+
fi
|
|
45
|
+
backend=none
|
|
46
|
+
[ "$(uname -s)" = "Darwin" ] && backend=appkit
|
|
47
|
+
archs="$(uname -m)"
|
|
48
|
+
config=RelWithDebInfo
|
|
49
|
+
run_tests=0
|
|
50
|
+
tests=ON
|
|
51
|
+
no_tests=0
|
|
52
|
+
libraries=()
|
|
53
|
+
build_dir=""
|
|
54
|
+
debug_info=1
|
|
55
|
+
while [ $# -gt 0 ]; do
|
|
56
|
+
case "$1" in
|
|
57
|
+
--backend) backend="$2"; shift ;;
|
|
58
|
+
--universal) archs="arm64;x86_64" ;;
|
|
59
|
+
--debug) config=Debug ;;
|
|
60
|
+
--release) config=Release; tests=OFF ;;
|
|
61
|
+
--test) run_tests=1 ;;
|
|
62
|
+
--no-tests) tests=OFF; no_tests=1 ;;
|
|
63
|
+
--no-debug-info) debug_info=0 ;;
|
|
64
|
+
--library) libraries+=("$2"); shift ;;
|
|
65
|
+
--build-dir) build_dir="$2"; shift ;;
|
|
66
|
+
*) echo "build.sh: unknown option $1" >&2; exit 2 ;;
|
|
67
|
+
esac
|
|
68
|
+
shift
|
|
69
|
+
done
|
|
70
|
+
if [ "$run_tests" = 1 ] && [ "$tests" = OFF ]; then
|
|
71
|
+
if [ "$no_tests" = 1 ]; then left_out=--no-tests; else left_out=--release; fi
|
|
72
|
+
echo "build.sh: --test needs the core tests, which $left_out leaves out" >&2
|
|
73
|
+
exit 2
|
|
74
|
+
fi
|
|
75
|
+
# CMAKE_OSX_ARCHITECTURES means nothing off macOS.
|
|
76
|
+
[ "$(uname -s)" = "Darwin" ] || archs=""
|
|
77
|
+
|
|
78
|
+
JOBS="${NGN_JOBS:-8}"
|
|
79
|
+
RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
|
|
80
|
+
CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
|
|
81
|
+
|
|
82
|
+
"$here/fetch.sh" "$RN_PKG" >&2
|
|
83
|
+
|
|
84
|
+
library_dirs=""
|
|
85
|
+
for lib in ${libraries[@]+"${libraries[@]}"}; do
|
|
86
|
+
library_dirs="$library_dirs${library_dirs:+;}$("$here/codegen-library.sh" "$RN_PKG" "$lib")"
|
|
87
|
+
done
|
|
88
|
+
|
|
89
|
+
link_args=()
|
|
90
|
+
# Keyed by this install's native sources and the libraries compiled in, so another install or an
|
|
91
|
+
# app with other libraries never rebuilds this one's executable.
|
|
92
|
+
native_dir="$(cd "$here/.." && pwd -P)"
|
|
93
|
+
library_list=()
|
|
94
|
+
[ -n "$library_dirs" ] && IFS=';' read -ra library_list <<< "$library_dirs"
|
|
95
|
+
host_dir="$("$here/host-dir.sh" "$CACHE" "$native_dir" ${library_list[@]+"${library_list[@]}"})"
|
|
96
|
+
if [ -n "${NGN_DESKTOP_LINK:-}" ] && [ "$backend" != "none" ]; then
|
|
97
|
+
link="$(cd "$(dirname "$NGN_DESKTOP_LINK")" && pwd -P)/$(basename "$NGN_DESKTOP_LINK")"
|
|
98
|
+
# The libraries' package names and directories, one per line, when the app links anything.
|
|
99
|
+
linked="$(node -e '
|
|
100
|
+
const link = require(process.argv[1]);
|
|
101
|
+
if (link.version !== 1) { console.error(`build.sh: ${process.argv[1]} is version ${link.version}, not 1`); process.exit(1); }
|
|
102
|
+
if (link.libraries.length + link.appModules.length === 0) process.exit(0);
|
|
103
|
+
console.log("linked");
|
|
104
|
+
for (const lib of link.libraries) console.log(`${lib.name}\t${lib.dir}`);
|
|
105
|
+
' "$link")"
|
|
106
|
+
if [ -n "$linked" ]; then
|
|
107
|
+
codegen=""
|
|
108
|
+
while IFS=$'\t' read -r name dir; do
|
|
109
|
+
out="$("$here/codegen-library.sh" "$RN_PKG" "$dir" --modules)"
|
|
110
|
+
[ -n "$out" ] && codegen="$codegen${codegen:+;}$name|$out"
|
|
111
|
+
# Its Fabric components, when it has any: compiled in and registered like a --library's.
|
|
112
|
+
[ -n "$out" ] && [ -f "$out/library.cmake" ] && library_dirs="$library_dirs${library_dirs:+;}$out"
|
|
113
|
+
done < <(tail -n +2 <<< "$linked")
|
|
114
|
+
# The app is link.json's .expo/ng-native-desktop/..
|
|
115
|
+
app="$(cd "$(dirname "$link")/../.." && pwd -P)"
|
|
116
|
+
host_dir="$CACHE/host/app-$(printf '%s' "$app" | shasum | cut -c1-12)"
|
|
117
|
+
mkdir -p "$host_dir"
|
|
118
|
+
echo "$app" > "$host_dir/app"
|
|
119
|
+
link_args=(-DNGN_DESKTOP_LINK="$link" -DNGN_LINK_CODEGEN="$codegen")
|
|
120
|
+
fi
|
|
121
|
+
fi
|
|
122
|
+
[ ${#link_args[@]} -eq 0 ] && link_args=(-DNGN_DESKTOP_LINK= -DNGN_LINK_CODEGEN=)
|
|
123
|
+
|
|
124
|
+
launcher_args=()
|
|
125
|
+
while IFS= read -r arg; do
|
|
126
|
+
launcher_args+=("$arg")
|
|
127
|
+
done < <("$here/compiler-launcher.sh" "${NGN_COMPILER_LAUNCHER:-}")
|
|
128
|
+
|
|
129
|
+
# RelWithDebInfo's flags, with or without -g, set either way: CMake keeps a -D in the build
|
|
130
|
+
# directory's cache, so a build with debug info after one without would otherwise go without too.
|
|
131
|
+
# Hermes builds as Release, which has none.
|
|
132
|
+
flags_args=()
|
|
133
|
+
if [ "$config" = RelWithDebInfo ]; then
|
|
134
|
+
flags="-O2 -g -DNDEBUG"
|
|
135
|
+
[ "$debug_info" = 0 ] && flags="-O2 -DNDEBUG"
|
|
136
|
+
langs=(C CXX)
|
|
137
|
+
[ "$(uname -s)" = "Darwin" ] && langs+=(OBJC OBJCXX)
|
|
138
|
+
for lang in "${langs[@]}"; do
|
|
139
|
+
flags_args+=("-DCMAKE_${lang}_FLAGS_RELWITHDEBINFO=$flags")
|
|
140
|
+
done
|
|
141
|
+
fi
|
|
142
|
+
|
|
143
|
+
arch_key="${archs//;/-}"
|
|
144
|
+
hermes_args=()
|
|
145
|
+
if [ "$backend" != "none" ]; then
|
|
146
|
+
hermes="$CACHE/hermes-$arch_key"
|
|
147
|
+
# Built again when missing, or built for another macOS than the host's.
|
|
148
|
+
if ! "$here/hermes-built.sh" "$hermes"; then
|
|
149
|
+
"$here/build-hermes.sh" "$RN_PKG" "$archs" >&2
|
|
150
|
+
fi
|
|
151
|
+
hermes_args=(-DNGN_HERMES_BUILD="$hermes")
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
BUILD="${build_dir:-$host_dir/$backend-${arch_key:-native}-$config}"
|
|
155
|
+
cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
|
|
156
|
+
-DCMAKE_BUILD_TYPE="$config" \
|
|
157
|
+
-DCMAKE_OSX_ARCHITECTURES="$archs" \
|
|
158
|
+
-DNGN_BACKEND="$backend" \
|
|
159
|
+
-DRN_DIR="$RN_PKG" \
|
|
160
|
+
-DNGN_SOURCES="$CACHE/src" \
|
|
161
|
+
-DNGN_LIBRARIES="$library_dirs" \
|
|
162
|
+
-DNGN_TESTS="$tests" \
|
|
163
|
+
"${link_args[@]}" \
|
|
164
|
+
${launcher_args[@]+"${launcher_args[@]}"} \
|
|
165
|
+
${flags_args[@]+"${flags_args[@]}"} \
|
|
166
|
+
${hermes_args[@]+"${hermes_args[@]}"} >&2
|
|
167
|
+
nice -n 10 cmake --build "$BUILD" -j "$JOBS" >&2
|
|
168
|
+
if [ "$run_tests" = 1 ]; then
|
|
169
|
+
"$BUILD/ngn_core_tests" >&2
|
|
170
|
+
fi
|
|
171
|
+
echo "$BUILD"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Prints the per-user build cache for one React Native version:
|
|
3
|
+
#
|
|
4
|
+
# macOS ~/Library/Caches/ng-native/desktop/rn-<version>
|
|
5
|
+
# Linux ${XDG_CACHE_HOME:-~/.cache}/ng-native/desktop/rn-<version>
|
|
6
|
+
#
|
|
7
|
+
# NGN_DESKTOP_CACHE replaces the part before rn-<version> (CI points it at a cached directory).
|
|
8
|
+
# bin/host.mjs computes the same path for the ng-native-desktop bin; keep the two in step.
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
version="${1:?usage: cache-dir.sh <react-native version>}"
|
|
11
|
+
if [ -n "${NGN_DESKTOP_CACHE:-}" ]; then
|
|
12
|
+
root="$NGN_DESKTOP_CACHE"
|
|
13
|
+
elif [ "$(uname -s)" = "Darwin" ]; then
|
|
14
|
+
root="$HOME/Library/Caches/ng-native/desktop"
|
|
15
|
+
else
|
|
16
|
+
root="${XDG_CACHE_HOME:-$HOME/.cache}/ng-native/desktop"
|
|
17
|
+
fi
|
|
18
|
+
echo "$root/rn-$version"
|