-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
feat(lyra): Add WebAssembly support #194
Merged
Merged
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
57dc9f5
feat(lyra): extract intersectTokenScores into the "lyra-utils-wasm" R…
jkomyno 10a94dc
chore: add bash scripts to build wasm artifacts
jkomyno 6cd1179
feat(lyra): replaced "intersectTokenScores" with its Wasm counterpart
jkomyno 5129e66
chore: add experimental nix script to build Rust / Wasm
jkomyno e71b499
ci: add experimental wasm workflow
jkomyno ad7782d
chore: swapped scripts interpreter to "/bin/bash"
jkomyno 8804f47
ci: attempt to fix "bad interpreter: no such file or directory " error
jkomyno 5225e95
chore: removed nix
jkomyno f56d8c6
ci: replaced bash scripts with node.js scripts
jkomyno 5fb6822
ci: added Dockerfile for Wasm generation pipeline
jkomyno eb99522
ci: replaced nix with Docker
jkomyno 4dea2f9
chore: add examples of optimized wasm and textual wat representation
jkomyno b5688f2
chore: swapped order in test to match Rust's lexicographic order when…
jkomyno 4e32323
chore: removed leftover from Dockerfile
jkomyno 1becdca
ci: trigger wasm workflow on PRs
jkomyno d1f51a0
ci: fix typo
jkomyno 1f0469d
ci: fix typo in "docker cp" command
jkomyno 75fb53b
test: removes generated files from tests
micheleriva 240fb39
build: wip: moves generated files to dist
micheleriva 67519f3
build(wasm): wip on wasm bundling
micheleriva 473891c
build(wasm): fixes wasm build system
micheleriva ea31125
build(wasm): fixes wasm build system
micheleriva 856fe29
chore: removes rc from package version
micheleriva c564847
build: fixes build system via dockerfile
micheleriva 52656bf
build: wip on build system
micheleriva bf46ead
build: removes post-install build
micheleriva 397efcc
test(wasm): fix tests
micheleriva d21ae83
build(docker): fixes dockerfile
micheleriva 5e03604
build(wasm): removes rust compilation process from bundling system
micheleriva 0043cdc
Merge branch 'main' into feat/add-wasm
micheleriva 7dfa3b5
build(wasm): wip on wasm build system
micheleriva 9958fba
build(wasm): adds rust build command
micheleriva edd6fa7
fix: Fixed WASM loader.
ShogunPanda ebad3c9
feat: wip on build system
micheleriva b883437
Merge branch 'main' into feat/add-wasm
micheleriva 8561bac
Merge branch 'main' into feat/add-wasm
micheleriva f09a459
Merge branch 'main' into feat/add-wasm
micheleriva 341cd6a
feat(lyra): adds components
micheleriva 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 |
---|---|---|
|
@@ -20,4 +20,6 @@ get-imdb-dataset.mjs | |
*.vue | ||
stemmer/**/*.js | ||
stemmer/**/*.d.ts | ||
*.dic | ||
*.dic | ||
src/wasm | ||
rust/scripts |
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,62 @@ | ||
name: wasm | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Compile Rust to WebAssembly with Docker | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
env: | ||
DOCKER_BUILDKIT: 1 | ||
COMPOSE_DOCKER_CLI_BUILD: 1 | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Set git to use LF | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
|
||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.inputs.enginesHash }} | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Set up cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ matrix.os }}-buildx-${{ hashFiles('**/Dockerfile') }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
build-contexts: rust=rust | ||
context: . | ||
file: ./Dockerfile | ||
builder: ${{ steps.buildx.outputs.name }} | ||
load: true | ||
tags: lyrasearch/lyra-wasm | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
|
||
- name: Create Wasm artifacts | ||
run: | | ||
docker create --name tmp lyrasearch/lyra-wasm | ||
docker cp tmp:/opt/app/src/wasm ./src/wasm | ||
docker rm -f tmp | ||
|
||
- name: Show Wasm artifacts | ||
run: ls -l ./src/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
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,94 @@ | ||
######## | ||
# docker buildx build --load -f Dockerfile --build-context rust=rust . -t lyrasearch/lyra-wasm --progress plain | ||
# docker create --name tmp lyrasearch/lyra-wasm | ||
# docker cp tmp:/opt/app/src/wasm ./src/wasm | ||
# docker rm -f tmp | ||
######## | ||
|
||
ARG RUST_VERSION="1.65.0" | ||
ARG ALPINE_VERSION="3.17.0" | ||
|
||
####################### | ||
#### Wasm tools builder | ||
####################### | ||
FROM alpine:${ALPINE_VERSION} as wasm-tools | ||
WORKDIR /tmp | ||
|
||
RUN apk update \ | ||
&& apk add --no-cache bash curl git | ||
RUN git clone https://github.com/WebAssembly/binaryen.git wasm-tools | ||
|
||
WORKDIR /tmp/wasm-tools | ||
|
||
RUN apk add build-base cmake git python3 py3-pip clang ninja \ | ||
&& pip3 install -r requirements-dev.txt | ||
|
||
RUN git submodule init \ | ||
&& git submodule update \ | ||
&& cmake . -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=install \ | ||
&& ninja install | ||
|
||
RUN cp ./bin/wasm-opt /usr/bin/wasm-opt | ||
|
||
######################## | ||
#### Rust + Wasm builder | ||
######################## | ||
FROM rust:${RUST_VERSION}-slim as builder | ||
|
||
ARG WASM_BINDGEN_VERSION="0.2.83" | ||
|
||
# Rust compilation profile | ||
ARG LYRA_WASM_PROFILE="release" | ||
|
||
# Rust+Wasm compilation target (e.g. nodejs, deno, etc.) | ||
ARG LYRA_WASM_TARGET="nodejs" | ||
|
||
# When set to "1", attempt Wasm optimization via wasm-opt | ||
ARG LYRA_WASM_OPT="1" | ||
|
||
## | ||
# Install Rust and Node.js tools | ||
## | ||
WORKDIR /opt/app/rust | ||
|
||
# Install Node.js (used for running wasm-bindgen scripts only) | ||
RUN apt-get update -y \ | ||
&& apt-get install -y curl libssl-dev pkg-config \ | ||
&& curl -sL https://deb.nodesource.com/setup_18.x | bash - \ | ||
&& apt-get install -y nodejs | ||
|
||
# Add Wasm target support | ||
RUN rustup target add wasm32-unknown-unknown | ||
RUN cargo install -f wasm-bindgen-cli@${WASM_BINDGEN_VERSION} | ||
|
||
# Import the Rust project | ||
COPY --from=rust . ./ | ||
|
||
# Run unit tests (and cache dependencies) | ||
RUN cargo test | ||
|
||
## | ||
# Build the Wasm artifacts running wasm-bindgen via Node.js scripts | ||
## | ||
WORKDIR /opt/app/rust/scripts | ||
|
||
ENV LYRA_WASM_PROFILE ${LYRA_WASM_PROFILE} | ||
ENV LYRA_WASM_TARGET ${LYRA_WASM_TARGET} | ||
ENV LYRA_WASM_OPT ${LYRA_WASM_OPT} | ||
|
||
# Pull in the wasm-opt optimizer compiled in a previous stage | ||
COPY --from=wasm-tools /usr/bin/wasm-opt /usr/bin/wasm-opt | ||
|
||
# Install Node.js dependencies | ||
RUN npm i | ||
WORKDIR /opt/app | ||
RUN (cd rust && node ./scripts/wasmAll.mjs) | ||
|
||
################ | ||
#### Wasm output | ||
################ | ||
FROM alpine:${ALPINE_VERSION} as output | ||
|
||
WORKDIR /opt/app/src/wasm | ||
|
||
COPY --from=builder /opt/app/src/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
Oops, something went wrong.
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.
We might need to include OSX and Windows here