Skip to content

Commit

Permalink
[32_7] Build and test kernel L3 on wasm
Browse files Browse the repository at this point in the history
Co-authored-by: 沈浪熊猫儿 <[email protected]>
  • Loading branch information
da-liii and 沈浪熊猫儿 authored Sep 8, 2023
1 parent 551f5b3 commit 7e998ed
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
18 changes: 18 additions & 0 deletions bin/test_wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env elvish

use platform


var pkg_info = (xrepo fetch --json emscripten | from-json)
var emsdk_path = $pkg_info[0][artifacts][installdir]
set-env EMSDK $emsdk_path


if $platform:is-windows {
set-env EMSDK_NODE $emsdk_path/node/16.20.0_64bit/bin/node.exe
} elif $platform:is-unix {
set-env EMSDK_NODE $emsdk_path/node/16.20.0_64bit/bin/node
}


xmake run commute_test
87 changes: 57 additions & 30 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ if is_plat("mingw") and is_host("windows") then
set_toolchains("mingw@mingw-w64")
end

if is_plat("wasm") then
add_requires("emscripten 3.1.25")
set_toolchains("emcc@emscripten")
end

-- add releasedbg, debug and release modes for different platforms.
-- debug mode cannot run on mingw with qt precompiled binary
if is_plat("mingw") then
Expand Down Expand Up @@ -85,6 +90,31 @@ local TeXmacs_files = {
includes("misc/xmake/packages.lua")
add_requires_of_mogan()

function build_glue_on_config()
on_config(function (target)
import("core.project.depend")
-- use relative path here to avoid import failure on windows
local scheme_path = path.join("src", "Scheme")
local build_glue_path = path.join("src", "Scheme", "Glue")
local build_glue = import("build_glue", {rootdir = build_glue_path})
for _, filepath in ipairs(os.filedirs(path.join(scheme_path, "**/glue_*.lua"))) do
depend.on_changed(function ()
local glue_name = path.basename(filepath)
local glue_dir = path.directory(filepath)
local glue_table = import(glue_name, {rootdir = glue_dir})()
io.writefile(
path.join("$(buildir)", glue_name .. ".cpp"),
build_glue(glue_table, glue_name))
cprint("generating scheme glue %s ... %s", glue_name, "${color.success}${text.success}")
end, {
values = {true},
files = {filepath, path.join(build_glue_path, "build_glue.lua")},
always_changed = false
})
end
end)
end


--
-- Experimental options of Mogan
Expand Down Expand Up @@ -330,28 +360,7 @@ target("libmogan") do
add_frameworks("QtMacExtras")
end

on_config(function (target)
import("core.project.depend")
-- use relative path here to avoid import failure on windows
local scheme_path = path.join("src", "Scheme")
local build_glue_path = path.join("src", "Scheme", "Glue")
local build_glue = import("build_glue", {rootdir = build_glue_path})
for _, filepath in ipairs(os.filedirs(path.join(scheme_path, "**/glue_*.lua"))) do
depend.on_changed(function ()
local glue_name = path.basename(filepath)
local glue_dir = path.directory(filepath)
local glue_table = import(glue_name, {rootdir = glue_dir})()
io.writefile(
path.join("$(buildir)", glue_name .. ".cpp"),
build_glue(glue_table, glue_name))
cprint("generating scheme glue %s ... %s", glue_name, "${color.success}${text.success}")
end, {
values = {true},
files = {filepath, path.join(build_glue_path, "build_glue.lua")},
always_changed = false
})
end
end)
build_glue_on_config()

add_packages("lolly")
add_packages("libiconv")
Expand Down Expand Up @@ -804,12 +813,12 @@ target("windows_installer") do
end)
end

function add_test_target (filepath)
function add_test_target (filepath, dep)
local testname = path.basename(filepath)
target(testname) do
add_runenvs("TEXMACS_PATH", path.join(os.projectdir(), "TeXmacs"))
set_group("tests")
add_deps("libmogan")
add_deps(dep)
set_languages("c++17")
set_policy("check.auto_ignore_flags", false)
add_rules("qt.console")
Expand All @@ -822,31 +831,49 @@ function add_test_target (filepath)
add_packages("lolly")

add_includedirs({"$(buildir)", "tests/Base"})
build_glue_on_config()
add_files("tests/Base/base.cpp")
add_files(filepath)
add_files(filepath, {rules = "qt.moc"})
add_cxxflags("-include $(buildir)/config.h")

if is_plat("wasm") then
on_run(function (target)
node = os.getenv("EMSDK_NODE")
cmd = node .. " $(buildir)/wasm/wasm32/$(mode)/" .. testname .. ".js"
print("> " .. cmd)
os.exec(cmd)
end)
end
end
end

for _, filepath in ipairs(os.files("tests/Data/**_test.cpp")) do
add_test_target (filepath)
for _, filepath in ipairs(os.files("tests/Data/History/**_test.cpp")) do
add_test_target (filepath, "libkernel_l3")
end

for _, filepath in ipairs(os.files("tests/Data/Parser/**_test.cpp")) do
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("tests/Data/String/**_test.cpp")) do
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("tests/Graphics/**_test.cpp")) do
add_test_target (filepath)
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("tests/System/**_test.cpp")) do
add_test_target (filepath)
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("tests/Typeset/**_test.cpp")) do
add_test_target (filepath)
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("tests/Plugins/**_test.cpp")) do
add_test_target (filepath)
add_test_target (filepath, "libmogan")
end

for _, filepath in ipairs(os.files("TeXmacs/tests/*.scm")) do
Expand Down

0 comments on commit 7e998ed

Please sign in to comment.