| 5 | let optimizedC: [CSetting] = localCheckout ? [.unsafeFlags(["-O3"])] : [] |
| 6 | let optimizesDebug = localCheckout && Context.environment["WIDGET_SANDBOX_DEBUG_UNOPTIMIZED"] == nil |
| 7 |
| 8 | let package = Package( |
| 9 | name: "WidgetSandbox", |
| 10 | platforms: [.iOS(.v16), .macOS(.v10_13)], |
| 11 | products: [ |
| 12 | .library(name: "WidgetSandbox", targets: ["WidgetSandbox"]), |
| 13 | .library(name: "WidgetSandboxProtocol", targets: ["WidgetSandboxProtocol"]), |
| 14 | .library(name: "CQuickJS", targets: ["CQuickJS"]), |
| 15 | ], |
| 16 | targets: [ |
| 17 | // QuickJS from the TelegramMessenger/quickjs fork (quickjs-ng 0.17 with fixes; a git |
| 18 | // submodule, MIT) + a tiny shim for Swift. The same sources build the Android library, |
| 19 | // the desktop core and qjsc; the web/Node wasm is built from it in packages/quickjs-wasm. |
| 20 | .target( |
| 21 | name: "CQuickJS", |
| 22 | path: "packages/ios/Sources/CQuickJS", |
| 23 | exclude: [ |
| 24 | "quickjs/LICENSE", "quickjs/docs", "quickjs/examples", "quickjs/tests", "quickjs/test262", "quickjs/gen", |
| 25 | "quickjs/CMakeLists.txt", "quickjs/Makefile", "quickjs/README.md", "quickjs/SECURITY.md", "quickjs/meson.build", |
| 26 | "quickjs/meson_options.txt", "quickjs/amalgam.js", "quickjs/api-test.c", "quickjs/ctest.c", "quickjs/cxxtest.cc", |
| 27 | "quickjs/fuzz.c", "quickjs/gc-stress-skip.txt", "quickjs/lre-test.c", "quickjs/qjs-wasi-reactor.c", "quickjs/qjs.c", |
| 28 | "quickjs/qjs.man", "quickjs/qjsc.c", "quickjs/qjsc.man", "quickjs/quickjs-libc.c", "quickjs/repl.js", |
| 29 | "quickjs/run-test262.c", "quickjs/standalone.js", "quickjs/test262-fast.conf", "quickjs/test262.conf", |
| 30 | "quickjs/test262_errors.txt", "quickjs/tests.conf", "quickjs/unicode_download.sh", "quickjs/unicode_gen.c", |
| 31 | "quickjs/unicode_gen_def.h", "quickjs/update-version.sh", "quickjs/builtin-array-fromasync.js", |
| 32 | "quickjs/builtin-iterator-zip.js", "quickjs/builtin-iterator-zip-keyed.js", |
| 33 | ], |
| 34 | sources: ["quickjs/quickjs.c", "quickjs/dtoa.c", "quickjs/libregexp.c", "quickjs/libunicode.c", "shim/qjs_shim.c"], |
| 35 | publicHeadersPath: "include", |
| 36 | cSettings: [ |
| 37 | .headerSearchPath("include"), |
| 38 | .headerSearchPath("quickjs"), |
| 39 | .define("_GNU_SOURCE"), |
| 40 | .define("QUICKJS_NG_BUILD"), |
| 41 | .define("QJS_DISABLE_DUMPS"), |
| 42 | ] + optimizedC |
| 43 | ), |
| 44 | // Typed host -> renderer ops for in-process native renderers; no dependencies. |
| 45 | .target( |
| 46 | name: "WidgetSandboxProtocol", |
| 47 | path: "packages/ios/Sources/WidgetSandboxProtocol" |
| 48 | ), |
| 49 | .target( |
| 50 | name: "WidgetSandbox", |
| 51 | dependencies: ["CQuickJS", "WidgetSandboxProtocol"], |
| 52 | path: "packages/ios/Sources/WidgetSandbox", |
| 53 | resources: [.copy("WidgetJS")] |
| 54 | ), |
| 55 | .testTarget( |
| 56 | name: "WidgetSandboxTests", |
| 57 | dependencies: ["WidgetSandbox"], |
| 58 | path: "packages/ios/Tests/WidgetSandboxTests", |
| 59 | resources: [.copy("Fixtures")] |
| 60 | ), |
| 61 | ] |
| 62 | ) |
| 63 |
| 64 | if optimizesDebug { |
| 65 | for target in package.targets where target.type == .regular && target.name != "CQuickJS" { |
| 66 | target.swiftSettings = (target.swiftSettings ?? []) + [.unsafeFlags(["-O"], .when(configuration: .debug))] |
| 67 | } |
| 68 | } |
| 69 |