Skip to content
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

gha: use emsdk action #53

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: 3.1.61
actions-cache-folder: 'emsdk-cache'
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: '.node-version'
Expand Down
36 changes: 12 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include third_party_versions.mk

EMSDK_DIR=$(PWD)/third_party/emsdk/upstream/emscripten
INSTALL_DIR=$(PWD)/install
FALLBACK_INSTALL_DIR=$(INSTALL_DIR)/fallback

Expand Down Expand Up @@ -47,17 +46,6 @@ release: clean lib typecheck test
@which np || (echo "Install np from https://github.com/sindresorhus/np" && false)
np minor

third_party/emsdk: third_party_versions.mk
mkdir -p third_party/emsdk
test -d $@/.git || git clone --depth 1 https://github.com/emscripten-core/emsdk.git $@
cd $@ && git fetch origin $(EMSDK_COMMIT) && git checkout $(EMSDK_COMMIT)
touch $@

build/emsdk.uptodate: third_party/emsdk | build
third_party/emsdk/emsdk install latest
third_party/emsdk/emsdk activate latest
touch build/emsdk.uptodate

# Compile flags for Leptonica. These turn off support for various image formats to
# reduce size. We don't need this since the browser includes this functionality.
LEPTONICA_FLAGS=\
Expand All @@ -71,11 +59,11 @@ third_party/leptonica: third_party_versions.mk
cd $@ && git fetch origin $(LEPTONICA_COMMIT) && git checkout $(LEPTONICA_COMMIT)
touch $@

build/leptonica.uptodate: third_party/leptonica build/emsdk.uptodate
build/leptonica.uptodate: third_party/leptonica
mkdir -p build/leptonica
cd build/leptonica && $(EMSDK_DIR)/emcmake cmake -G Ninja ../../third_party/leptonica $(LEPTONICA_FLAGS)
cd build/leptonica && $(EMSDK_DIR)/emmake ninja
cd build/leptonica && $(EMSDK_DIR)/emmake ninja install
cd build/leptonica && emcmake cmake -G Ninja ../../third_party/leptonica $(LEPTONICA_FLAGS)
cd build/leptonica && emmake ninja
cd build/leptonica && emmake ninja install
touch build/leptonica.uptodate

# Additional preprocessor defines for Tesseract.
Expand Down Expand Up @@ -126,16 +114,16 @@ third_party/tessdata_fast:

build/tesseract.uptodate: build/leptonica.uptodate third_party/tesseract
mkdir -p build/tesseract
(cd build/tesseract && $(EMSDK_DIR)/emcmake cmake -G Ninja ../../third_party/tesseract $(TESSERACT_FLAGS))
(cd build/tesseract && $(EMSDK_DIR)/emmake ninja)
(cd build/tesseract && $(EMSDK_DIR)/emmake ninja install)
(cd build/tesseract && emcmake cmake -G Ninja ../../third_party/tesseract $(TESSERACT_FLAGS))
(cd build/tesseract && emmake ninja)
(cd build/tesseract && emmake ninja install)
touch build/tesseract.uptodate

build/tesseract-fallback.uptodate: build/leptonica.uptodate third_party/tesseract
mkdir -p build/tesseract-fallback
(cd build/tesseract-fallback && $(EMSDK_DIR)/emcmake cmake -G Ninja ../../third_party/tesseract $(TESSERACT_FALLBACK_FLAGS))
(cd build/tesseract-fallback && $(EMSDK_DIR)/emmake ninja)
(cd build/tesseract-fallback && $(EMSDK_DIR)/emmake ninja install)
(cd build/tesseract-fallback && emcmake cmake -G Ninja ../../third_party/tesseract $(TESSERACT_FALLBACK_FLAGS))
(cd build/tesseract-fallback && emmake ninja)
(cd build/tesseract-fallback && emmake ninja install)
touch build/tesseract-fallback.uptodate

# emcc flags. `-Os` minifies the JS wrapper and optimises WASM code size.
Expand All @@ -161,14 +149,14 @@ EMCC_FLAGS =\

# Build main WASM binary for browsers that support WASM SIMD.
build/tesseract-core.js build/tesseract-core.wasm: src/lib.cpp src/tesseract-init.js build/tesseract.uptodate
$(EMSDK_DIR)/emcc src/lib.cpp $(EMCC_FLAGS) \
emcc src/lib.cpp $(EMCC_FLAGS) \
-I$(INSTALL_DIR)/include/ -L$(INSTALL_DIR)/lib/ -ltesseract -lleptonica -lembind \
-o build/tesseract-core.js

# Build fallback WASM binary for browsers that don't support WASM SIMD. The JS
# output from this build is not used.
build/tesseract-core-fallback.js build/tesseract-core-fallback.wasm: src/lib.cpp src/tesseract-init.js build/tesseract-fallback.uptodate
$(EMSDK_DIR)/emcc src/lib.cpp $(EMCC_FLAGS) \
emcc src/lib.cpp $(EMCC_FLAGS) \
-I$(INSTALL_DIR)/include/ -L$(FALLBACK_INSTALL_DIR)/lib/ -L$(INSTALL_DIR)/lib -ltesseract -lleptonica -lembind \
-o build/tesseract-core-fallback.js

Expand Down
3 changes: 0 additions & 3 deletions third_party_versions.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# v3.1.61
EMSDK_COMMIT=ca7b40ae222a2d8763b6ac845388744b0e57cfb7

# v1.84.1
LEPTONICA_COMMIT=7e803e73511fbd320f01314c141d35d2b8491dde

Expand Down