Created
July 12, 2019 02:49
-
-
Save omochi/335291b3beda79c4fd463782e8ca0641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compile.rb | |
#!/usr/bin/ruby | |
require "shellwords" | |
def system(args) | |
cmd = args.shelljoin | |
if RUBY_VERSION.to_f >= 2.6 | |
Kernel.system(cmd, exception: true) | |
else | |
Kernel.system(cmd) | |
st = $? | |
if not st.success? | |
raise "exit status: #{st}" | |
end | |
end | |
end | |
args = [ | |
"swiftc", | |
"-emit-assembly", | |
"-O", | |
"-target", "wasm32-unknown-unknown-wasm", | |
"-sdk", "/work/wasi-sdk/share/sysroot", | |
"a.swift" | |
] | |
system(args) | |
# link.rb | |
#!/usr/bin/ruby | |
require "shellwords" | |
def system(args) | |
system(args.shelljoin) | |
st = $? | |
if not st.success? | |
raise "exit status: #{st}" | |
end | |
end | |
sysroot = "/work/wasi-sdk/share/sysroot" | |
swsdk = "/work/swiftwasm-sdk" | |
swcs = "/work/swiftwasm-compile-service" | |
wasdk = "/work/wasi-sdk" | |
args = [ | |
"wasm-ld", | |
"-o", "a.out", | |
"#{sysroot}/lib/wasm32-wasi/crt1.o", | |
"#{swcs}/extra_objs/swift_start.o", | |
"#{swsdk}/lib/swift_static/wasm/wasm32/swiftrt.o", | |
"a.o", | |
"-L#{swsdk}/lib/swift_static/wasm", | |
"-L#{sysroot}/lib/wasm32-wasi", | |
"-L/work/icu_out/lib", | |
"-lswiftCore", | |
"-lc", "-lc++", "-lc++abi", "-lswiftImageInspectionShared", | |
"-licuuc", "-licudata", | |
"#{wasdk}/lib/clang/8.0.0/lib/wasi/libclang_rt.builtins-wasm32.a", | |
"#{swcs}/extra_objs/fakepthread.o", | |
"#{swcs}/extra_objs/fakelocaltime.o", | |
"#{swcs}/extra_objs/swift_end.o", | |
"--no-gc-sections", | |
"--no-threads" | |
] | |
system(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment