Skip to content

Commit

Permalink
wasm debug, fix comment nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Jul 22, 2023
1 parent 11282ce commit 1544c37
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pnpm run font
pnpm run native
pnpm run schema
export ENABLE_LOGGING=OFF # optional, default ON
export BUILD_TYPE=Debug # optional, default Release
pnpm run lib
pnpm run wasm
```
Expand Down
2 changes: 1 addition & 1 deletion checksum
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1af97e7578a6b23af1aff33269acf462 public/rime.data
c5623abdffe84cb43c4cfb105df1208b public/rime.js
3e81ab6c5bca5747ef648fc1e37be41b public/rime.wasm
f25061f36b942ee3d4dd929f78693aa2 public/rime.wasm
12 changes: 8 additions & 4 deletions scripts/build_lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set -e

: "${ENABLE_LOGGING:=ON}"
: "${BUILD_TYPE:=Release}"

export CXXFLAGS=-fexceptions

Expand Down Expand Up @@ -33,7 +34,7 @@ rm -f lua/onelua.c
PREFIX=/usr
CMAKE_DEF="""
-DCMAKE_INSTALL_PREFIX:PATH=$PREFIX
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE
-DBUILD_TESTING:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
Expand Down Expand Up @@ -67,7 +68,7 @@ marisa_trie_blddir=build/marisa-trie
rm -rf $marisa_trie_blddir
emcmake cmake librime/deps -B $marisa_trie_blddir -G Ninja \
$CMAKE_DEF
cmake --build $marisa_trie_blddir
cmake --build $marisa_trie_blddir
DESTDIR=$root/build/sysroot cmake --install $marisa_trie_blddir

pushd librime/deps/opencc
Expand All @@ -81,7 +82,7 @@ emcmake cmake librime/deps/opencc -B $opencc_blddir -G Ninja \
$CMAKE_DEF \
-DCMAKE_FIND_ROOT_PATH:PATH=$root/build/sysroot/usr \
-DUSE_SYSTEM_MARISA:BOOL=ON
cmake --build $opencc_blddir
cmake --build $opencc_blddir
DESTDIR=$root/build/sysroot cmake --install $opencc_blddir

if [[ $ENABLE_LOGGING == 'ON' ]]; then
Expand Down Expand Up @@ -109,5 +110,8 @@ emcmake cmake librime -B $librime_blddir -G Ninja \
-DBUILD_TEST:BOOL=OFF \
-DBUILD_STATIC:BOOL=ON \
-DENABLE_LOGGING:BOOL=$ENABLE_LOGGING
cmake --build $librime_blddir
cmake --build $librime_blddir
DESTDIR=$root/build/sysroot cmake --install $librime_blddir
# Fix source map for chromium debug
rm -rf $librime_blddir/src
ln -s ../../librime/src $librime_blddir/src
2 changes: 1 addition & 1 deletion scripts/build_wasm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const exportedFunctions = [

const compileArgs = [
'-std=c++14',
'-O2',
process.env.BUILD_TYPE === 'Debug' ? '-g' : '-O2',
'-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', `EXPORTED_FUNCTIONS=${exportedFunctions.map(name => '_' + name).join(',')}`,
'-s', 'EXPORTED_RUNTIME_METHODS=["ccall","FS"]',
Expand Down
2 changes: 1 addition & 1 deletion src/components/MyPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function analyze (result: RIME_RESULT, rimeKey: string) {
highlighted.value = result.highlighted
menuOptions.value = result.candidates.map((candidate, i) => {
let label = `${result.selectLabels?.[i] || i + 1} ${candidate.text}`
if (hideComment.value === false || (hideComment.value === 'emoji' && !isEmoji(candidate.text))) {
if (candidate.comment && (hideComment.value === false || (hideComment.value === 'emoji' && !isEmoji(candidate.text)))) {
label += ' ' + candidate.comment
}
return { label, key: i }
Expand Down
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ declare global {
selectLabels?: string[]
candidates: {
text: string
comment: string
comment?: string
}[]
}
type RIME_REJECTED = {
Expand Down
4 changes: 3 additions & 1 deletion wasm/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ const char *post_process() {
for (int i = 0; i < menu.num_candidates; ++i) {
boost::json::object candidate;
candidate["text"] = menu.candidates[i].text;
candidate["comment"] = menu.candidates[i].comment;
if (menu.candidates[i].comment) {
candidate["comment"] = menu.candidates[i].comment;
}
candidates.push_back(candidate);
}
obj["candidates"] = candidates;
Expand Down

0 comments on commit 1544c37

Please sign in to comment.