Skip to content

Commit 1c8828e

Browse files
committed
feat: meson build
1 parent ae611a6 commit 1c8828e

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

deno.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@discere-os/pango.wasm",
3+
"exports": {
4+
".": "./",
5+
"./side": "./install/wasm/pango-side.wasm",
6+
"./main": "./install/wasm/pango-main.js"
7+
},
8+
"tasks": {
9+
"build:main:meson": "meson setup build-main --cross-file=scripts/emscripten.cross -Dbuildtype=release --prefix=$PWD/install -Dlibdir=wasm -Dbindir=wasm && meson compile -C build-main pango-main && meson install -C build-main",
10+
"build:side:meson": "meson setup build-side --cross-file=scripts/emscripten.cross -Dbuildtype=release --prefix=$PWD/install -Dlibdir=wasm -Dbindir=wasm -Dc_args='-msimd128' -Dc_link_args='-sSIDE_MODULE=2 -fPIC -O3 -flto' && meson compile -C build-side pango-side && meson install -C build-side && python3 scripts/postinstall.py $PWD/install",
11+
"build:wasm:meson": "deno task build:main:meson && deno task build:side:meson"
12+
}
13+
}

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ root_inc = include_directories('.')
562562
pango_inc = include_directories('pango')
563563

564564
subdir('pango')
565+
subdir('wasm')
565566
subdir('utils')
566567
subdir('tools')
567568
subdir('docs')

scripts/emscripten.cross

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[binaries]
2+
c = 'emcc'
3+
cpp = 'em++'
4+
ar = 'emar'
5+
ranlib = 'emranlib'
6+
strip = 'llvm-strip'
7+
pkgconfig = 'em-pkg-config'
8+
9+
[built-in options]
10+
c_args = []
11+
c_link_args = []
12+
13+
[host_machine]
14+
system = 'emscripten'
15+
cpu_family = 'wasm32'
16+
cpu = 'wasm32'
17+
endian = 'little'

scripts/postinstall.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
import os, sys, shutil
3+
4+
def main():
5+
prefix = os.environ.get('MESON_INSTALL_DESTDIR_PREFIX') or (sys.argv[1] if len(sys.argv) > 1 else None)
6+
if not prefix:
7+
prefix = os.getcwd()
8+
wasm_dir = os.path.join(prefix, 'wasm')
9+
if not os.path.isdir(wasm_dir):
10+
return 0
11+
target = os.path.join(wasm_dir, 'pango-side.wasm')
12+
if os.path.exists(target):
13+
return 0
14+
for f in os.listdir(wasm_dir):
15+
if f.endswith('.wasm'):
16+
shutil.copy2(os.path.join(wasm_dir,f), target)
17+
break
18+
return 0
19+
20+
if __name__ == '__main__':
21+
raise SystemExit(main())
22+

wasm/meson.build

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pango_wasm_cargs = ['-msimd128', '-DPANGO_WASM=1']
2+
3+
pango_main_link_args = [
4+
'-sWASM=1',
5+
'-sMODULARIZE=1',
6+
'-sEXPORT_ES6=1',
7+
'-sEXPORT_NAME=PangoModule',
8+
'-sALLOW_MEMORY_GROWTH=1',
9+
'-sENVIRONMENT=web,webview,worker',
10+
'-sNO_FILESYSTEM=1',
11+
'-sEXPORTED_RUNTIME_METHODS=["cwrap","ccall","UTF8ToString"]',
12+
'-O3',
13+
'-flto',
14+
]
15+
16+
executable(
17+
'pango-main',
18+
files('pango_wasm_module.c'),
19+
dependencies: [libpango_dep],
20+
c_args: pango_wasm_cargs,
21+
link_args: pango_main_link_args,
22+
install: true,
23+
install_dir: get_option('bindir'),
24+
)
25+
26+
pango_side_link_args = [
27+
'-sSIDE_MODULE=2',
28+
'-fPIC',
29+
'-O3',
30+
'-flto',
31+
'-sEXPORTED_FUNCTIONS=["_pango_wasm_version"]',
32+
]
33+
34+
shared_module(
35+
'pango-side',
36+
files('pango_wasm_side.c'),
37+
dependencies: [libpango_dep],
38+
name_prefix: '',
39+
c_args: pango_wasm_cargs,
40+
link_args: pango_side_link_args,
41+
install: true,
42+
install_dir: get_option('libdir'),
43+
)
44+

wasm/pango_wasm_module.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <emscripten.h>
2+
#include <pango/pango.h>
3+
4+
EMSCRIPTEN_KEEPALIVE
5+
const char* pango_wasm_version(void) {
6+
return pango_version_string();
7+
}
8+

wasm/pango_wasm_side.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <pango/pango.h>
2+
3+
const char* pango_wasm_version(void) {
4+
return pango_version_string();
5+
}
6+

0 commit comments

Comments
 (0)