fix(build): bundle service tools from the resolved IPC source

This commit is contained in:
Tunglies
2026-12-04 15:38:22 +08:00
parent 6f81fb91b3
commit 72c3653a8a
5 changed files with 65 additions and 49 deletions
+8 -8
View File
@@ -265,14 +265,6 @@ jobs:
node-version: '26.14.0'
cache: 'pnpm'
- name: Pnpm install and check
run: |
pnpm i
pnpm run prebuild ${{ matrix.target }}
- name: Release ${{ env.TAG_CHANNEL }} Version
run: pnpm release-version autobuild-latest
- name: 'Setup for linux'
run: |-
sudo ls -lR /etc/apt/
@@ -317,6 +309,14 @@ jobs:
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf
- name: Pnpm install and check
run: |
pnpm i
pnpm run prebuild ${{ matrix.target }}
- name: Release ${{ env.TAG_CHANNEL }} Version
run: pnpm release-version autobuild-latest
- name: Tauri Build for Linux
run: |
export PKG_CONFIG_ALLOW_CROSS=1
+8 -8
View File
@@ -107,6 +107,14 @@ jobs:
node-version: '26.14.0'
cache: 'pnpm'
- name: Add Rust Target
if: github.event.inputs[matrix.input] == 'true'
run: |
# Ensure cross target is installed for the pinned toolchain; fallback without explicit toolchain if needed
rustup target add ${{ matrix.target }} --toolchain 1.100.1 || rustup target add ${{ matrix.target }}
rustup target list --installed
echo "Rust target ${{ matrix.target }} installed."
- name: Pnpm install and check
if: github.event.inputs[matrix.input] == 'true'
run: |
@@ -117,14 +125,6 @@ jobs:
if: github.event.inputs[matrix.input] == 'true'
run: pnpm release-version ${{ env.TAG_NAME }}
- name: Add Rust Target
if: github.event.inputs[matrix.input] == 'true'
run: |
# Ensure cross target is installed for the pinned toolchain; fallback without explicit toolchain if needed
rustup target add ${{ matrix.target }} --toolchain 1.100.1 || rustup target add ${{ matrix.target }}
rustup target list --installed
echo "Rust target ${{ matrix.target }} installed."
- name: Tauri build
if: github.event.inputs[matrix.input] == 'true'
uses: tauri-apps/tauri-action@v1
+5 -5
View File
@@ -333,11 +333,6 @@ jobs:
node-version: '26.14.0'
cache: 'pnpm'
- name: Pnpm install and check
run: |
pnpm i
pnpm run prebuild ${{ matrix.target }}
- name: 'Setup for linux'
run: |-
sudo ls -lR /etc/apt/
@@ -382,6 +377,11 @@ jobs:
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf
- name: Pnpm install and check
run: |
pnpm i
pnpm run prebuild ${{ matrix.target }}
- name: Build for Linux
run: |
export PKG_CONFIG_ALLOW_CROSS=1
+20 -17
View File
@@ -9,7 +9,7 @@ import AdmZip from 'adm-zip'
import { HttpsProxyAgent } from 'https-proxy-agent'
import { extract } from 'tar'
import { resolveServiceRelease } from './service-release.mjs'
import { resolveServiceBundle as serviceBundleFromMetadata } from './service-release.mjs'
import { log_debug, log_error, log_info, log_success } from './utils.mjs'
/** Prepares platform resources, caching versions and unchanged files unless `--force` is used. */
@@ -581,23 +581,30 @@ async function resolveServiceBundle() {
}
})
const cargoManifest = await fsp.readFile(
path.join(cwd, 'src-tauri', 'Cargo.toml'),
'utf8',
const metadata = JSON.parse(
execFileSync(
'cargo',
[
'metadata',
'--locked',
'--format-version',
'1',
'--filter-platform',
SIDECAR_HOST,
],
{ cwd, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 },
),
)
const serviceDependency = cargoManifest
.split(/\r?\n/)
.find((line) => line.trimStart().startsWith('clash_verge_service_ipc ='))
const sourcePath = serviceDependency?.match(/\bpath\s*=\s*"([^"]+)"/)?.[1]
if (sourcePath) {
const manifest = path.resolve(cwd, 'src-tauri', sourcePath, 'Cargo.toml')
const bundle = serviceBundleFromMetadata(metadata, SIDECAR_HOST, platform)
if (bundle.manifest) {
const targetDirectory = path.join(cwd, 'target', 'bundled-service')
execFileSync(
'cargo',
[
'build',
'--locked',
'--manifest-path',
manifest,
bundle.manifest,
'--target-dir',
targetDirectory,
'--target',
@@ -605,7 +612,7 @@ async function resolveServiceBundle() {
'--release',
'--features',
'standalone,client',
'--bins',
...SERVICE_BINARIES.flatMap((name) => ['--bin', name]),
],
{ stdio: 'inherit' },
)
@@ -620,11 +627,7 @@ async function resolveServiceBundle() {
}
return
}
const { archiveFile, downloadURL } = resolveServiceRelease(
cargoManifest,
SIDECAR_HOST,
platform,
)
const { archiveFile, downloadURL } = bundle
const tempDir = path.join(TEMP_DIR, 'clash-verge-service-ipc')
const tempArchive = path.join(tempDir, archiveFile)
+24 -11
View File
@@ -1,22 +1,35 @@
const SERVICE_URL_PREFIX =
'https://github.com/clash-verge-rev/clash-verge-service-ipc/releases/download'
export function resolveServiceRelease(cargoManifest, host, platform) {
const dependency = cargoManifest
.split(/\r?\n/)
.find((line) => line.trimStart().startsWith('clash_verge_service_ipc ='))
const packageVersion = dependency?.match(/\bversion\s*=\s*"([^"]+)"/)?.[1]
if (!packageVersion) {
throw new Error(
'clash_verge_service_ipc dependency must declare an inline version',
)
export function resolveServiceBundle(metadata, host, platform) {
const app = metadata.packages.find(
(pkg) =>
pkg.name === 'clash-verge' && metadata.workspace_members.includes(pkg.id),
)
const dependency = app?.dependencies.find(
(dep) => dep.name === 'clash_verge_service_ipc',
)
const edge = metadata.resolve.nodes
.find((node) => node.id === app?.id)
?.deps.find((dep) => dep.name === 'clash_verge_service_ipc')
const service = metadata.packages.find((pkg) => pkg.id === edge?.pkg)
if (!service || !dependency) {
throw new Error('Cargo did not resolve the desktop IPC client dependency')
}
if (!service.source || new URL(service.source).searchParams.has('rev')) {
return { manifest: service.manifest_path }
}
const version = `v${packageVersion}`
const declared = dependency.req.replace(/^[=^]/, '')
if (declared !== service.version) {
throw new Error(
`Service release version ${declared} differs from the resolved IPC client ${service.version}`,
)
}
const version = `v${declared}`
const archiveExt = platform === 'win32' ? 'zip' : 'tar.gz'
const archiveFile = `clash-verge-service-ipc-${version}-${host}.${archiveExt}`
return {
version,
archiveFile,
downloadURL: `${SERVICE_URL_PREFIX}/${version}/${archiveFile}`,
}