Skip to content

Commit

Permalink
gha: use setup-emsdk
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 committed May 27, 2024
1 parent 6ba27dd commit 32ab337
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ jobs:
node-version-file: '.node-version'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: 3.1.60
actions-cache-folder: 'emsdk-cache'
- name: Poop out node info
run: which node && node --version && npm --version
- name: Install apt deps
run: sudo apt-get install clang-format ninja-build
- name: Install npm deps
run: npm ci
- name: pre-lib node info
run: which node && node --version && npm --version
- name: Build library
run: make lib
- name: post-lib node info
run: which node && node --version && npm --version
- name: Typecheck
run: make typecheck
- name: Check formatting
run: make checkformat
- name: Mode node info
run: which node && node --version && npm --version
- name: Run tests
run: make test
43 changes: 19 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 @@ -40,24 +39,20 @@ typecheck:

.PHONY: test
test: third_party/tessdata_fast
SHELL=/bin/bash
echo "Current Shell: $$SHELL"
echo "PATH: $$PATH"
echo "Checking user permissions:"
id
which node
node --version
node --test test/ocr-engine-test.js

.PHONY: release
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 +66,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 +121,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,15 +156,15 @@ 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
cp src/tesseract-core.d.ts build/

# 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.60
EMSDK_COMMIT=ce74ca2b1c968f897150bdc55daa9e3c12a3fefc

# v1.84.1
LEPTONICA_COMMIT=7e803e73511fbd320f01314c141d35d2b8491dde

Expand Down

0 comments on commit 32ab337

Please sign in to comment.