Skip to content

Commit

Permalink
Use pre-built ort, fix builds on Windows (BloopAI#231)
Browse files Browse the repository at this point in the history
* Fix building on Windows

Some key changes include:

- Using the pre-built `onnxruntime` library
- Patching `esaxx-rs` to avoid statically linking crt
- Disabling telemetry on Windows builds at runtime
- Moving the `model` folder to `apps/desktop/src-tauri` as the
  symlinked folder does not work in Windows
- Move `config.json` to a `config/` subdirectory, as tauri ignores it on
  Windows otherwise

This overrides the previous `ort` branch, so the two upstream branches
still need to be unified, as it is not possible to have differing crate
sources per target.

* Add `npm start` script

* Add ctags and qdrant Windows binaries

* Add Windows cert thumbprint and timestamp URL

* Remove indirect npm build scripts

* Dynamically load ORT at runtime

* Remove build.sh in favor of npm scripts

* Remove lib folder and onnxruntime artifacts, clean up Windows bin files

* Clean up windows cfg blocks, simplify disabling telemetry

* Move model to apps/desktop/src-tauri

Windows does not play well with symlinks, so we swap the symlink and
source directory, so that the tauri app can build successfully.

* Revert identifier to ai.bloop.bloop

* Copy dylibs in Docker build stage

* Update helm chart to pass --dylib-dir

* Rename dylibs in image to dylib

* Move telemetry logic to ort::EnvBuilder

* Fix flakes

* Fix deps task

* Remove dependencies.yml

---------

Co-authored-by: rsdy <p@symmetree.dev>
  • Loading branch information
calyptobai and rsdy committed Jun 22, 2023
1 parent be535ff commit 96cffe4
Show file tree
Hide file tree
Showing 194 changed files with 203 additions and 924 deletions.
253 changes: 13 additions & 240 deletions .gitattributes

Large diffs are not rendered by default.

125 changes: 0 additions & 125 deletions .github/workflows/dependencies.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ playwright-report

# local config
/local_config.json

apps/desktop/src-tauri/dylibs/*.so
apps/desktop/src-tauri/dylibs/*.dylib
apps/desktop/src-tauri/dylibs/*.dll
3 changes: 3 additions & 0 deletions .taurignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
server/bleep/bleep.db*
apps/desktop/src-tauri/dylibs/*.so
apps/desktop/src-tauri/dylibs/*.dylib
apps/desktop/src-tauri/dylibs/*.dll
31 changes: 14 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ inherits = "release"
debug = true
split-debuginfo = "unpacked"
strip = "none"

[patch.crates-io]
esaxx-rs = { git = "https://github.com/bloopai/esaxx-rs" }
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ ENV CXX /usr/bin/clang++
COPY server server
COPY apps/desktop/src-tauri apps/desktop/src-tauri
COPY Cargo.lock Cargo.toml .
RUN --mount=target=/root/.cache/sccache,type=cache --mount=target=/build/target,type=cache \
RUN --mount=target=/root/.cache/sccache,type=cache --mount=target=/build/target,type=cache \
cargo --locked build -p bleep --release && \
cp /build/target/release/bleep / && \
sccache --show-stats
sccache --show-stats && \
mkdir /dylib && \
cp /build/target/release/libonnxruntime.so /dylib/

FROM debian:bookworm-slim
VOLUME ["/repos", "/data"]
RUN apt-get update && apt-get -y install openssl ca-certificates libprotobuf-lite32 && apt-get clean
COPY model /model
COPY --from=builder /bleep /
COPY --from=builder /dylib /dylib
COPY --from=frontend /build/client/dist /frontend
ENTRYPOINT ["/bleep", "--host=0.0.0.0", "--source-dir=/repos", "--index-dir=/data", "--model-dir=/model"]
ENTRYPOINT ["/bleep", "--host=0.0.0.0", "--source-dir=/repos", "--index-dir=/data", "--model-dir=/model", "--dylib-dir=/dylib"]
20 changes: 0 additions & 20 deletions apps/desktop/build.sh

This file was deleted.

4 changes: 1 addition & 3 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"vite-build": "vite build",
"build": "npm-run-all tsc vite-build",
"preview": "vite preview",
"tauri": "tauri",
"tauri-dev": "./build.sh dev",
"tauri-build": "./build.sh build"
"tauri": "tauri"
}
}
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/bin/qdrant-x86_64-pc-windows-msvc.exe
Git LFS file not shown
38 changes: 38 additions & 0 deletions apps/desktop/src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
use std::{
env, fs,
path::{Path, PathBuf},
thread,
time::Duration,
};

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let profile_dir = out_dir
// "target/.../build/bloop-hash"
.parent()
.unwrap()
// "target/.../build"
.parent()
.unwrap()
// "target/.../"
.parent()
.unwrap();

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();

let dylib_name = match target_os.as_str() {
"linux" => Some("libonnxruntime.so"),
"macos" => Some("libonnxruntime.dylib"),
"windows" => None,
other => panic!("unknown OS {other}"),
};

if let Some(dylib_name) = dylib_name {
let dylib_path = profile_dir.join(dylib_name);

while !dylib_path.exists() {
thread::sleep(Duration::from_millis(500));
}

fs::copy(dylib_path, Path::new(".").join("dylibs").join(dylib_name)).unwrap();
}

tauri_build::build()
}
1 change: 0 additions & 1 deletion apps/desktop/src-tauri/config.json

This file was deleted.

1 change: 1 addition & 0 deletions apps/desktop/src-tauri/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
1 change: 0 additions & 1 deletion apps/desktop/src-tauri/model

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion apps/desktop/src-tauri/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
let configuration = {
let path = app
.path_resolver()
.resolve_resource("config.json")
.resolve_resource("config/config.json")
.expect("failed to resolve resource");

let mut bundled = Configuration::read(path).unwrap();
Expand All @@ -37,6 +37,11 @@ where
.path_resolver()
.resolve_resource("model")
.expect("bad bundle");
bundled.dylib_dir = Some(
app.path_resolver()
.resolve_resource("dylibs")
.expect("missing `apps/desktop/src-tauri/dylibs`"),
);

let data_dir = app.path_resolver().app_data_dir().unwrap();
bundled.index_dir = data_dir.join("bleep");
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src-tauri/src/qdrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ fn run_command(command: &Path, qdrant_dir: &Path) -> Child {

#[cfg(windows)]
fn run_command(command: &Path, qdrant_dir: &Path) -> Child {
use std::os::windows::process::CommandExt;

Command::new(command)
.current_dir(qdrant_dir)
// Add a CREATE_NO_WINDOW flag to prevent qdrant console popup
.creation_flags(0x08000000)
.spawn()
.expect("failed to start qdrant")
}
Expand Down
11 changes: 6 additions & 5 deletions apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@
"signingIdentity": null
},
"resources": [
"config.json",
"model/*"
"model/*",
"dylibs/*",
"config/config.json"
],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"certificateThumbprint": "b955de6f8483ad3b14497e798a6eef48a137931b",
"digestAlgorithm": "sha256",
"timestampUrl": ""
"timestampUrl": "http://timestamp.sectigo.com"
}
},
"security": {
Expand Down Expand Up @@ -100,4 +101,4 @@
}
]
}
}
}
Loading

0 comments on commit 96cffe4

Please sign in to comment.