Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/ci-macos-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build on macOS for WASM
on:
push:
branches: [main]
paths:
- "src/**"
- "!src/Plugins/Macos/**"
- "!src/Plugins/Windows/**"
- "tests/**"
- "lolly/**"
- "moebius/**"
- "xmake.lua"
- 'xmake/options.lua'
- 'xmake/requires.lua'
- 'xmake/targets/**'
- "xmake/packages.lua"
- "xmake/packages/**"
- ".github/workflows/ci-macos-wasm.yml"
- "TeXmacs/tests/*.scm"
- "3rdparty/**"
pull_request:
branches: [main]
paths:
- "src/**"
- "!src/Plugins/Macos/**"
- "!src/Plugins/Windows/**"
- "tests/**"
- "lolly/**"
- "moebius/**"
- "xmake.lua"
- 'xmake/options.lua'
- 'xmake/requires.lua'
- 'xmake/targets/**'
- "xmake/packages.lua"
- "xmake/packages/**"
- ".github/workflows/ci-macos-wasm.yml"
- "TeXmacs/tests/*.scm"
- "3rdparty/**"
workflow_dispatch:

env:
XMAKE_ROOT: y
INSTALL_DIR: tmp/build/packages/app.mogan/

jobs:
build:
strategy:
matrix:
os: [macos-14]
arch: [arm64]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
if: always()
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: cache xmake
uses: actions/cache@v4
with:
path: |
${{github.workspace}}/build/.build_cache
/Users/runner/.xmake
key: xmake-${{ runner.os }}-wasm-${{ hashFiles('xmake/vars.lua', 'lolly/xmake.lua', 'moebius/xmake.lua') }}

- name: set XMAKE_GLOBALDIR
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV

- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: v3.0.4
actions-cache-folder: '.xmake-cache'

- name: xmake repo --update
run: xmake repo --update

- name: cache packages from xrepo
uses: actions/cache@v4
with:
path: |
${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: xrepo-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('xmake/vars.lua', 'lolly/xmake.lua', 'moebius/xmake.lua') }}

- name: config
run: xmake config --policies=build.ccache -o ${{ runner.workspace }}/build -m releasedbg -p wasm --qt_frontend=no --yes

- name: build
run: xmake build --yes -vD stem
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ docs/**/plugin_binary.md

# Binary of the goldfish plugin
TeXmacs/plugins/goldfish/bin/goldfish
TeXmacs/plugins/goldfish/bin/*.wasm
TeXmacs/plugins/goldfish/bin/*.js
TeXmacs/plugins/goldfish/bin/*.html
goldfish.dSYM/
*.sym
*goldfish.pdb

# font
TeXmacs/fonts/opentype/noto

record
record
2 changes: 1 addition & 1 deletion 3rdparty/libaesgm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package("liii-libaesgm")

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

on_install("linux", "macosx", "windows", "mingw", function (package)
on_install("linux", "macosx", "windows", "mingw", "wasm", function (package)
if package:is_plat("windows", "mingw") and package:is_arch("arm", "arm64") then
-- Windows is always little endian
io.replace("brg_endian.h", [[
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/pdfhummus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package("liii-pdfhummus")
end
end
end)
on_install("linux", "windows", "mingw", "macosx", function (package)
on_install("linux", "windows", "mingw", "macosx", "wasm", function (package)
local configs = {}
if package:config("shared") then
configs.kind = "shared"
Expand Down
5 changes: 3 additions & 2 deletions 3rdparty/pdfhummus/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- originally from https://github.com/xmake-io/xmake-repo/pull/1709

includes("../libaesgm.lua")
option("libtiff", {description = "Enable libtiff", default = false})
option("libpng", {description = "Enable libpng", default = false})
option("libjpeg", {description = "Enable libjpeg", default = false})
Expand All @@ -17,14 +18,14 @@ end
if has_config("openssl") then
add_requires("openssl")
end
add_requires("freetype", "zlib", "libaesgm")
add_requires("freetype", "zlib", "liii-libaesgm")
target("pdfhummus")
set_kind("$(kind)")
add_files("PDFWriter/*.cpp")
add_headerfiles("(PDFWriter/*.h)")
add_packages("freetype")
add_packages("libtiff", "libpng", "libjpeg", "openssl")
add_packages("libaesgm", "zlib")
add_packages("liii-libaesgm", "zlib")
if has_package("libtiff") then
add_defines("_INCLUDE_TIFF_HEADER")
add_cxflags("-Wno-deprecated-declarations")
Expand Down
6 changes: 0 additions & 6 deletions 3rdparty/tbox/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ if has_config("coroutine") then
add_cxflags("gcc::-Wno-error=dangling-pointer")
end

-- set wasm toolchain
if is_plat("wasm") then
add_requires("emscripten")
set_toolchains("emcc@emscripten")
end

-- add build modes
add_rules("mode.release", "mode.debug", "mode.profile", "mode.coverage", "mode.valgrind", "mode.asan", "mode.tsan", "mode.ubsan")
if is_mode("debug") then
Expand Down
62 changes: 62 additions & 0 deletions bin/wasm_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
import sys
import os

root = os.path.abspath(sys.argv[1])

html = os.path.join(root, "stem.html")
js = os.path.join(root, "stem.js")

#if not os.path.exists(html) and os.path.exists(js):
with open(html, "w", encoding="utf-8") as f:
f.write("""<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>stem</title>
<style>
html, body, canvas {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>

<script>
var Module = {
canvas: document.getElementById('canvas')
};
</script>

<script src="stem.js"></script>
</body>
</html>
""")

class Handler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=root, **kwargs)

def end_headers(self):
self.send_header(
"Cross-Origin-Opener-Policy",
"same-origin"
)
self.send_header(
"Cross-Origin-Embedder-Policy",
"require-corp"
)
super().end_headers()

server = ThreadingHTTPServer(
("127.0.0.1", 8000),
Handler
)

print("Serving on http://127.0.0.1:8000/stem.html")

server.serve_forever()
21 changes: 21 additions & 0 deletions devel/0724.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [0724] WASM Support for STEM (ImGui)
## What
- 在构建脚本中添加了适配 wasm 的逻辑
- bin 中新增 wasm_server.py
- `tm_server.cpp` `pipe_link.cpp` 中调整 WASM 条件编译选项,以通过编译(目前没有实现 WASM 的多进程接口)
- `im_tm_widget` 中添加符合 Emscripten 3.1.56 的调用(在条件编译中)

## 如何测试
测试默认的 Qt 构建不被改变
```
xmake f
xmake b stem
```

测试 WASM 构建
```
xmake f -p wasm
xmake b stem
xmake r stem
```
浏览器打开监听的地址
5 changes: 0 additions & 5 deletions lolly/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ 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

-- Options
option("malloc")
set_default("default")
Expand Down
Loading
Loading