diff options
author | 深淵の鴿子 <71170059+ZerxZ@users.noreply.github.com> | 2024-10-27 20:51:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-28 11:51:48 +0800 |
commit | 3387abbfe072cbfe1ed1e7a3d71668603831591b (patch) | |
tree | 22a7601ed657750ae57ad45d5d3ee8f6d88b18f3 | |
parent | 1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0 (diff) | |
download | yuescript-3387abbfe072cbfe1ed1e7a3d71668603831591b.tar.gz yuescript-3387abbfe072cbfe1ed1e7a3d71668603831591b.tar.bz2 yuescript-3387abbfe072cbfe1ed1e7a3d71668603831591b.zip |
Add Support WASM ESM and CommonJs module, Typescript. (#176)
-rw-r--r-- | .github/workflows/wasm.yml | 23 | ||||
-rw-r--r-- | makefile | 122 | ||||
-rw-r--r-- | wasm/package.json | 64 |
3 files changed, 208 insertions, 1 deletions
diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml new file mode 100644 index 0000000..a0910ba --- /dev/null +++ b/.github/workflows/wasm.yml | |||
@@ -0,0 +1,23 @@ | |||
1 | name: Wasm Build | ||
2 | |||
3 | on: | ||
4 | workflow_dispatch: | ||
5 | |||
6 | jobs: | ||
7 | build: | ||
8 | name: Build | ||
9 | runs-on: macos-latest | ||
10 | steps: | ||
11 | - name: Checkout | ||
12 | uses: actions/checkout@v3 | ||
13 | - name: Build Wasm | ||
14 | run: | | ||
15 | brew upgrade -f python | ||
16 | brew install emscripten | ||
17 | make wasm-node | ||
18 | - name: Upload artifact | ||
19 | uses: actions/upload-artifact@v4 | ||
20 | with: | ||
21 | name: yuescript-wasm | ||
22 | path: ./wasm | ||
23 | retention-days: 7 | ||
@@ -207,11 +207,131 @@ endif | |||
207 | @echo -n "Total build time: " | 207 | @echo -n "Total build time: " |
208 | @$(END_TIME) | 208 | @$(END_TIME) |
209 | 209 | ||
210 | .PHONY: wasm-node | ||
211 | wasm-node: clean | ||
212 | @$(MAKE) generic CC='emcc' AR='emar rcu' RANLIB='emranlib' -C $(SRC_PATH)/3rdParty/lua | ||
213 | @mkdir -p wasm/dist | ||
214 | @mkdir -p wasm/dist/esm | ||
215 | @mkdir -p wasm/dist/cjs | ||
216 | # ESM Module | ||
217 | @emcc $(SRC_PATH)/yue_wasm.cpp \ | ||
218 | $(SRC_PATH)/yuescript/ast.cpp \ | ||
219 | $(SRC_PATH)/yuescript/yue_ast.cpp \ | ||
220 | $(SRC_PATH)/yuescript/parser.cpp \ | ||
221 | $(SRC_PATH)/yuescript/yue_compiler.cpp \ | ||
222 | $(SRC_PATH)/yuescript/yue_parser.cpp \ | ||
223 | $(SRC_PATH)/yuescript/yuescript.cpp \ | ||
224 | $(SRC_PATH)/3rdParty/lua/liblua.a \ | ||
225 | -O2 \ | ||
226 | -o wasm/dist/esm/yuescript.mjs \ | ||
227 | -I $(SRC_PATH) \ | ||
228 | -I $(SRC_PATH)/3rdParty/lua \ | ||
229 | -std=c++17 \ | ||
230 | --bind \ | ||
231 | -fexceptions \ | ||
232 | -Wno-deprecated-declarations \ | ||
233 | -gsource-map \ | ||
234 | --emit-tsd="yuescript.d.ts" \ | ||
235 | -s EXPORT_NAME="'_createYuescriptModule'" \ | ||
236 | -s EXPORT_EXCEPTION_HANDLING_HELPERS \ | ||
237 | -s EXCEPTION_CATCHING_ALLOWED=['we only want to allow exception handling in side modules'] \ | ||
238 | -sEXPORTED_RUNTIME_METHODS='wasmTable,ERRNO_CODES' \ | ||
239 | -s FORCE_FILESYSTEM=1 \ | ||
240 | -s TOTAL_MEMORY=20971520 \ | ||
241 | -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \ | ||
242 | -s EXPORT_ALL=1 \ | ||
243 | -s FS_DEBUG=1 \ | ||
244 | -s STACK_SIZE=5MB \ | ||
245 | -s AUTO_JS_LIBRARIES=0 \ | ||
246 | -s AUTO_NATIVE_LIBRARIES=0 \ | ||
247 | -s NODEJS_CATCH_EXIT=0 \ | ||
248 | -s NODEJS_CATCH_REJECTION=0 \ | ||
249 | -sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 \ | ||
250 | -s USE_ZLIB \ | ||
251 | -s USE_BZIP2 \ | ||
252 | -s WASM_BIGINT \ | ||
253 | -s MODULARIZE=1 \ | ||
254 | -s LZ4=1 | ||
255 | # CommonJS Module | ||
256 | @emcc $(SRC_PATH)/yue_wasm.cpp \ | ||
257 | $(SRC_PATH)/yuescript/ast.cpp \ | ||
258 | $(SRC_PATH)/yuescript/yue_ast.cpp \ | ||
259 | $(SRC_PATH)/yuescript/parser.cpp \ | ||
260 | $(SRC_PATH)/yuescript/yue_compiler.cpp \ | ||
261 | $(SRC_PATH)/yuescript/yue_parser.cpp \ | ||
262 | $(SRC_PATH)/yuescript/yuescript.cpp \ | ||
263 | $(SRC_PATH)/3rdParty/lua/liblua.a \ | ||
264 | -O2 \ | ||
265 | -o wasm/dist/cjs/yuescript.cjs \ | ||
266 | --emit-tsd="yuescript.d.ts" \ | ||
267 | -I $(SRC_PATH) \ | ||
268 | -I $(SRC_PATH)/3rdParty/lua \ | ||
269 | -std=c++17 \ | ||
270 | --bind \ | ||
271 | -fexceptions \ | ||
272 | -Wno-deprecated-declarations \ | ||
273 | -gsource-map \ | ||
274 | -s EXPORT_NAME="'_createYuescriptModule'" \ | ||
275 | -s EXPORT_EXCEPTION_HANDLING_HELPERS \ | ||
276 | -s EXCEPTION_CATCHING_ALLOWED=['we only want to allow exception handling in side modules'] \ | ||
277 | -sEXPORTED_RUNTIME_METHODS='wasmTable,ERRNO_CODES' \ | ||
278 | -s FORCE_FILESYSTEM=1 \ | ||
279 | -s TOTAL_MEMORY=20971520 \ | ||
280 | -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \ | ||
281 | -s EXPORT_ALL=1 \ | ||
282 | -s FS_DEBUG=1 \ | ||
283 | -s STACK_SIZE=5MB \ | ||
284 | -s AUTO_JS_LIBRARIES=0 \ | ||
285 | -s AUTO_NATIVE_LIBRARIES=0 \ | ||
286 | -s NODEJS_CATCH_EXIT=0 \ | ||
287 | -s NODEJS_CATCH_REJECTION=0 \ | ||
288 | -sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 \ | ||
289 | -s USE_ZLIB \ | ||
290 | -s USE_BZIP2 \ | ||
291 | -s WASM_BIGINT\ | ||
292 | -s MODULARIZE=1\ | ||
293 | -s LZ4=1 | ||
294 | @${MAKE} clean | ||
295 | |||
210 | .PHONY: wasm | 296 | .PHONY: wasm |
211 | wasm: clean | 297 | wasm: clean |
212 | @$(MAKE) generic CC='emcc' AR='emar rcu' RANLIB='emranlib' -C $(SRC_PATH)/3rdParty/lua | 298 | @$(MAKE) generic CC='emcc' AR='emar rcu' RANLIB='emranlib' -C $(SRC_PATH)/3rdParty/lua |
213 | @mkdir -p doc/docs/.vuepress/public/js | 299 | @mkdir -p doc/docs/.vuepress/public/js |
214 | @emcc $(SRC_PATH)/yue_wasm.cpp $(SRC_PATH)/yuescript/ast.cpp $(SRC_PATH)/yuescript/yue_ast.cpp $(SRC_PATH)/yuescript/parser.cpp $(SRC_PATH)/yuescript/yue_compiler.cpp $(SRC_PATH)/yuescript/yue_parser.cpp $(SRC_PATH)/yuescript/yuescript.cpp $(SRC_PATH)/3rdParty/lua/liblua.a -O2 -o doc/docs/.vuepress/public/js/yuescript.js -I $(SRC_PATH) -I $(SRC_PATH)/3rdParty/lua -std=c++17 --bind -fexceptions -Wno-deprecated-declarations | 300 | @emcc $(SRC_PATH)/yue_wasm.cpp \ |
301 | $(SRC_PATH)/yuescript/ast.cpp \ | ||
302 | $(SRC_PATH)/yuescript/yue_ast.cpp \ | ||
303 | $(SRC_PATH)/yuescript/parser.cpp \ | ||
304 | $(SRC_PATH)/yuescript/yue_compiler.cpp \ | ||
305 | $(SRC_PATH)/yuescript/yue_parser.cpp \ | ||
306 | $(SRC_PATH)/yuescript/yuescript.cpp \ | ||
307 | $(SRC_PATH)/3rdParty/lua/liblua.a \ | ||
308 | -O2 \ | ||
309 | -o doc/docs/.vuepress/public/js/yuescript.js \ | ||
310 | -I $(SRC_PATH) \ | ||
311 | -I $(SRC_PATH)/3rdParty/lua \ | ||
312 | -std=c++17 \ | ||
313 | --bind \ | ||
314 | -fexceptions \ | ||
315 | -Wno-deprecated-declarations \ | ||
316 | -s EXPORT_EXCEPTION_HANDLING_HELPERS \ | ||
317 | -s EXCEPTION_CATCHING_ALLOWED=['we only want to allow exception handling in side modules'] \ | ||
318 | -sEXPORTED_RUNTIME_METHODS='wasmTable,ERRNO_CODES' \ | ||
319 | -s FORCE_FILESYSTEM=1 \ | ||
320 | -s TOTAL_MEMORY=20971520 \ | ||
321 | -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \ | ||
322 | -s EXPORT_ALL=1 \ | ||
323 | -s FS_DEBUG=1 \ | ||
324 | -s STACK_SIZE=5MB \ | ||
325 | -s AUTO_JS_LIBRARIES=0 \ | ||
326 | -s AUTO_NATIVE_LIBRARIES=0 \ | ||
327 | -s NODEJS_CATCH_EXIT=0 \ | ||
328 | -s NODEJS_CATCH_REJECTION=0 \ | ||
329 | -sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 \ | ||
330 | -s USE_ZLIB \ | ||
331 | -s USE_BZIP2 \ | ||
332 | -s WASM_BIGINT\ | ||
333 | -s MODULARIZE=1 \ | ||
334 | -s LZ4=1 | ||
215 | @${MAKE} clean | 335 | @${MAKE} clean |
216 | 336 | ||
217 | # Debug build for gdb debugging | 337 | # Debug build for gdb debugging |
diff --git a/wasm/package.json b/wasm/package.json new file mode 100644 index 0000000..b8d2586 --- /dev/null +++ b/wasm/package.json | |||
@@ -0,0 +1,64 @@ | |||
1 | { | ||
2 | "name": "yuescript", | ||
3 | "version": "0.25.5", | ||
4 | "description": "A Moonscript dialect compiles to Lua.", | ||
5 | "main": "./dist/esm/yuescript.mjs", | ||
6 | "repository": { | ||
7 | "type": "git", | ||
8 | "url": "git+https://github.com/pigpigyyy/Yuescript.git" | ||
9 | }, | ||
10 | "keywords": ["lua", "cpp", "moonscript", "yuescript", "transpiler"], | ||
11 | "exports": { | ||
12 | ".": { | ||
13 | "import": "./dist/esm/yuescript.mjs", | ||
14 | "require": "./dist/cjs/yuescript.js", | ||
15 | "types": "./dist/esm/yuescript.d.ts" | ||
16 | }, | ||
17 | "./yuescript.wasm": { | ||
18 | "import": "./dist/esm/yuescript.wasm", | ||
19 | "require": "./dist/cjs/yuescript.wasm" | ||
20 | }, | ||
21 | "./yuescript.wasm.map": { | ||
22 | "import": "./dist/esm/yuescript.wasm.map", | ||
23 | "require": "./dist/cjs/yuescript.wasm.map" | ||
24 | } | ||
25 | }, | ||
26 | "files": [ | ||
27 | "./dist/cjs/yuescript.cjs", | ||
28 | "./dist/esm/yuescript.mjs", | ||
29 | "./dist/esm/yuescript.d.ts", | ||
30 | "./dist/esm/yuescript.wasm", | ||
31 | "./dist/esm/yuescript.wasm.map", | ||
32 | "./dist/cjs/yuescript.d.ts", | ||
33 | "./dist/cjs/yuescript.wasm", | ||
34 | "./dist/cjs/yuescript.wasm.map" | ||
35 | |||
36 | ], | ||
37 | "browser": { | ||
38 | "child_process": false, | ||
39 | "crypto": false, | ||
40 | "fs": false, | ||
41 | "fs/promises": false, | ||
42 | "path": false, | ||
43 | "url": false, | ||
44 | "vm": false, | ||
45 | "ws": false | ||
46 | }, | ||
47 | "author": "pigpigyyy", | ||
48 | "license": "MIT", | ||
49 | "bugs": { | ||
50 | "url": "https://github.com/pigpigyyy/Yuescript/issues" | ||
51 | }, | ||
52 | "homepage": "https://github.com/pigpigyyy/Yuescript#readme", | ||
53 | "tsd": { | ||
54 | "compilerOptions": { | ||
55 | "lib": ["ES2017", "DOM"] | ||
56 | } | ||
57 | }, | ||
58 | "types": "./dist/esm/yuescript.d.ts", | ||
59 | "engines": { | ||
60 | "node": ">=18.0.0" | ||
61 | }, | ||
62 | "devDependencies": {}, | ||
63 | "scripts": {} | ||
64 | } | ||