| 125 | } |
| 126 | |
| 127 | function printUsage() { |
| 128 | console.log(`Usage: |
| 129 | node scripts/experimental/swiftui-preview.mjs --udid <sim> --file <Preview.swift> [options] |
| 130 | |
| 131 | Options: |
| 132 | --preview <name-or-index> Select a #Preview block. Defaults to the first one. |
| 133 | --watch, -w Recompile and dlopen a new payload after file changes. |
| 134 | --extra-swift <file> Include another Swift file. Can be repeated. |
| 135 | --swiftc-arg <arg> Pass an extra argument to swiftc. Can be repeated. |
| 136 | --workspace <path> Use an Xcode workspace for compatibility mode. |
| 137 | --project <path> Use an Xcode project for compatibility mode. |
| 138 | --scheme <name> Xcode scheme to build for compatibility mode. |
| 139 | --configuration <name> Xcode configuration. Default: Debug. |
| 140 | --derived-data-path <path> DerivedData path for Xcode builds. |
| 141 | --skip-xcode-build Reuse existing Xcode build artifacts. |
| 142 | --skip-codesign Do not ad-hoc sign reload dylibs. |
| 143 | --profile Print reload-stage timings. |
| 144 | --split-compile Cache the preview source as a testable Swift module. |
| 145 | --bundle-id <id> Host bundle id. Default: ${DEFAULT_BUNDLE_ID} |
| 146 | --build-root <path> Build/cache directory. Default: .simdeck-preview/build |
| 147 | --rebuild-host Rebuild and reinstall the stable host app. |
| 148 | |
| 149 | This is intentionally experimental. It extracts simple #Preview { ... } bodies, |
| 150 | builds them into a versioned simulator dylib, and asks a tiny host app to dlopen |
| 151 | the new dylib without reinstalling the host. |
| 152 | |
| 153 | When --workspace/--project and --scheme are supplied, the runner builds the real |
| 154 | app target once, copies its resources/frameworks into the host, and links reload |
| 155 | dylibs against the target's Xcode-built debug dylib. That is the faster Xcode-ish |
| 156 | path: reloads compile the edited preview source plus a tiny wrapper, not the full |
| 157 | app target.`); |
| 158 | } |
| 159 | |
| 160 | function buildHostApp(context, rebuildHost) { |
| 161 | const appPath = path.join(context.buildRoot, "SimDeckPreviewHost.app"); |