Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Commit 3842548

Browse files
committed
Initial commit
0 parents  commit 3842548

17 files changed

+200
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
compiler
2+
swiftwasm-sdk
3+
prebuilt
4+
output

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Creates packages containing everything needed to build WebAssembly prpgrams with Swift.
2+
3+
# Building
4+
5+
```
6+
./downloadPrebuilts.sh
7+
./buildPackages.sh
8+
```
9+
10+
# Contents of package
11+
12+
- Swift toolchain from [swiftwasm-sdk](https://github.com/swiftwasm/swiftwasm-sdk)
13+
- WASI modified sysroot from [wasi-sdk](https://github.com/swiftwasm/wasi-sdk)
14+
- libicu from [icu4c-wasi](https://github.com/swiftwasm/icu4c-wasi)
15+
- linking helpers from [swiftwasm-wasi-stubs](https://github.com/swiftwasm/swiftwasm-wasi-stubs)
16+
- wasi-ld, either from wasi-sdk (on Linux) or upstream LLVM 8.0 (on Mac)
17+
- build script for compiling a Swift file to a .wasm
18+
- a Getting Started guide
19+
20+
# Notes
21+
22+
This shares a lot with the [swiftwasm-compile-service](https://github.com/swiftwasm/swiftwasm-compile-service).

buildPackages.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
rm -rf output || true
4+
mkdir output
5+
echo "Linux"
6+
cd linux
7+
./unpackPrebuilts.sh
8+
echo "Compressing"
9+
tar cJf ../output/swiftwasm-sdk-linux.tar.xz swiftwasm-sdk
10+
echo "macOS"
11+
cd ../macos
12+
./unpackPrebuilts.sh
13+
echo "Compressing"
14+
tar cJf ../output/swiftwasm-sdk-macos.tar.xz swiftwasm-sdk

copy-shared-files.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
cp -r ../sdkroot/* compiler/
4+
cp compiler/opt/swiftwasm-sdk/lib/swift/wasm/wasm32/glibc.modulemap compiler/extra_utils

downloadPrebuilts.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
rm -r prebuilt || true
4+
mkdir prebuilt
5+
cd prebuilt
6+
wget https://github.com/swiftwasm/swiftwasm-sdk/releases/download/20190503.1/swiftwasm.tar.gz
7+
wget https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
8+
wget https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz
9+
wget https://github.com/WebAssembly/wabt/releases/download/1.0.10/wabt-1.0.10-linux.tar.gz
10+
# Mac specific
11+
wget https://github.com/swiftwasm/swiftwasm-sdk/releases/download/20190506.3/swiftwasm-mac.tar.gz
12+
wget http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-apple-darwin.tar.xz

linux/unpackPrebuilts.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
rm -r swiftwasm-sdk compiler || true
4+
mkdir swiftwasm-sdk
5+
ln -s swiftwasm-sdk compiler
6+
cd compiler
7+
untar="../prebuilt/wasi-sdk-"*"-linux.tar.gz
8+
../prebuilt/swiftwasm-sdk.tar.gz
9+
../prebuilt/icu4c-wasi.tar.xz"
10+
for i in $untar
11+
do
12+
echo $i
13+
tar xf $i
14+
done
15+
cd ..
16+
mv "compiler/wasi-sdk-"* "compiler/wasi-sdk"
17+
mv "compiler/wabt-"* "compiler/wabt"
18+
bash ../remove-swift-extra-files.sh || true
19+
bash ../remove-wasi-extra-files.sh || true
20+
bash ../copy-shared-files.sh || true

macos/unpackPrebuilts.sh

Whitespace-only changes.

remove-swift-extra-files.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
basepath="compiler/opt/swiftwasm-sdk"
3+
filestoremove="bin/sil-*
4+
bin/lldb*
5+
bin/sourcekitd-*
6+
bin/swift-api-digester
7+
bin/swift-autolink-extract
8+
bin/swift-demangle
9+
bin/swift-demangle-yamldump
10+
bin/swift-format
11+
bin/swift-llvm-opt
12+
bin/swift-refactor
13+
bin/swift-reflection-dump
14+
bin/swift-*-test
15+
lib/libsourcekitdInProc.so
16+
lib/swift/clang/lib/linux/*
17+
lib/swift_static/linux/*
18+
lib/swift/linux/x86_64/*
19+
lib/swift/linux/*"
20+
for i in $filestoremove
21+
do
22+
echo $basepath/$i
23+
rm $basepath/$i
24+
done

remove-wasi-extra-files.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
basepath="compiler/wasi-sdk/opt/wasi-sdk"
3+
filestoremove="bin/clang*
4+
bin/llvm*
5+
bin/llc"
6+
for i in $filestoremove
7+
do
8+
echo $basepath/$i
9+
rm $basepath/$i
10+
done

sdkroot/README.txt

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
SwiftWasm: Getting started
2+
==========================
3+
4+
Thank you for trying SwiftWasm! Here's how to get started.
5+
6+
Please visit our website at https://swiftwasm.org for the latest updates.
7+
8+
9+
Install dependencies
10+
11+
====================
12+
13+
Before running SwiftWasm, you will need to install some dependencies.
14+
15+
Ubuntu:
16+
17+
```
18+
sudo apt-get install libatomic1
19+
```
20+
21+
macOS:
22+
23+
(No dependencies needed.)
24+
25+
Windows:
26+
27+
Install Windows Subsystem for Linux, then follow the Ubuntu instructions.
28+
29+
30+
31+
32+
Compile SwiftWasm
33+
34+
=================
35+
36+
Run
37+
38+
```
39+
./swiftwasm example/hello.swift hello.wasm
40+
```
41+
42+
To compile example/hello.swift to hello.wasm.
43+
44+
45+
46+
47+
Running Wasm files
48+
49+
==================
50+
51+
To run the resulting hello.wasm file:
52+
53+
- open js-polyfill/polyfill.html in your browser
54+
- select the hello.wasm file
55+
56+
You can also run the file with
57+
58+
- Wasmtime https://github.com/CraneStation/wasmtime
59+
- Lucet https://github.com/swiftwasm/lucet/tree/swiftwasm
60+
- or any other WASI-compatible WebAssembly runtime.
61+
62+
63+
64+
65+
Questions and support
66+
67+
=====================
68+
69+
If you have any questions, please open an issue on
70+
71+
https://github.com/swiftwasm/swift
72+
73+
74+
75+
Third-party licenses
76+
77+
====================
78+
79+
This package contains components with their own license requirements.
80+
81+
Swift compiler: https://github.com/apple/swift/blob/master/LICENSE.txt
82+
83+
LLVM/Clang: https://github.com/llvm/llvm-project/blob/master/lld/LICENSE.TXT
84+
85+
WASI sysroot: https://github.com/CraneStation/wasi-sysroot/blob/master/LICENSE
86+
87+
ICU: https://github.com/unicode-org/icu/blob/master/icu4c/LICENSE

sdkroot/example/hello.swift

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, 🌐!")

sdkroot/extra_objs/fakelocaltime.o

423 Bytes
Binary file not shown.

sdkroot/extra_objs/fakepthread.o

3.97 KB
Binary file not shown.

sdkroot/extra_objs/swift_end.o

576 Bytes
Binary file not shown.

sdkroot/extra_objs/swift_start.o

584 Bytes
Binary file not shown.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec sed -e "s@\"/include@\"$1/include@g" glibc.modulemap

sdkroot/swiftwasm

Whitespace-only changes.

0 commit comments

Comments
 (0)