download lib at build time
This commit is contained in:
parent
48d1164858
commit
7dbc2c3af2
5
Makefile
5
Makefile
@ -29,7 +29,7 @@ endif
|
|||||||
|
|
||||||
dev: install-and-build
|
dev: install-and-build
|
||||||
yarn download:bin
|
yarn download:bin
|
||||||
yarn copy:lib
|
yarn download:lib
|
||||||
yarn dev
|
yarn dev
|
||||||
|
|
||||||
# Linting
|
# Linting
|
||||||
@ -47,11 +47,12 @@ build-and-publish: install-and-build
|
|||||||
|
|
||||||
# Build
|
# Build
|
||||||
build: install-and-build
|
build: install-and-build
|
||||||
|
yarn download:lib
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
# Deprecated soon
|
# Deprecated soon
|
||||||
build-tauri: install-and-build
|
build-tauri: install-and-build
|
||||||
yarn copy:lib
|
yarn download:lib
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -22,10 +22,7 @@
|
|||||||
"dev:web": "yarn workspace @janhq/web-app dev",
|
"dev:web": "yarn workspace @janhq/web-app dev",
|
||||||
"dev:tauri": "CLEAN=true yarn build:icon && yarn copy:assets:tauri && tauri 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:assets:tauri": "cpx \"pre-install/*.tgz\" \"src-tauri/resources/pre-install/\"",
|
||||||
"copy:lib": "run-script-os",
|
"download:lib": "node ./scripts/download-lib.mjs",
|
||||||
"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:bin": "node ./scripts/download-bin.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: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",
|
"build:tauri:darwin": "yarn build:icon && yarn copy:assets:tauri && yarn tauri build --target universal-apple-darwin",
|
||||||
|
|||||||
86
scripts/download-lib.mjs
Normal file
86
scripts/download-lib.mjs
Normal file
@ -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)
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user