Skip to content

Commit

Permalink
gha: use setup-emsdk (#53)
Browse files Browse the repository at this point in the history
Use system emsdk when building locally.

Should make builds faster.
  • Loading branch information
wydengyre authored Jun 15, 2024
1 parent 251a4e7 commit 6e079e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
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

0 comments on commit 6e079e1

Please sign in to comment.