Skip to content

Commit 40cfb33

Browse files
authored
chore: pull binaries windows, linux (#4963)
1 parent d9e8615 commit 40cfb33

File tree

2 files changed

+75
-20
lines changed

2 files changed

+75
-20
lines changed

scripts/download-bin.js

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
console.log('Script is running')
2+
// scripts/download.js
13
import https from 'https'
2-
import fs, { existsSync, mkdirSync } from 'fs'
3-
import os, { platform } from 'os'
4+
import fs, { copyFile, mkdirSync } from 'fs'
5+
import os from 'os'
46
import path from 'path'
57
import unzipper from 'unzipper'
68
import tar from 'tar'
@@ -66,11 +68,11 @@ function getPlatformArch() {
6668
uvPlatform =
6769
arch === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin'
6870
} else if (platform === 'linux') {
69-
bunPlatform = arch === 'arm64' ? 'linux-aarch64' : 'linux-x86_64'
70-
uvPlatform = 'unknown-x86_64-linux-aarch64-gnu' // Add aarch64 support if needed
71+
bunPlatform = arch === 'arm64' ? 'linux-aarch64' : 'linux-x64'
72+
uvPlatform = arch === 'arm64' ? 'aarch64-unknown-linux-gnu' : 'x86_64-unknown-linux-gnu'
7173
} else if (platform === 'win32') {
72-
bunPlatform = 'windows-x86_64' // Bun has limited Windows support
73-
uvPlatform = 'windows'
74+
bunPlatform = 'windows-x64' // Bun has limited Windows support
75+
uvPlatform = 'x86_64-pc-windows-msvc'
7476
} else {
7577
throw new Error(`Unsupported platform: ${platform}`)
7678
}
@@ -80,50 +82,104 @@ function getPlatformArch() {
8082

8183
async function main() {
8284
console.log('Starting main function')
85+
const platform = os.platform()
8386
const { bunPlatform, uvPlatform } = getPlatformArch()
8487
console.log(`bunPlatform: ${bunPlatform}, uvPlatform: ${uvPlatform}`)
8588

8689
const binDir = 'src-tauri/resources/bin'
8790
const tempBinDir = 'scripts/dist'
8891
const bunPath = `${tempBinDir}/bun-${bunPlatform}.zip`
89-
const uvPath = `${tempBinDir}/uv-${uvPlatform}.tar.gz`
90-
if (!existsSync(tempBinDir)) {
91-
mkdirSync(tempBinDir)
92+
let uvPath = `${tempBinDir}/uv-${uvPlatform}.tar.gz`
93+
if (platform === 'win32') {
94+
uvPath = `${tempBinDir}/uv-${uvPlatform}.zip`
95+
}
96+
try {
97+
mkdirSync('scripts/dist')
98+
} catch (err) {
99+
// Expect EEXIST error if the directory already exists
92100
}
93101

94102
// Adjust these URLs based on latest releases
95103
const bunVersion = '1.2.10' // Example Bun version
96104
const bunUrl = `https://github.com/oven-sh/bun/releases/download/bun-v${bunVersion}/bun-${bunPlatform}.zip`
97105

98106
const uvVersion = '0.6.17' // Example UV version
99-
const uvUrl = `https://github.com/astral-sh/uv/releases/download/${uvVersion}/uv-${uvPlatform}.tar.gz`
107+
let uvUrl = `https://github.com/astral-sh/uv/releases/download/${uvVersion}/uv-${uvPlatform}.tar.gz`
108+
if (platform === 'win32') {
109+
uvUrl = `https://github.com/astral-sh/uv/releases/download/${uvVersion}/uv-${uvPlatform}.zip`
110+
}
100111

101112
console.log(`Downloading Bun for ${bunPlatform}...`)
102113
await download(bunUrl, path.join(tempBinDir, `bun-${bunPlatform}.zip`))
103114
await decompress(bunPath, tempBinDir)
104-
if (platform() !== 'win32') {
115+
try {
105116
copySync(
106117
path.join(tempBinDir, `bun-${bunPlatform}`, 'bun'),
107118
path.join(binDir)
108119
)
109-
} else {
120+
if (platform === 'linux') {
121+
copyFile(path.join(binDir, 'bun'), path.join(binDir, 'bun-x86_64-unknown-linux-gnu'), (err) => {
122+
if (err) {
123+
console.log("Error Found:", err);
124+
}
125+
})
126+
}
127+
} catch (err) {
128+
// Expect EEXIST error
129+
}
130+
try {
110131
copySync(
111132
path.join(tempBinDir, `bun-${bunPlatform}`, 'bun.exe'),
112133
path.join(binDir)
113134
)
135+
if (platform === 'win32') {
136+
copyFile(path.join(binDir, 'bun.exe'), path.join(binDir, 'bun-x86_64-pc-windows-msvc.exe'), (err) => {
137+
if (err) {
138+
console.log("Error Found:", err);
139+
}
140+
})
141+
}
142+
} catch (err) {
143+
// Expect EEXIST error
114144
}
115145
console.log('Bun downloaded.')
116146

117147
console.log(`Downloading UV for ${uvPlatform}...`)
118-
await download(uvUrl, path.join(tempBinDir, `uv-${uvPlatform}.tar.gz`))
119-
await decompress(uvPath, tempBinDir)
120-
if (platform() !== 'win32') {
121-
copySync(path.join(tempBinDir, `uv-${uvPlatform}`, 'uv'), path.join(binDir))
148+
if (platform === 'win32') {
149+
await download(uvUrl, path.join(tempBinDir, `uv-${uvPlatform}.zip`))
122150
} else {
151+
await download(uvUrl, path.join(tempBinDir, `uv-${uvPlatform}.tar.gz`))
152+
}
153+
await decompress(uvPath, tempBinDir)
154+
try {
123155
copySync(
124-
path.join(tempBinDir, `uv-${uvPlatform}`, 'uv.exe'),
156+
path.join(tempBinDir, `uv-${uvPlatform}`, 'uv'),
125157
path.join(binDir)
126158
)
159+
if (platform === 'linux') {
160+
copyFile(path.join(binDir, 'uv'), path.join(binDir, 'uv-x86_64-unknown-linux-gnu'), (err) => {
161+
if (err) {
162+
console.log("Error Found:", err);
163+
}
164+
})
165+
}
166+
} catch (err) {
167+
// Expect EEXIST error
168+
}
169+
try {
170+
copySync(
171+
path.join(tempBinDir, 'uv.exe'),
172+
path.join(binDir)
173+
)
174+
if (platform === 'win32') {
175+
copyFile(path.join(binDir, 'uv.exe'), path.join(binDir, 'uv-x86_64-pc-windows-msvc.exe'), (err) => {
176+
if (err) {
177+
console.log("Error Found:", err);
178+
}
179+
})
180+
}
181+
} catch (err) {
182+
// Expect EEXIST error
127183
}
128184
console.log('UV downloaded.')
129185

src-tauri/tauri.conf.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@
6767
"resources": [
6868
"binaries/engines/**/*",
6969
"resources/themes/**/*",
70-
"resources/pre-install/**/*",
71-
"resources/bin/**/*"
70+
"resources/pre-install/**/*"
7271
],
73-
"externalBin": ["binaries/cortex-server"]
72+
"externalBin": ["binaries/cortex-server", "resources/bin/bun", "resources/bin/uv"]
7473
}
7574
}

0 commit comments

Comments
 (0)