Skip to content

Commit 36d94a7

Browse files
committed
[724] WASM Support for STEM
1 parent 237ed63 commit 36d94a7

23 files changed

Lines changed: 573 additions & 183 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build on Debian 13 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-debian13-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-debian13-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+
container: debian:13
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Install dependencies
51+
run: |
52+
DEBIAN_FRONTEND=noninteractive apt-get update
53+
DEBIAN_FRONTEND=noninteractive apt-get install -y gcc git 7zip unzip curl build-essential \
54+
fonts-noto-cjk libcurl4-openssl-dev libfreetype-dev libfontconfig-dev \
55+
libmimalloc-dev libgit2-dev zlib1g-dev libssl-dev libjpeg62-turbo-dev cmake \
56+
pandoc python3.13 python3.13-venv python3-pip ninja-build \
57+
libdbus-1-3 libglib2.0-0t64 libegl1 libgl-dev libxkbcommon0
58+
# Make python3 point to python3.13 so xmake uses system Python instead of compiling its own
59+
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.13 1
60+
# Pre-install aqtinstall to avoid xmake pulling its own Python 3.14
61+
python3 -m pip install --break-system-packages aqtinstall
62+
- uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0
65+
66+
- uses: xmake-io/github-action-setup-xmake@v1
67+
with:
68+
xmake-version: v3.0.7
69+
70+
- name: git add safe directory
71+
run: git config --global --add safe.directory '*'
72+
73+
- name: set XMAKE_GLOBALDIR
74+
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV
75+
76+
- name: xmake repo --update
77+
run: xmake repo --update
78+
79+
- name: cache packages from xrepo
80+
uses: actions/cache@v4
81+
with:
82+
path: |
83+
${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
84+
key: ${{ runner.os }}-xrepo-wasm-${{ hashFiles('**/packages.lua') }}
85+
86+
- name: cache xmake
87+
uses: actions/cache@v4
88+
with:
89+
path: |
90+
tmp/build/.build_cache
91+
key: ${{ runner.os }}-build-wasm-${{ hashFiles('**/packages.lua') }}
92+
93+
- name: config
94+
run: xmake config -vD --policies=build.ccache -o tmp/build -m releasedbg -p wasm --yes
95+
- name: build
96+
run: xmake build --yes -vD stem

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# binary files
2+
TeXmacs/plugins/goldfish/bin/*
23
*.vs
34
*.so
45
*.[oa]
@@ -53,4 +54,4 @@ goldfish.dSYM/
5354
# font
5455
TeXmacs/fonts/opentype/noto
5556

56-
record
57+
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")

src/Graphics/Renderer/brush.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace moebius::data;
1818
#include "tree_analyze.hpp"
1919
#include <moebius/data/true_color.hpp>
2020

21-
#if not defined(KERNEL_L3)
21+
#ifndef KERNEL_L3
2222
url get_current_buffer_safe ();
2323
#endif
2424

@@ -111,7 +111,7 @@ brush_rep::get_pattern_url () {
111111
url u= url_system (as_string (t[0]));
112112
url r= resolve_pattern (u);
113113
if (!is_none (r)) return r;
114-
#if defined(KERNEL_L3)
114+
#ifdef KERNEL_L3
115115
url base= url_pwd ();
116116
#else
117117
url base= get_current_buffer_safe ();

0 commit comments

Comments
 (0)