-
-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wasm support #754
Closed
Closed
Add wasm support #754
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: WASM CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install emsdk | ||
run: | | ||
git clone https://github.com/emscripten-core/emsdk.git | ||
cd emsdk | ||
./emsdk install latest | ||
./emsdk activate latest | ||
- name: Build wasm | ||
run: | | ||
. emsdk/emsdk_env.sh | ||
bash wasm/build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
demo.data | ||
demo.js | ||
demo.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
root=$PWD | ||
|
||
# build data and share with wasm | ||
cmake . -B build/native \ | ||
-DCMAKE_INSTALL_PREFIX:PATH=$root/build/sysroot/usr | ||
make -C build/native/data install | ||
|
||
# build wasm libopencc.a and libmarisa.a | ||
emcmake cmake . -B build/wasm \ | ||
-DBUILD_SHARED_LIBS:BOOL=OFF \ | ||
-DCMAKE_BUILD_TYPE:STRING="Release" \ | ||
-DCMAKE_INSTALL_PREFIX:PATH=/usr | ||
make DESTDIR=$root/build/sysroot -C build/wasm install | ||
cp build/wasm/deps/marisa-0.2.6/libmarisa.a build/sysroot/usr/lib | ||
|
||
# build demo.js | ||
em++ -std=c++14 \ | ||
-I build/sysroot/usr/include/opencc \ | ||
--preload-file build/sysroot/usr/share/opencc@/usr/share/opencc \ | ||
-o wasm/demo.js \ | ||
wasm/demo.cpp \ | ||
-L build/sysroot/usr/lib \ | ||
-l opencc -l marisa | ||
|
||
# test demo.js | ||
expected="網路" | ||
actual=$(cd wasm; node demo.js) | ||
if [[ $actual != $expected ]]; then | ||
echo Test failed. | ||
echo expected: $expected | ||
echo actual: $actual | ||
exit 1 | ||
else | ||
echo Test passed. | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
#include "opencc.h" | ||
|
||
int main() { | ||
const opencc::SimpleConverter converter("s2twp.json"); | ||
std::cout << converter.Convert("网络") << std::endl; // 網路 | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那 txt 转 ocd2 的工作如何在编译时进行?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm/build.sh里,先本地编译,然后把ocd2产物共享给wasm