Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Avoid using Foundation when it is unavailable #32

Merged
merged 2 commits into from
Apr 23, 2020
Merged

Avoid using Foundation when it is unavailable #32

merged 2 commits into from
Apr 23, 2020

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Apr 18, 2020

Foundation is not available on platforms such as SwiftWasm, this change allows the library to be compiled for such platforms.

Sources/AnyCodable/AnyEncodable.swift Outdated Show resolved Hide resolved
@mattt
Copy link
Member

mattt commented Apr 23, 2020

Interesting! Thanks for the patch, @MaxDesiatov. Just one suggested change to consolidate some duplicated logic.

I've been watching WASM support from a distance for a while. Where do you think everything is at now? What needs to happen before we can start using this for real? (Are there blocking technical issues, or do things basically work, and it's just a matter of documenting and motivating use to the community at large?)

@mattt mattt merged commit a1d46df into Flight-School:master Apr 23, 2020
@mattt
Copy link
Member

mattt commented Apr 23, 2020

Perfect. Thanks again for your help with this, @MaxDesiatov!

@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Apr 23, 2020

@mattt If you don't care about binary size, it's more or less usable right now as in this demo. Swift can't run dead code elimination on unused protocol conformances yet, so the minimum produced binary size is ~10M and ~1.5M when optimized and compressed, as tracked in swiftwasm/swift#7. Building with SwiftPM works, as long as you don't use Foundation or Dispatch due to a few technical reasons (swiftwasm/swift#592, swiftwasm/swift#658, swiftwasm/swift#647), but I hope that a minimalistic bare-bones subset of Foundation can alleviate that pain in the meantime.

Interacting with DOM works through JavaScriptKit built by @kateinoigakukun, also big thanks to him for the Game of Life demo. I honestly didn't expect that we actually have SwiftPM and DOM interaction working at this point before I saw the demo in action 🤩

swift test doesn't work yet, but I was able to get a subset of XCTest without expectations, waiters and parallel testing compiling, but not working yet due to a codegen/linking issue. XCTest is one of my top priorities right now, as lack of XCTest blocks people from verifying how well their libraries work when compiled by SwiftWasm. By the way, AnyCodable was a big help in making XCTest compile, as the upstream version used Foundation's JSONSerialization API, which I was able to replace with pure-swift-json in combination with AnyEncodable 🙂

As soon as tests work, I want to get back to implementing a SwiftUI renderer for DOM. I have a reconciler that worked for iOS and macOS renderers last year before SwiftUI was announced. Although its public API was modeled after React at that time, it was relatively easy to repurpose the internals for the SwiftUI API, there's a test renderer now in the codebase that passes basic tests when compiled for macOS. Now it's just a matter of verifying that runtime reflection works well when running in browsers and then implemeninting the DOM renderer that matches Button to <button>, Text to <span>, Image to <img> etc. Combine bits of the API can then be implemented with OpenCombine, which now compiles and passes basic tests (the whole OpenCombine XCTest suite not working yet due to the reasons described above).

Overall, I think it's in the state now where any help from the community would be greatly appreciated. Everyone can now install the SwiftWasm locally with swiftenv and check if their package works. I hope to get a GitHub action with the toolchain preinstalled working ASAP so that people can start adding this to their CI. Now that upstream 5.3 has been branched, I'd like to start making 5.3 SwiftWasm snapshots, which hopefully converge to something stable by the time upstream Swift 5.3 toolchain is released. Upstreaming the changes would also tremendously help, as it would reduce the maintenance burden we have due to re-appearing merge conflicts. Technical writing and doing basic "DevRel tasks" is also something that would help a lot. I personally work on this full-time right now, but would be deeply grateful for any help and contributions.

Thanks for considering the patch, and many thanks for reading this 🙂

@mattt
Copy link
Member

mattt commented Apr 24, 2020

@MaxDesiatov This is tremendous, Max. (Also, that @kateinoigakukun is next-level).

Thanks for writing this up.

Technical writing and doing basic "DevRel tasks" is also something that would help a lot.

Count me in! I see WASM as a total game-changer, both for Swift and software in general. Consider whatever reach I have with @NSHipster to be at your disposal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants