Skip to content

Commit 9eaef9e

Browse files
committed
[724] WASM Support for STEM
1 parent 237ed63 commit 9eaef9e

20 files changed

Lines changed: 582 additions & 205 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build on macOS for WASM
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- "src/**"
7+
- "!src/Plugins/Macos/**"
8+
- "!src/Plugins/Windows/**"
9+
- "tests/**"
10+
- "lolly/**"
11+
- "moebius/**"
12+
- "xmake.lua"
13+
- 'xmake/options.lua'
14+
- 'xmake/requires.lua'
15+
- 'xmake/targets/**'
16+
- "xmake/packages.lua"
17+
- "xmake/packages/**"
18+
- ".github/workflows/ci-macos-wasm.yml"
19+
- "TeXmacs/tests/*.scm"
20+
- "3rdparty/**"
21+
pull_request:
22+
branches: [main]
23+
paths:
24+
- "src/**"
25+
- "!src/Plugins/Macos/**"
26+
- "!src/Plugins/Windows/**"
27+
- "tests/**"
28+
- "lolly/**"
29+
- "moebius/**"
30+
- "xmake.lua"
31+
- 'xmake/options.lua'
32+
- 'xmake/requires.lua'
33+
- 'xmake/targets/**'
34+
- "xmake/packages.lua"
35+
- "xmake/packages/**"
36+
- ".github/workflows/ci-macos-wasm.yml"
37+
- "TeXmacs/tests/*.scm"
38+
- "3rdparty/**"
39+
workflow_dispatch:
40+
41+
env:
42+
XMAKE_ROOT: y
43+
INSTALL_DIR: tmp/build/packages/app.mogan/
44+
45+
jobs:
46+
build:
47+
strategy:
48+
matrix:
49+
os: [macos-14]
50+
arch: [arm64]
51+
runs-on: ${{ matrix.os }}
52+
timeout-minutes: 45
53+
if: always()
54+
steps:
55+
- uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 1
58+
59+
- name: cache xmake
60+
uses: actions/cache@v4
61+
with:
62+
path: |
63+
${{github.workspace}}/build/.build_cache
64+
/Users/runner/.xmake
65+
key: xmake-${{ runner.os }}-wasm-${{ hashFiles('xmake/vars.lua', 'lolly/xmake.lua', 'moebius/xmake.lua') }}
66+
67+
- name: set XMAKE_GLOBALDIR
68+
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV
69+
70+
- uses: xmake-io/github-action-setup-xmake@v1
71+
with:
72+
xmake-version: v3.0.4
73+
actions-cache-folder: '.xmake-cache'
74+
75+
- name: xmake repo --update
76+
run: xmake repo --update
77+
78+
- name: cache packages from xrepo
79+
uses: actions/cache@v4
80+
with:
81+
path: |
82+
${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
83+
key: xrepo-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('xmake/vars.lua', 'lolly/xmake.lua', 'moebius/xmake.lua') }}
84+
85+
- name: config
86+
run: xmake config --policies=build.ccache -o ${{ runner.workspace }}/build -m releasedbg -p wasm --qt_frontend=no --yes
87+
88+
- name: build
89+
run: xmake build --yes -vD stem

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ docs/**/plugin_binary.md
4646

