|
| 1 | +--- |
| 2 | +date: 2020-09-30 14:34 |
| 3 | +description: An update on what happened in the SwiftWasm ecosystem during September 2020. |
| 4 | +# tags: update |
| 5 | +--- |
| 6 | +# September 2020 Update |
| 7 | + |
| 8 | +The amount of work happening in the SwiftWasm ecosystem is growing, so we decided to start |
| 9 | +publishing blog updates to give you an overview of what happened recently. This update for |
| 10 | +September is big enough to be split into different sections for each area of our work, so let's |
| 11 | +get started. 🙂 |
| 12 | + |
| 13 | +## Libraries |
| 14 | + |
| 15 | +[JavaScriptKit 0.7](https://github.com/swiftwasm/JavaScriptKit/releases/tag/0.7.0) has been |
| 16 | +released. It adds multiple new types bridged from JavaScript, |
| 17 | +namely `JSError`, `JSDate`, `JSTimer` (which corresponds to `setTimeout`/`setInterval` calls and |
| 18 | +manages closure lifetime for you), `JSString` and `JSPromise`. We now also have [documentation |
| 19 | +published automatically](https://swiftwasm.github.io/JavaScriptKit/) for the `main` branch. |
| 20 | + |
| 21 | +New features of JavaScriptKit allowed us to start working on closer integration with |
| 22 | +[OpenCombine](https://github.com/OpenCombine/OpenCombine). The current progress is available in the |
| 23 | +new [OpenCombineJS](https://github.com/swiftwasm/OpenCombineJS) repository, and we plan to tag a |
| 24 | +release for it soon. At the moment it has a `JSScheduler` class wrapping `JSTimer` that implements |
| 25 | +[the `Scheduler` protocol](https://developer.apple.com/documentation/combine/scheduler), enabling |
| 26 | +you to use `debounce` and other time-based operators. Additionally, OpenCombineJS now provides a |
| 27 | +helper `publisher` property on `JSPromise`, which allows you to integrate any promise-based API with |
| 28 | +an OpenCombine pipeline. |
| 29 | + |
| 30 | +We also saw a lot of great progress with [DOMKit](https://github.com/swiftwasm/DOMKit) in September |
| 31 | +thanks to the outstanding work by [Jed Fox](https://jedfox.com/) and |
| 32 | +[@Unkaputtbar](https://github.com/Unkaputtbar), which was unblocked by the recent additions to |
| 33 | +JavaScriptKit. With DOMKit we're going to get type-safe access to the most common browser DOM APIs. |
| 34 | +It will be expanded in the future to support even more features that currently are only available |
| 35 | +via JavaScriptKit through force unwrapping and dynamic casting. |
| 36 | + |
| 37 | +That is, compare the current API you get with JavaScriptKit: |
| 38 | + |
| 39 | +```swift |
| 40 | +import JavaScriptKit |
| 41 | + |
| 42 | +let document = JSObject.global.document.object! |
| 43 | + |
| 44 | +let divElement = document.createElement!("div").object! |
| 45 | +divElement.innerText = "Hello, world" |
| 46 | +let body = document.body.object! |
| 47 | +_ = body.appendChild!(divElement) |
| 48 | +``` |
| 49 | + |
| 50 | +to an equivalent snippet that could look like this with DOMKit: |
| 51 | + |
| 52 | +```swift |
| 53 | +import DOMKit |
| 54 | + |
| 55 | +let document = global.document |
| 56 | + |
| 57 | +let divElement = document.createElement("div") |
| 58 | +divElement.innerText = "Hello, world" |
| 59 | +document.body.appendChild(divElement) |
| 60 | +``` |
| 61 | + |
| 62 | +Lastly on the libraries front, [Tokamak 0.4](https://github.com/TokamakUI/Tokamak/releases) is now |
| 63 | +available, enabling compatibility with the new version of JavaScriptKit, and utilizing the |
| 64 | +aforementioned `JSScheduler` implementation. |
| 65 | + |
| 66 | +## Developer tools |
| 67 | + |
| 68 | +Following the new 0.7 release of JavaScriptKit, [`carton` |
| 69 | +0.6](https://github.com/swiftwasm/carton/releases/tag/0.6.0) has been tagged, shipping with the |
| 70 | +appropriate JavaScriptKit runtime compatible with the new release. It also includes support for the |
| 71 | +new `carton bundle` command that produces a directory with optimized build output ready for |
| 72 | +deployment on a CDN or any other server. Notably, both `carton bundle` and `carton dev` support |
| 73 | +[SwiftPM package |
| 74 | +resources](https://github.com/apple/swift-evolution/blob/master/proposals/0271-package-manager-resources.md), |
| 75 | +allowing you to include additional static content to your SwiftWasm apps. These could be styles, |
| 76 | +scripts, images, fonts, or whatever other data you'd like to ship with your app. |
| 77 | + |
| 78 | +This version of `carton` also ships with the latest version of |
| 79 | +[wasmer.js](https://github.com/wasmerio/wasmer-js/), which is one of our dependencies. This update |
| 80 | +brings compatibility of SwiftWasm apps with Safari 14 that was released recently. |
| 81 | + |
| 82 | +## Toolchain/SDK work |
| 83 | + |
| 84 | +The upstream Swift toolchain has switched to use [LLVM](http://llvm.org) 11 in the `main` branch, |
| 85 | +which caused a substantial amount of conflicts in our forked repositories. We've spent most of |
| 86 | +our time in September on resolving the fallout from that and making sure everything builds properly. |
| 87 | +You could've noticed that the previously steady stream of nighly development snapshots stalled for |
| 88 | +most of September, but it resumed starting with `wasm-DEVELOPMENT-SNAPSHOT-2020-09-20-a`. |
| 89 | + |
| 90 | +As for the 5.3 branch, with the upstream Swift 5.3.0 release now generally available, we're |
| 91 | +currently preparing a stable SwiftWasm 5.3.0 release. It is based off upstream 5.3.0 |
| 92 | +with our patches applied to the toolchain and the SDK. [We've created a |
| 93 | +checklist](https://github.com/swiftwasm/swift/issues/1759) that allows us to track the |
| 94 | +progress of this effort. |
| 95 | + |
| 96 | +One of the issues we wanted to resolve before tagging SwiftWasm 5.3.0 is the inconsistency between |
| 97 | +WASI and Glibc APIs. While there's a subset of these APIs that looks and works the same, there are a |
| 98 | +lot of differences that our users should be aware of. Because of this, in subsequent snapshots our |
| 99 | +users need to use `import WASILibc` instead of `import Glibc` if they need to access to libc on the |
| 100 | +WASI platform. This has already landed in the `swiftwasm-release/5.3` branch with |
| 101 | +[swiftwasm/swift#1773](https://github.com/swiftwasm/swift/pull/1773) and is available |
| 102 | +in `wasm-5.3-SNAPSHOT-2020-09-23-a` or later. It was also implemented in the main `swiftwasm` branch |
| 103 | +in [swiftwasm/swift#1832](https://github.com/swiftwasm/swift/pull/1832), all thanks to the amazing |
| 104 | +work by [Yuta Saito](https://github.com/sponsors/kateinoigakukun). |
| 105 | + |
| 106 | +## Upstream PRs |
| 107 | + |
| 108 | +The divergence between the SwiftWasm toolchain and SDKs is still significant and causes regular |
| 109 | +conflicts that we have to resolve manually. We're working on making our changes available upstream, |
| 110 | +but this takes a lot of time, as upstream toolchain and SDK PRs need high level of polish to be |
| 111 | +accepted. Here's a list of PRs that had some progress in September: |
| 112 | + |
| 113 | +### Foundation |
| 114 | + |
| 115 | +* Add locking primitives for `TARGET_OS_WASI` in `CFLocking.h` |
| 116 | + [apple/swift-corelibs-foundation#2867](https://github.com/apple/swift-corelibs-foundation/pull/2867). |
| 117 | + **Status: merged.** |
| 118 | +* Add support for WASI in `CFInternal.h` |
| 119 | + [apple/swift-corelibs-foundation#2872](https://github.com/apple/swift-corelibs-foundation/pull/2872). |
| 120 | + **Status: merged.** |
| 121 | +* Add WASI support in `CoreFoundation_Prefix.h` |
| 122 | + [apple/swift-corelibs-foundation#2873](https://github.com/apple/swift-corelibs-foundation/pull/2873). |
| 123 | + **Status: merged.** |
| 124 | +* Add support for WASI in `CFDate.c` |
| 125 | + [apple/swift-corelibs-foundation#2880](https://github.com/apple/swift-corelibs-foundation/pull/2880). |
| 126 | + **Status: in review.** |
| 127 | + |
| 128 | +### SwiftPM |
| 129 | + |
| 130 | +* Propagate PATH to UserToolchain to fix sysroot search |
| 131 | + [apple/swift-package-manager#2936](https://github.com/apple/swift-package-manager/pull/2936). |
| 132 | + **Status: merged.** |
| 133 | + |
| 134 | +## Contributions |
| 135 | + |
| 136 | +We hope you can contribute to the SwiftWasm ecosystem, either to any of the projects listed above, |
| 137 | +or with your own libraries and apps that you built. We'd be very happy to feature your open-source |
| 138 | +work in our next update! Our whole [swiftwasm.org](https://swiftwasm.org) website including this |
| 139 | +blog [is open-source](https://github.com/swiftwasm/swiftwasm.org), so please feel free to open |
| 140 | +an issue or a pull request with a link to your work related to SwiftWasm. |
| 141 | + |
| 142 | +A lot of the progress wouldn't be possible without payments from our GitHub Sponsors. Their |
| 143 | +contribution is deeply appreciated and allows us to spend more time on SwiftWasm projects. You can |
| 144 | +see the list of sponsors and make your contribution on the sponsorship pages of [Yuta |
| 145 | +Saito](https://github.com/sponsors/kateinoigakukun) and [Max |
| 146 | +Desiatov](https://github.com/sponsors/MaxDesiatov). |
| 147 | + |
| 148 | +Thanks for reading! 👋 |
0 commit comments