Cross-compiling Swift to WebAssembly


(Nathan Gray) #1

Hello,

Is anybody else out there excited by the idea of cross-compiling Swift to
WebAssembly? My impression is that almost all of the pieces are in place
and that the remaining challenges are likely build related. For example,
the Clang that ships with Xcode 9 includes support for wasm32 as a
compilation target. Has anybody thought about this or pursued it?

If you're unfamiliar with WebAssembly take a look at http://webassembly.org.
In essence, they're defining a VM that runs in the browser, and all the
major browsers are supporting it. We're talking about being able to code
for the web without Javascript. Imagine being able to write Swift
libraries that could be compiled for iOS, Android, Linux, *and* the web!
It's currently possible with C and C++, and Swift is a promising candidate.

As I understand it, the first obstacle is getting a version of the Swift
standard library that's compiled to llvm bitcode using the "wasm32"
target. Does that sound achievable?

Thanks,
-Nathan

ยทยทยท

--
Functional Programmer, iOS Developer, Surfs Poorly
http://twitter.com/n8gray


(Daniel Dunbar) #2

Hi Nathan,

This is probably best brought up on swift-dev (CC'd), since this is (initially) mostly a compiler problem and not related to the build tools (the package manager).

- Daniel

ยทยทยท

On Jun 25, 2017, at 4:50 PM, Nathan Gray via swift-build-dev <swift-build-dev@swift.org> wrote:

Hello,

Is anybody else out there excited by the idea of cross-compiling Swift to WebAssembly? My impression is that almost all of the pieces are in place and that the remaining challenges are likely build related. For example, the Clang that ships with Xcode 9 includes support for wasm32 as a compilation target. Has anybody thought about this or pursued it?

If you're unfamiliar with WebAssembly take a look at http://webassembly.org <http://webassembly.org/>. In essence, they're defining a VM that runs in the browser, and all the major browsers are supporting it. We're talking about being able to code for the web without Javascript. Imagine being able to write Swift libraries that could be compiled for iOS, Android, Linux, *and* the web! It's currently possible with C and C++, and Swift is a promising candidate.

As I understand it, the first obstacle is getting a version of the Swift standard library that's compiled to llvm bitcode using the "wasm32" target. Does that sound achievable?

Thanks,
-Nathan

--
Functional Programmer, iOS Developer, Surfs Poorly
http://twitter.com/n8gray_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Nathan Gray) #3

Thanks Daniel. I was guessing this was more of a build challenge but
swift-dev is probably a better forum regardless.

I think a WebAssembly target would more-or-less look like a generic unix
target, so I was thinking about trying a port analogous to the FreeBSD or
Linux port but using the emscripten compiler and linker. I'm imagining
there will be snags related to linking and packaging, but the emscripten
people seem pretty confident in their compatibility story, so maybe I'll
get lucky?

To be honest, I'm willing to flail at this and cargo-cult my way through
alone but I'd love to hear from anybody else interested in making it
happen. C'mon folks, Swift in the browser will be a massive, massive game
changer!

Cheers,
-n8

ยทยทยท

On Tue, Jun 27, 2017 at 9:06 AM, Daniel Dunbar <daniel_dunbar@apple.com> wrote:

Hi Nathan,

This is probably best brought up on swift-dev (CC'd), since this is
(initially) mostly a compiler problem and not related to the build tools
(the package manager).

- Daniel

On Jun 25, 2017, at 4:50 PM, Nathan Gray via swift-build-dev < > swift-build-dev@swift.org> wrote:

Hello,

Is anybody else out there excited by the idea of cross-compiling Swift to
WebAssembly? My impression is that almost all of the pieces are in place
and that the remaining challenges are likely build related. For example,
the Clang that ships with Xcode 9 includes support for wasm32 as a
compilation target. Has anybody thought about this or pursued it?

If you're unfamiliar with WebAssembly take a look at
http://webassembly.org. In essence, they're defining a VM that runs in
the browser, and all the major browsers are supporting it. We're talking
about being able to code for the web without Javascript. Imagine being
able to write Swift libraries that could be compiled for iOS, Android,
Linux, *and* the web! It's currently possible with C and C++, and Swift is
a promising candidate.

As I understand it, the first obstacle is getting a version of the Swift
standard library that's compiled to llvm bitcode using the "wasm32"
target. Does that sound achievable?

Thanks,
-Nathan

--
Functional Programmer, iOS Developer, Surfs Poorly
http://twitter.com/n8gray
_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-build-dev

--
Functional Programmer, iOS Developer, Surfs Poorly
http://twitter.com/n8gray