4747
# Binary of the goldfish plugin
4848
TeXmacs/plugins/goldfish/bin/goldfish
49+
TeXmacs/plugins/goldfish/bin/*.wasm
50+
TeXmacs/plugins/goldfish/bin/*.js
51+
TeXmacs/plugins/goldfish/bin/*.html
4952
goldfish.dSYM/
5053
*.sym
5154
*goldfish.pdb
5255

5356
# font
5457
TeXmacs/fonts/opentype/noto
5558

56-
record
59+
record

3rdparty/libaesgm.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package("liii-libaesgm")
1010

1111
set_sourcedir(path.join(os.scriptdir(), "libaesgm"))
1212

13-
on_install("linux", "macosx", "windows", "mingw", function (package)
13+
on_install("linux", "macosx", "windows", "mingw", "wasm", function (package)
1414
if package:is_plat("windows", "mingw") and package:is_arch("arm", "arm64") then
1515
-- Windows is always little endian
1616
io.replace("brg_endian.h", [[

3rdparty/pdfhummus.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ package("liii-pdfhummus")
3030
end
3131
end
3232
end)
33-
on_install("linux", "windows", "mingw", "macosx", function (package)
33+
on_install("linux", "windows", "mingw", "macosx", "wasm", function (package)
3434
local configs = {}
3535
if package:config("shared") then
3636
configs.kind = "shared"

3rdparty/pdfhummus/xmake.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- originally from https://github.com/xmake-io/xmake-repo/pull/1709
22

3+
includes("../libaesgm.lua")
34
option("libtiff", {description = "Enable libtiff", default = false})
45
option("libpng", {description = "Enable libpng", default = false})
56
option("libjpeg", {description = "Enable libjpeg", default = false})
@@ -17,14 +18,14 @@ end
1718
if has_config("openssl") then
1819
add_requires("openssl")
1920
end
20-
add_requires("freetype", "zlib", "libaesgm")
21+
add_requires("freetype", "zlib", "liii-libaesgm")
2122
target("pdfhummus")
2223
set_kind("$(kind)")
2324
add_files("PDFWriter/*.cpp")
2425
add_headerfiles("(PDFWriter/*.h)")
2526
add_packages("freetype")
2627
add_packages("libtiff", "libpng", "libjpeg", "openssl")
27-
add_packages("libaesgm", "zlib")
28+
add_packages("liii-libaesgm", "zlib")
2829
if has_package("libtiff") then
2930
add_defines("_INCLUDE_TIFF_HEADER")
3031
add_cxflags("-Wno-deprecated-declarations")

3rdparty/tbox/xmake.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ if has_config("coroutine") then
3131
add_cxflags("gcc::-Wno-error=dangling-pointer")
3232
end
3333

34-
-- set wasm toolchain
35-
if is_plat("wasm") then
36-
add_requires("emscripten")
37-
set_toolchains("emcc@emscripten")
38-
end
39-
4034
-- add build modes
4135
add_rules("mode.release", "mode.debug", "mode.profile", "mode.coverage", "mode.valgrind", "mode.asan", "mode.tsan", "mode.ubsan")
4236
if is_mode("debug") then

bin/wasm_server.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
2+
import sys
3+
import os
4+
5+
root = os.path.abspath(sys.argv[1])
6+
7+
html = os.path.join(root, "stem.html")
8+
js = os.path.join(root, "stem.js")
9+
10+
#if not os.path.exists(html) and os.path.exists(js):
11+
with open(html, "w", encoding="utf-8") as f:
12+
f.write("""<!doctype html>
13+
<html>
14+
<head>
15+
<meta charset="utf-8">
16+
<title>stem</title>
17+
<style>
18+
html, body, canvas {
19+
margin: 0;
20+
width: 100%;
21+
height: 100%;
22+
overflow: hidden;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<canvas id="canvas"></canvas>
28+
29+
<script>
30+
var Module = {
31+
canvas: document.getElementById('canvas')
32+
};
33+
</script>
34+
35+
<script src="stem.js"></script>
36+
</body>
37+
</html>
38+
""")
39+
40+
class Handler(SimpleHTTPRequestHandler):
41+
def __init__(self, *args, **kwargs):
42+
super().__init__(*args, directory=root, **kwargs)
43+
44+
def end_headers(self):
45+
self.send_header(
46+
"Cross-Origin-Opener-Policy",
47+
"same-origin"
48+
)
49+
self.send_header(
50+
"Cross-Origin-Embedder-Policy",
51+
"require-corp"
52+
)
53+
super().end_headers()
54+
55+
server = ThreadingHTTPServer(
56+
("127.0.0.1", 8000),
57+
Handler
58+
)
59+
60+
print("Serving on http://127.0.0.1:8000/stem.html")
61+
62+
server.serve_forever()

devel/0724.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# [0724] WASM Support for STEM (ImGui)
2+
## What
3+
- 在构建脚本中添加了适配 wasm 的逻辑
4+
- bin 中新增 wasm_server.py
5+
- `tm_server.cpp` `pipe_link.cpp` 中调整 WASM 条件编译选项,以通过编译(目前没有实现 WASM 的多进程接口)
6+
- `im_tm_widget` 中添加符合 Emscripten 3.1.56 的调用(在条件编译中)
7+
8+
## 如何测试
9+
测试默认的 Qt 构建不被改变
10+
```
11+
xmake f
12+
xmake b stem
13+
```
14+
15+
测试 WASM 构建
16+
```
17+
xmake f -p wasm
18+
xmake b stem
19+
xmake r stem
20+
```
21+
浏览器打开监听的地址

lolly/xmake.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ if is_plat("mingw") and is_host("windows") then
2121
set_toolchains("mingw@mingw-w64")
2222
end
2323

24-
if is_plat("wasm") then
25-
add_requires("emscripten 3.1.25")
26-
set_toolchains("emcc@emscripten")
27-
end
28-
2924
-- Options
3025
option("malloc")
3126
set_default("default")

0 commit comments

Comments
 (0)