Skip to content

Commit

Permalink
support wasi-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 7, 2024
1 parent 606339e commit 31c752b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
68 changes: 68 additions & 0 deletions scripts/compiler/wasi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local wasi = require "compiler.gcc"
local globals = require "globals"

function wasi.update_flags(flags, _, cxxflags, attribute)
if attribute.mode == "debug" then
flags[#flags+1] = "-g"
end
if attribute.lto ~= "off" then
if attribute.lto == "thin" then
flags[#flags+1] = "-flto=thin"
else
flags[#flags+1] = "-flto"
end
end
if attribute.rtti == "off" then
cxxflags[#cxxflags+1] = "-fno-rtti"
end
flags[#flags+1] = "-target"
flags[#flags+1] = attribute.target or "wasm32-wasi"
flags[#flags+1] = "--sysroot"
flags[#flags+1] = globals.WASI_SDK_PATH.."/share/wasi-sysroot"
end

function wasi.update_ldflags(ldflags, attribute)
if attribute.crt == "dynamic" then
ldflags[#ldflags+1] = "-lstdc++"
else
ldflags[#ldflags+1] = "-Wl,--push-state,-Bstatic"
ldflags[#ldflags+1] = "-lstdc++"
ldflags[#ldflags+1] = "-Wl,--pop-state"
end
if attribute.mode ~= "debug" then
ldflags[#ldflags+1] = "-Wl,-S"
end
if attribute.lto ~= "off" then
if attribute.lto == "thin" then
ldflags[#ldflags+1] = "-flto=thin"
else
ldflags[#ldflags+1] = "-flto"
end
end
ldflags[#ldflags+1] = "-target"
ldflags[#ldflags+1] = attribute.target or "wasm32-wasi"
ldflags[#ldflags+1] = "--sysroot"
ldflags[#ldflags+1] = globals.WASI_SDK_PATH.."/share/wasi-sysroot"
end

function wasi.rule_dll(w, name, ldflags)
error "TODO"
end

function wasi.rule_exe(w, name, ldflags)
if globals.hostshell == "cmd" then
w:rule("link_"..name, ([[$cc @$out.rsp -o $out %s]]):format(ldflags),
{
description = "Link Exe $out",
rspfile = "$out.rsp",
rspfile_content = "$in",
})
else
w:rule("link_"..name, ([[$cc $in -o $out %s]]):format(ldflags),
{
description = "Link Exe $out"
})
end
end

return wasi
2 changes: 2 additions & 0 deletions scripts/env/wasi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local globals = require "globals"
globals.cc = globals.WASI_SDK_PATH .. "/bin/clang"
3 changes: 3 additions & 0 deletions scripts/writer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,9 @@ function m.generate()
if globals.os == "android" and globals.hostos ~= "android" then
require "env.ndk"
end
if globals.compiler == "wasi" then
require "env.wasi"
end

if globals.compiler == "msvc" then
if not globals.prebuilt then
Expand Down

0 comments on commit 31c752b

Please sign in to comment.