Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

download lib at build time

Thien Tran7dbc2c3af24c
diff --git a/Makefile b/Makefile
index 22e390c71..e72a4e645 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ endif
dev: install-and-build
yarn download:bin
- yarn copy:lib
+ yarn download:lib
yarn dev
# Linting
@@ -47,11 +47,12 @@ build-and-publish: install-and-build
# Build
build: install-and-build
+ yarn download:lib
yarn build
# Deprecated soon
build-tauri: install-and-build
- yarn copy:lib
+ yarn download:lib
yarn build
clean:
diff --git a/lib/linux/libvulkan.so b/lib/linux/libvulkan.so
deleted file mode 100644
index 241557479..000000000
Binary files a/lib/linux/libvulkan.so and /dev/null differ
diff --git a/lib/windows/vulkan-1.dll b/lib/windows/vulkan-1.dll
deleted file mode 100644
index e0039bc4e..000000000
Binary files a/lib/windows/vulkan-1.dll and /dev/null differ
diff --git a/package.json b/package.json
index 6af07be9a..1c59a191a 100644
--- a/package.json
+++ b/package.json
@@ -22,10 +22,7 @@
"dev:web": "yarn workspace @janhq/web-app dev",
"dev:tauri": "CLEAN=true yarn build:icon && yarn copy:assets:tauri && tauri dev",
"copy:assets:tauri": "cpx \"pre-install/*.tgz\" \"src-tauri/resources/pre-install/\"",
- "copy:lib": "run-script-os",
- "copy:lib:linux": "cpx \"./lib/linux/*.so\" \"./src-tauri/resources/lib/\"",
- "copy:lib:win32": "cpx \"./lib/windows/*.dll\" \"./src-tauri/resources/lib/\"",
- "copy:lib:darwin": "mkdir -p \"./src-tauri/resources/lib/\"",
+ "download:lib": "node ./scripts/download-lib.mjs",
"download:bin": "node ./scripts/download-bin.mjs",
"build:tauri:linux:win32": "yarn download:bin && yarn build:icon && yarn copy:assets:tauri && yarn tauri build",
"build:tauri:darwin": "yarn build:icon && yarn copy:assets:tauri && yarn tauri build --target universal-apple-darwin",
diff --git a/scripts/download-lib.mjs b/scripts/download-lib.mjs
new file mode 100644
index 000000000..d2086b36e
--- /dev/null
+++ b/scripts/download-lib.mjs
@@ -0,0 +1,86 @@
+console.log('Script is running')
+// scripts/download-lib.mjs
+import https from 'https'
+import fs, { mkdirSync } from 'fs'
+import os from 'os'
+import path from 'path'
+import { copySync } from 'cpx'
+
+function download(url, dest) {
+ return new Promise((resolve, reject) => {
+ console.log(`Downloading ${url} to ${dest}`)
+ const file = fs.createWriteStream(dest)
+ https
+ .get(url, (response) => {
+ console.log(`Response status code: ${response.statusCode}`)
+ if (
+ response.statusCode >= 300 &&
+ response.statusCode < 400 &&
+ response.headers.location
+ ) {
+ // Handle redirect
+ const redirectURL = response.headers.location
+ console.log(`Redirecting to ${redirectURL}`)
+ download(redirectURL, dest).then(resolve, reject) // Recursive call
+ return
+ } else if (response.statusCode !== 200) {
+ reject(`Failed to get '${url}' (${response.statusCode})`)
+ return
+ }
+ response.pipe(file)
+ file.on('finish', () => {
+ file.close(resolve)
+ })
+ })
+ .on('error', (err) => {
+ fs.unlink(dest, () => reject(err.message))
+ })
+ })
+}
+
+async function main() {
+ console.log('Starting main function')
+ const platform = os.platform() // 'darwin', 'linux', 'win32'
+ const arch = os.arch() // 'x64', 'arm64', etc.
+
+ if (arch != 'x64') return
+
+ let filename
+ if (platform == 'linux')
+ filename = 'libvulkan.so'
+ else if (platform == 'win32')
+ filename = 'vulkan-1.dll'
+ else
+ return
+
+ const url = `https://catalog.jan.ai/${filename}`
+
+ const libDir = 'src-tauri/resources/lib'
+ const tempDir = 'scripts/dist'
+
+ try {
+ mkdirSync('scripts/dist')
+ } catch (err) {
+ // Expect EEXIST error if the directory already exists
+ }
+
+ console.log(`Downloading libvulkan...`)
+ const savePath = path.join(tempDir, filename)
+ if (!fs.existsSync(savePath)) {
+ await download(url, savePath)
+ }
+
+ // copy to tauri resources
+ try {
+ copySync(savePath, libDir)
+ } catch (err) {
+ // Expect EEXIST error
+ }
+
+ console.log('Downloads completed.')
+}
+
+main().catch((err) => {
+ console.error('Error:', err)
+ process.exit(1)
+})