@tokamakdev/platform-macos-x64 0.1.1-beta.155 → 0.1.1-beta.158
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/macos-x64/build/entrypoint +186 -90
- package/macos-x64/frameworks/TokamakRuntime.xcframework/Info.plist +29 -0
- package/macos-x64/frameworks/{TokamakRuntime.framework → TokamakRuntime.xcframework/macos-x86_64}/Headers/TokamakRuntime.h +8 -6
- package/macos-x64/frameworks/TokamakRuntime.xcframework/macos-x86_64/Headers/module.modulemap +4 -0
- package/macos-x64/frameworks/{TokamakRuntime.framework/TokamakRuntime → TokamakRuntime.xcframework/macos-x86_64/libtokamak.a} +0 -0
- package/macos-x64/native-shell/TokamakApp.swift +19 -25
- package/macos-x64/native-shell/TokamakControls.swift +1 -0
- package/macos-x64/plugin-api/TokamakPlugin/Package.swift +12 -0
- package/macos-x64/{native-shell → plugin-api/TokamakPlugin/Sources/TokamakPlugin}/TokamakExports.swift +63 -61
- package/macos-x64/{native-shell → plugin-api/TokamakPlugin/Sources/TokamakPlugin}/TokamakPlugins.swift +110 -50
- package/macos-x64/{native-shell → plugin-api/TokamakPlugin/Sources/TokamakPlugin}/TokamakResources.swift +5 -3
- package/macos-x64/tools/tokamak-apple-signing +0 -0
- package/macos-x64/tools/tokamak-swift-describe +2 -2
- package/package.json +1 -1
- package/macos-x64/frameworks/TokamakRuntime.framework/Modules/module.modulemap +0 -4
|
@@ -12,13 +12,14 @@ if [[ $# -eq 1 && $1 == certs ]]; then
|
|
|
12
12
|
exec "$apple_tool" inventory
|
|
13
13
|
fi
|
|
14
14
|
|
|
15
|
-
# Describes the methods
|
|
16
|
-
# into OUTPUT/description.json, with the dispatch that serves
|
|
17
|
-
# OUTPUT/Exports.generated.swift. The compiler's symbol
|
|
18
|
-
#
|
|
15
|
+
# Describes the methods the plugin's registration file REGISTRATION exports
|
|
16
|
+
# on each PLATFORM into OUTPUT/description.json, with the dispatch that serves
|
|
17
|
+
# them, OUTPUT/Exports.generated.swift. The compiler's symbol graphs of the
|
|
18
|
+
# plugin's module and the plugin API, built for each platform, give the
|
|
19
|
+
# methods' types.
|
|
19
20
|
describe() {
|
|
20
|
-
local plugin=$1 output=$
|
|
21
|
-
shift
|
|
21
|
+
local plugin=$1 registration=$2 output=$3
|
|
22
|
+
shift 3
|
|
22
23
|
if ! xcrun --sdk iphonesimulator --show-sdk-path > /dev/null 2>&1; then
|
|
23
24
|
echo "Describing an Apple plugin needs Xcode" >&2
|
|
24
25
|
exit 69
|
|
@@ -26,56 +27,56 @@ describe() {
|
|
|
26
27
|
# Global, for the exit trap.
|
|
27
28
|
temporary=$(mktemp -d "${TMPDIR:-/tmp}/tokamak-describe.XXXXXX")
|
|
28
29
|
trap 'rm -rf "$temporary"' EXIT
|
|
29
|
-
|
|
30
|
-
local sources=("$pack/native-shell"/*.swift "$temporary/registry.swift") source
|
|
31
|
-
while IFS= read -r -d '' source; do
|
|
32
|
-
[[ ${source##*/} == Exports.generated.swift ]] || sources+=("$source")
|
|
33
|
-
done < <(find "$plugin/apple" -name '*.swift' -print0 | sort -z)
|
|
34
|
-
local graphs=() compiles=() platform sdk triple
|
|
30
|
+
local platform destination class module packages graphs=() builds=()
|
|
35
31
|
for platform in "$@"; do
|
|
36
32
|
case "$platform" in
|
|
37
|
-
ios)
|
|
38
|
-
|
|
39
|
-
triple=$(uname -m)-apple-ios$(<"$pack/build/ios-deployment-target")-simulator
|
|
40
|
-
;;
|
|
41
|
-
macos)
|
|
42
|
-
sdk=macosx
|
|
43
|
-
triple=$(uname -m)-apple-macos$(<"$pack/build/macos-deployment-target")
|
|
44
|
-
;;
|
|
33
|
+
ios) destination='generic/platform=iOS Simulator' ;;
|
|
34
|
+
macos) destination='generic/platform=macOS' ;;
|
|
45
35
|
*)
|
|
46
36
|
echo "Apple plugins run on ios and macos, not $platform" >&2
|
|
47
37
|
exit 2
|
|
48
38
|
;;
|
|
49
39
|
esac
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
class=$(plutil -extract "platforms.$platform.class" raw -o - "$plugin/tokamak-plugin.json")
|
|
41
|
+
module=${class%%.*}
|
|
42
|
+
# Each platform builds its own copy of the plugin's package, staged as the
|
|
43
|
+
# app's build stages it, without the dispatch describing regenerates.
|
|
44
|
+
packages=$temporary/$platform/packages
|
|
45
|
+
mkdir -p "$packages/node_modules/@tokamakdev/plugin/apple"
|
|
46
|
+
cp -R "$pack/plugin-api/TokamakPlugin" "$packages/node_modules/@tokamakdev/plugin/apple/"
|
|
47
|
+
rsync -a --exclude .build --exclude .swiftpm "$plugin/apple/" "$packages/plugin/"
|
|
48
|
+
find "$packages/plugin" -name Exports.generated.swift -delete
|
|
49
|
+
# The platforms build at once, each into its own log.
|
|
50
|
+
(
|
|
51
|
+
cd "$packages/plugin"
|
|
52
|
+
xcodebuild build -quiet -scheme "$module" -destination "$destination" \
|
|
53
|
+
-derivedDataPath "$temporary/$platform/build" \
|
|
54
|
+
-skipPackagePluginValidation -skipMacroValidation \
|
|
55
|
+
ARCHS="$(uname -m)" ONLY_ACTIVE_ARCH=NO CODE_SIGNING_ALLOWED=NO \
|
|
56
|
+
"OTHER_SWIFT_FLAGS=\$(inherited) -emit-symbol-graph -emit-symbol-graph-dir $temporary/$platform -symbol-graph-minimum-access-level private"
|
|
57
|
+
) > "$temporary/$platform.log" 2>&1 &
|
|
58
|
+
builds+=("$!")
|
|
59
|
+
graphs+=("$platform=$temporary/$platform/$module.symbols.json" "$platform=$temporary/$platform/TokamakPlugin.symbols.json")
|
|
59
60
|
done
|
|
60
61
|
# The platforms report the same diagnostics, so only the first failure's
|
|
61
62
|
# show, or else the first platform's warnings.
|
|
62
63
|
local platforms=("$@") index failed=
|
|
63
|
-
for index in "${!
|
|
64
|
-
if ! wait "${
|
|
64
|
+
for index in "${!builds[@]}"; do
|
|
65
|
+
if ! wait "${builds[index]}" && [[ -z $failed ]]; then
|
|
65
66
|
failed=$index
|
|
66
67
|
fi
|
|
67
68
|
done
|
|
68
69
|
cat "$temporary/${platforms[${failed:-0}]}.log" >&2
|
|
69
70
|
[[ -z $failed ]] || exit 1
|
|
70
|
-
"$pack/tools/tokamak-swift-describe" "$
|
|
71
|
+
"$pack/tools/tokamak-swift-describe" "$registration" "$output" "${graphs[@]}"
|
|
71
72
|
}
|
|
72
|
-
if [[ $# -ge
|
|
73
|
+
if [[ $# -ge 5 && $1 == describe ]]; then
|
|
73
74
|
describe "${@:2}"
|
|
74
75
|
exit
|
|
75
76
|
fi
|
|
76
77
|
|
|
77
78
|
if [[ $# -ne 3 || $1 != build ]]; then
|
|
78
|
-
echo "usage: entrypoint build INPUT OUTPUT | entrypoint describe PLUGIN OUTPUT PLATFORM... | entrypoint certs" >&2
|
|
79
|
+
echo "usage: entrypoint build INPUT OUTPUT | entrypoint describe PLUGIN REGISTRATION OUTPUT PLATFORM... | entrypoint certs" >&2
|
|
79
80
|
exit 2
|
|
80
81
|
fi
|
|
81
82
|
|
|
@@ -89,7 +90,6 @@ target=$(cat "$metadata/target")
|
|
|
89
90
|
project_dir=$(cat "$metadata/project-dir")
|
|
90
91
|
minimum=$(<"$pack/build/$platform-deployment-target")
|
|
91
92
|
output_parent=$(dirname "$output")
|
|
92
|
-
module_cache=$output_parent/.tokamak/module-cache
|
|
93
93
|
temporary=$(mktemp -d "${TMPDIR:-/tmp}/tokamak-apple.XXXXXX")
|
|
94
94
|
trap 'rm -rf "$temporary"' EXIT
|
|
95
95
|
|
|
@@ -197,7 +197,7 @@ fi
|
|
|
197
197
|
|
|
198
198
|
rm -f "$bundle_key_file" "$icon_info_plist"
|
|
199
199
|
rm -rf "$bundle"
|
|
200
|
-
mkdir -p "$executable_dir" "$app_dir" "$
|
|
200
|
+
mkdir -p "$executable_dir" "$app_dir" "$output_parent/.tokamak"
|
|
201
201
|
cp -R "$input/app/." "$app_dir/"
|
|
202
202
|
|
|
203
203
|
if [[ -n "$icon" ]]; then
|
|
@@ -220,28 +220,46 @@ if [[ -n "$icon" ]]; then
|
|
|
220
220
|
fi
|
|
221
221
|
|
|
222
222
|
shopt -s nullglob
|
|
223
|
-
swift_sources=("$pack/native-shell"/*.swift)
|
|
224
223
|
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
|
|
228
|
-
#
|
|
229
|
-
#
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
# The app is a Swift package, which xcodebuild builds: an executable of the
|
|
225
|
+
# shell and the plugin registry that depends on the runtime, the plugin API
|
|
226
|
+
# and each plugin's package. Each plugin's package is staged as its id, beside
|
|
227
|
+
# the plugin API at the path its dependency on the API names. The packages are
|
|
228
|
+
# generated here, then synced to the target's staging directory, whose
|
|
229
|
+
# unchanged files the build reuses. Its fixed paths also keep the pins of the
|
|
230
|
+
# lock file, which xcodebuild drops when the packages' paths change.
|
|
231
|
+
generated=$temporary/swift
|
|
232
|
+
packages=$generated/packages
|
|
233
|
+
app_package=$generated/app
|
|
234
|
+
staging=$output_parent/.tokamak/swift/$target
|
|
235
|
+
plugin_api=$staging/packages/node_modules/@tokamakdev/plugin/apple/TokamakPlugin
|
|
236
|
+
mkdir -p "$app_package/Sources/App" "$packages/node_modules/@tokamakdev/plugin/apple"
|
|
237
|
+
cp -R "$pack/plugin-api/TokamakPlugin" "$packages/node_modules/@tokamakdev/plugin/apple/"
|
|
238
|
+
cp "$pack/native-shell"/*.swift "$app_package/Sources/App/"
|
|
239
|
+
ln -s "$pack/frameworks/TokamakRuntime.xcframework" "$app_package/TokamakRuntime.xcframework"
|
|
240
|
+
|
|
241
|
+
# A plugin's class is a Swift type named with its module, which the package's
|
|
242
|
+
# library product of the module's name provides.
|
|
243
|
+
swift_type='^([A-Za-z_][A-Za-z0-9_]*)(\.[A-Za-z_][A-Za-z0-9_]*)+$'
|
|
232
244
|
# A plugin's compilation conditions start with its id in capitals, such as
|
|
233
|
-
# LOCATION_ for location, as
|
|
234
|
-
compilation_conditions=
|
|
235
|
-
|
|
236
|
-
|
|
245
|
+
# LOCATION_ for location, as each one applies to every module the app compiles.
|
|
246
|
+
compilation_conditions=
|
|
247
|
+
dependencies=" .package(path: \"$plugin_api\"),"$'\n'
|
|
248
|
+
products=" .product(name: \"TokamakPlugin\", package: \"TokamakPlugin\"),"$'\n'
|
|
249
|
+
imports=
|
|
250
|
+
registrations=
|
|
237
251
|
for plugin in "$input/plugins"/*/; do
|
|
238
252
|
plugin_id=$(basename "$plugin")
|
|
239
253
|
class=$(cat "$plugin/class" 2>/dev/null || true)
|
|
240
254
|
if [[ ! "$class" =~ $swift_type ]]; then
|
|
241
|
-
echo "plugin '$plugin_id' has invalid $platform class '$class'" >&2
|
|
255
|
+
echo "plugin '$plugin_id' has invalid $platform class '$class'; name it with its module, as Module.Class" >&2
|
|
256
|
+
exit 1
|
|
257
|
+
fi
|
|
258
|
+
module=${BASH_REMATCH[1]}
|
|
259
|
+
if [[ ! -f "$plugin/native/Package.swift" ]]; then
|
|
260
|
+
echo "plugin '$plugin_id' has no Swift package, apple/Package.swift" >&2
|
|
242
261
|
exit 1
|
|
243
262
|
fi
|
|
244
|
-
printf ' %s(host: TokamakHost(app: app, plugin: "%s")),\n' "$class" "$plugin_id" >> "$registry"
|
|
245
263
|
condition_prefix=$(printf '%s' "$plugin_id" | tr 'a-z-' 'A-Z_')_
|
|
246
264
|
for condition_file in "$plugin/compilation-conditions"/*; do
|
|
247
265
|
condition=$(<"$condition_file")
|
|
@@ -249,59 +267,137 @@ for plugin in "$input/plugins"/*/; do
|
|
|
249
267
|
echo "plugin '$plugin_id' has compilation condition '$condition', which must be $condition_prefix followed by letters, digits or underscores" >&2
|
|
250
268
|
exit 1
|
|
251
269
|
fi
|
|
252
|
-
compilation_conditions+=
|
|
270
|
+
compilation_conditions+=" $condition"
|
|
253
271
|
done
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
echo "plugin '$plugin_id' source $relative stages as ${named##*/}, as another source does; rename one" >&2
|
|
260
|
-
exit 1
|
|
261
|
-
fi
|
|
262
|
-
cp "$source" "$named"
|
|
263
|
-
swift_sources+=("$named")
|
|
264
|
-
done < <(find "$plugin/native" -name '*.swift' -print0 | sort -z)
|
|
272
|
+
cp -R "$plugin/native" "$packages/$plugin_id"
|
|
273
|
+
dependencies+=" .package(path: \"$staging/packages/$plugin_id\"),"$'\n'
|
|
274
|
+
products+=" .product(name: \"$module\", package: \"$plugin_id\"),"$'\n'
|
|
275
|
+
imports+="import $module"$'\n'
|
|
276
|
+
registrations+=" $class(host: TokamakHost(app: app, plugin: \"$plugin_id\")),"$'\n'
|
|
265
277
|
done
|
|
266
|
-
|
|
278
|
+
{
|
|
279
|
+
printf '%s\n' 'import TokamakPlugin'
|
|
280
|
+
printf '%s' "$imports"
|
|
281
|
+
printf '\n%s\n%s\n' 'func tokamakPlugins(app: TokamakApp) -> [any TokamakPlugin] {' ' ['
|
|
282
|
+
printf '%s' "$registrations"
|
|
283
|
+
printf '%s\n' ' ]' '}'
|
|
284
|
+
} > "$app_package/Sources/App/TokamakPluginRegistry.swift"
|
|
267
285
|
|
|
268
286
|
# The executable exports only the entry points of the runtime parts the app
|
|
269
|
-
# links
|
|
270
|
-
|
|
271
|
-
sed 's/^/_/' "$metadata/exported-symbols" > "$
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
-swift-version 5
|
|
277
|
-
-Osize
|
|
278
|
-
-whole-module-optimization
|
|
279
|
-
-module-cache-path "$module_cache"
|
|
280
|
-
-F "$pack/frameworks"
|
|
281
|
-
-framework TokamakRuntime
|
|
282
|
-
-framework CoreFoundation
|
|
283
|
-
-lc++
|
|
284
|
-
-lresolv
|
|
285
|
-
-Xlinker -dead_strip
|
|
286
|
-
-Xlinker -exported_symbols_list -Xlinker "$exported_symbols"
|
|
287
|
-
)
|
|
288
|
-
# Bash 3.2 cannot expand an empty array under set -u.
|
|
289
|
-
if [[ ${#compilation_conditions[@]} -gt 0 ]]; then
|
|
290
|
-
swift_args+=("${compilation_conditions[@]}")
|
|
287
|
+
# links, and finds the dynamic frameworks of plugins' dependencies in the
|
|
288
|
+
# bundle.
|
|
289
|
+
sed 's/^/_/' "$metadata/exported-symbols" > "$app_package/exported-symbols"
|
|
290
|
+
if [[ "$platform" == macos ]]; then
|
|
291
|
+
frameworks_path=@executable_path/../Frameworks
|
|
292
|
+
else
|
|
293
|
+
frameworks_path=@executable_path/Frameworks
|
|
291
294
|
fi
|
|
292
|
-
|
|
295
|
+
linker_flags="\"-Xlinker\", \"-exported_symbols_list\", \"-Xlinker\", \"$staging/app/exported-symbols\", \"-Xlinker\", \"-rpath\", \"-Xlinker\", \"$frameworks_path\""
|
|
293
296
|
# Simulator builds embed their entitlements in __TEXT,__entitlements, where
|
|
294
297
|
# the simulator reads them.
|
|
295
298
|
if [[ "$sdk" == iphonesimulator ]]; then
|
|
296
|
-
|
|
297
|
-
"
|
|
298
|
-
swift_args+=(-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker "$simulator_entitlements")
|
|
299
|
+
"$apple_tool" simulator-entitlements --identifier "$identifier" --output "$app_package/simulator.entitlements"
|
|
300
|
+
linker_flags+=", \"-Xlinker\", \"-sectcreate\", \"-Xlinker\", \"__TEXT\", \"-Xlinker\", \"__entitlements\", \"-Xlinker\", \"$staging/app/simulator.entitlements\""
|
|
299
301
|
fi
|
|
302
|
+
cat > "$app_package/Package.swift" <<EOF
|
|
303
|
+
// swift-tools-version: 5.9
|
|
304
|
+
|
|
305
|
+
import PackageDescription
|
|
300
306
|
|
|
301
|
-
|
|
307
|
+
let package = Package(
|
|
308
|
+
name: "App",
|
|
309
|
+
platforms: [.iOS("$(<"$pack/build/ios-deployment-target")"), .macOS("$(<"$pack/build/macos-deployment-target")")],
|
|
310
|
+
dependencies: [
|
|
311
|
+
$dependencies ],
|
|
312
|
+
targets: [
|
|
313
|
+
.binaryTarget(name: "TokamakRuntime", path: "TokamakRuntime.xcframework"),
|
|
314
|
+
.executableTarget(
|
|
315
|
+
name: "App",
|
|
316
|
+
dependencies: [
|
|
317
|
+
"TokamakRuntime",
|
|
318
|
+
$products ],
|
|
319
|
+
linkerSettings: [
|
|
320
|
+
.linkedFramework("CoreFoundation"),
|
|
321
|
+
.linkedLibrary("c++"),
|
|
322
|
+
.linkedLibrary("resolv"),
|
|
323
|
+
.unsafeFlags([$linker_flags]),
|
|
324
|
+
]
|
|
325
|
+
),
|
|
326
|
+
]
|
|
327
|
+
)
|
|
328
|
+
EOF
|
|
329
|
+
|
|
330
|
+
swift_build=$output_parent/.tokamak/swift-build/$target
|
|
331
|
+
# The app's lock file pins the versions of plugins' dependencies, which
|
|
332
|
+
# resolving updates for changed requirements. Without one, the build resolves
|
|
333
|
+
# the newest versions they allow, rather than those it resolved before.
|
|
334
|
+
lock=$input/lock/Package.resolved
|
|
335
|
+
if [[ -f "$lock" ]]; then
|
|
336
|
+
cp "$lock" "$app_package/Package.resolved"
|
|
337
|
+
else
|
|
338
|
+
rm -rf "${swift_build:?}/SourcePackages"
|
|
339
|
+
fi
|
|
340
|
+
mkdir -p "$staging"
|
|
341
|
+
rsync -rlp --checksum --delete --exclude .swiftpm "$generated/" "$staging/"
|
|
342
|
+
case "$sdk" in
|
|
343
|
+
macosx)
|
|
344
|
+
destination='generic/platform=macOS'
|
|
345
|
+
products_dir=Release
|
|
346
|
+
;;
|
|
347
|
+
iphoneos)
|
|
348
|
+
destination='generic/platform=iOS'
|
|
349
|
+
products_dir=Release-iphoneos
|
|
350
|
+
;;
|
|
351
|
+
iphonesimulator)
|
|
352
|
+
destination='generic/platform=iOS Simulator'
|
|
353
|
+
products_dir=Release-iphonesimulator
|
|
354
|
+
;;
|
|
355
|
+
esac
|
|
356
|
+
products=$swift_build/Build/Products/$products_dir
|
|
357
|
+
# The build writes the resource bundles and frameworks of the packages the
|
|
358
|
+
# app has now, without those of removed ones.
|
|
359
|
+
rm -rf "${products:?}"/*.bundle "${products:?}/PackageFrameworks"
|
|
360
|
+
# Packages' build tool plugins and macros run without the prompt Xcode
|
|
361
|
+
# shows, as plugins' build scripts do. The build keeps the exported entry
|
|
362
|
+
# points, which Xcode's own strip removes, and writes no dSYM.
|
|
363
|
+
(
|
|
364
|
+
cd "$staging/app"
|
|
365
|
+
xcodebuild build -quiet \
|
|
366
|
+
-scheme App \
|
|
367
|
+
-destination "$destination" \
|
|
368
|
+
-configuration Release \
|
|
369
|
+
-derivedDataPath "$swift_build" \
|
|
370
|
+
-skipPackagePluginValidation \
|
|
371
|
+
-skipMacroValidation \
|
|
372
|
+
ARCHS="${triple%%-*}" \
|
|
373
|
+
ONLY_ACTIVE_ARCH=NO \
|
|
374
|
+
CODE_SIGNING_ALLOWED=NO \
|
|
375
|
+
SWIFT_OPTIMIZATION_LEVEL=-Osize \
|
|
376
|
+
SWIFT_COMPILATION_MODE=wholemodule \
|
|
377
|
+
DEAD_CODE_STRIPPING=YES \
|
|
378
|
+
STRIP_INSTALLED_PRODUCT=NO \
|
|
379
|
+
DEBUG_INFORMATION_FORMAT=dwarf \
|
|
380
|
+
"SWIFT_ACTIVE_COMPILATION_CONDITIONS=\$(inherited)$compilation_conditions"
|
|
381
|
+
)
|
|
382
|
+
if [[ -f "$staging/app/Package.resolved" ]]; then
|
|
383
|
+
mkdir -p "$input/lock"
|
|
384
|
+
cp "$staging/app/Package.resolved" "$lock"
|
|
385
|
+
fi
|
|
386
|
+
cp "$products/App" "$executable_dir/$app_slug"
|
|
302
387
|
# Local symbols go; the exported entry points of linked parts stay.
|
|
303
388
|
xcrun --sdk "$sdk" strip -x "$executable_dir/$app_slug"
|
|
304
389
|
|
|
390
|
+
# Packages' resource bundles go in the bundle's resources directory, where
|
|
391
|
+
# their Bundle.module finds them, and dynamic frameworks in its frameworks
|
|
392
|
+
# directory.
|
|
393
|
+
for resource_bundle in "$products"/*.bundle; do
|
|
394
|
+
cp -R "$resource_bundle" "$resources_dir/"
|
|
395
|
+
done
|
|
396
|
+
for framework in "$products"/PackageFrameworks/*.framework; do
|
|
397
|
+
mkdir -p "$contents/Frameworks"
|
|
398
|
+
cp -R "$framework" "$contents/Frameworks/"
|
|
399
|
+
done
|
|
400
|
+
|
|
305
401
|
write_plist
|
|
306
402
|
|
|
307
403
|
# Plugins' resources go in the bundle's resources directory, where the system
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>BinaryPath</key>
|
|
9
|
+
<string>libtokamak.a</string>
|
|
10
|
+
<key>HeadersPath</key>
|
|
11
|
+
<string>Headers</string>
|
|
12
|
+
<key>LibraryIdentifier</key>
|
|
13
|
+
<string>macos-x86_64</string>
|
|
14
|
+
<key>LibraryPath</key>
|
|
15
|
+
<string>libtokamak.a</string>
|
|
16
|
+
<key>SupportedArchitectures</key>
|
|
17
|
+
<array>
|
|
18
|
+
<string>x86_64</string>
|
|
19
|
+
</array>
|
|
20
|
+
<key>SupportedPlatform</key>
|
|
21
|
+
<string>macos</string>
|
|
22
|
+
</dict>
|
|
23
|
+
</array>
|
|
24
|
+
<key>CFBundlePackageType</key>
|
|
25
|
+
<string>XFWK</string>
|
|
26
|
+
<key>XCFrameworkFormatVersion</key>
|
|
27
|
+
<string>1.0</string>
|
|
28
|
+
</dict>
|
|
29
|
+
</plist>
|
|
@@ -21,17 +21,19 @@ typedef struct {
|
|
|
21
21
|
TokamakBytes private_key;
|
|
22
22
|
} TokamakIdentity;
|
|
23
23
|
|
|
24
|
-
typedef void (*
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
typedef void (*TokamakPluginRequestCallback)(void *context, uint64_t id,
|
|
25
|
+
const char *plugin,
|
|
26
|
+
const char *method,
|
|
27
|
+
const uint8_t *payload,
|
|
28
|
+
size_t payload_len);
|
|
27
29
|
|
|
28
30
|
typedef struct {
|
|
29
31
|
void *context;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
TokamakPluginRequestCallback call;
|
|
33
|
+
TokamakPluginRequestCallback call_with_body;
|
|
32
34
|
void (*chunk)(void *context, uint64_t id, const uint8_t *payload,
|
|
33
35
|
size_t payload_len, bool failed, bool done);
|
|
34
|
-
|
|
36
|
+
TokamakPluginRequestCallback subscribe;
|
|
35
37
|
void (*cancel)(void *context, uint64_t id);
|
|
36
38
|
} TokamakPluginHandler;
|
|
37
39
|
|
|
Binary file
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import TokamakPlugin
|
|
2
3
|
import TokamakRuntime
|
|
3
4
|
import WebKit
|
|
4
5
|
|
|
@@ -17,7 +18,7 @@ private let lifecycleDeadline: TimeInterval = 10
|
|
|
17
18
|
/// The tokamak runtime and native plugins of this process. Both outlive any
|
|
18
19
|
/// WebView, so plugins receive app events before a page loads and a Worker
|
|
19
20
|
/// event can run while no page is loaded.
|
|
20
|
-
final class TokamakApp {
|
|
21
|
+
final class TokamakApp: TokamakHostApp {
|
|
21
22
|
weak var webView: WKWebView?
|
|
22
23
|
let resources = TokamakResources()
|
|
23
24
|
/// Every plugin, by ID.
|
|
@@ -123,15 +124,27 @@ final class TokamakApp {
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/// Delivers the event `name`, whose encoded data is `payload`, to the
|
|
126
|
-
/// Worker's listeners
|
|
127
|
-
///
|
|
128
|
-
///
|
|
129
|
-
///
|
|
127
|
+
/// Worker's listeners, and calls `completion` on the main thread with their
|
|
128
|
+
/// encoded reply, which is empty when none replied. Fails unless they
|
|
129
|
+
/// return within `timeout`, which includes runtime startup. Call it on the
|
|
130
|
+
/// main thread.
|
|
130
131
|
func emit(
|
|
131
132
|
_ name: String,
|
|
132
133
|
payload: Data,
|
|
133
134
|
timeout: TimeInterval,
|
|
134
|
-
|
|
135
|
+
completion: @escaping (Result<Data, Error>) -> Void
|
|
136
|
+
) {
|
|
137
|
+
emit(
|
|
138
|
+
name, payload: payload, timeout: timeout, on: .global(qos: .userInitiated),
|
|
139
|
+
completion: completion)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// `emit`, delivering on `queue`.
|
|
143
|
+
private func emit(
|
|
144
|
+
_ name: String,
|
|
145
|
+
payload: Data,
|
|
146
|
+
timeout: TimeInterval,
|
|
147
|
+
on queue: DispatchQueue,
|
|
135
148
|
completion: @escaping (Result<Data, Error>) -> Void
|
|
136
149
|
) {
|
|
137
150
|
let deadline = Date() + timeout
|
|
@@ -292,25 +305,6 @@ final class TokamakApp {
|
|
|
292
305
|
}
|
|
293
306
|
}
|
|
294
307
|
|
|
295
|
-
/// What a plugin did with a background event, reported to the system.
|
|
296
|
-
enum TokamakBackgroundResult {
|
|
297
|
-
case newData
|
|
298
|
-
case noData
|
|
299
|
-
case failed
|
|
300
|
-
|
|
301
|
-
/// New data when any plugin fetched some, otherwise a failure when any
|
|
302
|
-
/// plugin failed.
|
|
303
|
-
init(combining results: [Self]) {
|
|
304
|
-
if results.contains(.newData) {
|
|
305
|
-
self = .newData
|
|
306
|
-
} else if results.contains(.failed) {
|
|
307
|
-
self = .failed
|
|
308
|
-
} else {
|
|
309
|
-
self = .noData
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
308
|
struct RuntimeError: Error, CustomStringConvertible {
|
|
315
309
|
let description: String
|
|
316
310
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
|
|
3
|
+
import PackageDescription
|
|
4
|
+
|
|
5
|
+
// The deployment targets are the platform pack's, in
|
|
6
|
+
// platforms/apple/build/*-deployment-target.
|
|
7
|
+
let package = Package(
|
|
8
|
+
name: "TokamakPlugin",
|
|
9
|
+
platforms: [.iOS("17.0"), .macOS("14.0")],
|
|
10
|
+
products: [.library(name: "TokamakPlugin", targets: ["TokamakPlugin"])],
|
|
11
|
+
targets: [.target(name: "TokamakPlugin")]
|
|
12
|
+
)
|