Skip to content

Commit 1fa6ef3

Browse files
committed
feat: deno and meson build
1 parent 94aace4 commit 1fa6ef3

7 files changed

Lines changed: 54 additions & 0 deletions

File tree

deno.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@discere-os/hunspell.wasm",
3+
"exports": { ".": "./", "./side": "./install/wasm/hunspell-side.wasm", "./main": "./install/wasm/hunspell-main.js" },
4+
"tasks": {
5+
"build:main:meson": "meson setup build-main --cross-file=scripts/emscripten.cross -Dmain_module=true -Dside_module=false -Dsimd=true --prefix=$PWD/install -Dlibdir=wasm -Dbindir=wasm && meson compile -C build-main hunspell-main && meson install -C build-main",
6+
"build:side:meson": "meson setup build-side --cross-file=scripts/emscripten.cross -Dmain_module=false -Dside_module=true -Dsimd=true --prefix=$PWD/install -Dlibdir=wasm -Dbindir=wasm && meson compile -C build-side hunspell-side && meson install -C build-side",
7+
"build:wasm:meson": "deno task build:main:meson && deno task build:side:meson"
8+
}
9+
}

exports.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"_malloc",
3+
"_free"
4+
]

meson.build

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
project('hunspell.wasm',['cpp','c'],version:'1.7.x',meson_version:'>=1.3.0',default_options:['buildtype=release','cpp_std=c++17'])
2+
fs = import('fs')
3+
if get_option('simd')
4+
add_project_arguments('-msimd128', language:'c')
5+
add_project_arguments('-msimd128', language:'cpp')
6+
endif
7+
incs = [ include_directories('src/hunspell') ]
8+
cxx = fs.glob('src/hunspell/*.cxx')
9+
cextras = ['src/hunspell/wasm_native.c','src/hunspell/wasm_simd.c']
10+
core = static_library('hunspell_core', cxx + cextras, include_directories: incs)
11+
if get_option('main_module')
12+
executable('hunspell-main','src/hunspell_wasm_module.cpp', link_with: core, include_directories: incs, install:true,
13+
link_args:['--no-entry','-sMODULARIZE=1','-sEXPORT_ES6=1','-sALLOW_MEMORY_GROWTH=1','-sENVIRONMENT=web,webview,worker','-sNO_FILESYSTEM=1','-sEXPORTED_RUNTIME_METHODS=["cwrap","ccall","UTF8ToString"]','-sEXPORTED_FUNCTIONS=@' + meson.project_source_root()/get_option('exports')])
14+
endif
15+
if get_option('side_module')
16+
shared_module('hunspell-side','src/hunspell_wasm_side.cpp', link_whole: core, include_directories: incs, name_prefix:'', install:true, link_args:['-sSIDE_MODULE=2','-fPIC'])
17+
endif

meson.options

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
option('main_module', type: 'boolean', value: false)
2+
option('side_module', type: 'boolean', value: false)
3+
option('simd', type: 'boolean', value: true)
4+
option('exports', type: 'string', value: 'exports.json')

scripts/emscripten.cross

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

src/hunspell_wasm_module.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern "C" int hunspell_wasm_version_stub(){ return 1; }

src/hunspell_wasm_side.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern "C" void __hunspell_wasm_side_marker(void) {}

0 commit comments

Comments
 (0)