diff --git a/bin/test_wasm b/bin/test_wasm new file mode 100644 index 0000000000..a866baa6b6 --- /dev/null +++ b/bin/test_wasm @@ -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 diff --git a/xmake.lua b/xmake.lua index 3e27e3faaa..121a4aef90 100644 --- a/xmake.lua +++ b/xmake.lua @@ -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 @@ -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 @@ -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") @@ -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") @@ -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