Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.