Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-rust-binding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- host: macos-latest
target: x86_64-apple-darwin
build: |
pnpm build:binding:release
pnpm build:binding:release --target x86_64-apple-darwin
strip -x crates/native_binding/*.node
- host: windows-latest
build: pnpm build:binding:release
target: x86_64-pc-windows-msvc
build: pnpm build:binding:release --target x86_64-pc-windows-msvc
- host: ubuntu-22.04
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
Expand All @@ -35,7 +35,7 @@ jobs:
- host: ubuntu-22.04
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: set -e && pnpm build:binding:release && strip crates/native_binding/*.node
build: set -e && pnpm build:binding:release --target x86_64-unknown-linux-musl && strip crates/native_binding/*.node
- host: ubuntu-22.04
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ jobs:
ls -R ./packages/taro-platform-harmony-cpp/static
shell: bash

# Verify bindings
- name: Verify Bindings
run: node scripts/verify-bindings.js
shell: bash

# Git stash
- name: Drop current changes
if: env.MOCK_PUBLISH != 'true'
Expand Down
123 changes: 123 additions & 0 deletions scripts/verify-bindings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const fs = require('fs')
const path = require('path')

const BINDINGS = [
{
name: '@tarojs/binding-darwin-x64',
path: 'npm/darwin-x64',
nodeFile: 'taro.darwin-x64.node',
minSize: 1024 * 1024
},
{
name: '@tarojs/binding-darwin-arm64',
path: 'npm/darwin-arm64',
nodeFile: 'taro.darwin-arm64.node',
minSize: 1024 * 1024
},
{
name: '@tarojs/binding-linux-x64-gnu',
path: 'npm/linux-x64-gnu',
nodeFile: 'taro.linux-x64-gnu.node',
minSize: 1024 * 1024
},
{
name: '@tarojs/binding-linux-x64-musl',
path: 'npm/linux-x64-musl',
nodeFile: 'taro.linux-x64-musl.node',
minSize: 1024 * 1024
},
{
name: '@tarojs/binding-linux-arm64-gnu',
path: 'npm/linux-arm64-gnu',
nodeFile: 'taro.linux-arm64-gnu.node',
minSize: 1024 * 1024
},
{
name: '@tarojs/binding-win32-x64-msvc',
path: 'npm/win32-x64-msvc',
nodeFile: 'taro.win32-x64-msvc.node',
minSize: 1024 * 1024
}
]

const rootDir = path.resolve(__dirname, '..')
let hasErrors = false
const errors = []
const warnings = []

console.log('🔍 验证 Binding 包完整性...\n')

for (const binding of BINDINGS) {
const bindingDir = path.join(rootDir, binding.path)
const nodeFilePath = path.join(bindingDir, binding.nodeFile)
const packageJsonPath = path.join(bindingDir, 'package.json')

if (!fs.existsSync(bindingDir)) {
errors.push(`❌ ${binding.name}: 目录不存在 (${binding.path})`)
hasErrors = true
continue
}

if (!fs.existsSync(packageJsonPath)) {
errors.push(`❌ ${binding.name}: package.json 不存在`)
hasErrors = true
continue
}

if (!fs.existsSync(nodeFilePath)) {
errors.push(`❌ ${binding.name}: 缺少 ${binding.nodeFile} 文件`)
hasErrors = true
continue
}

const stats = fs.statSync(nodeFilePath)
const fileSizeMB = (stats.size / (1024 * 1024)).toFixed(2)

if (stats.size < binding.minSize) {
errors.push(
`❌ ${binding.name}: ${binding.nodeFile} 文件太小 (${fileSizeMB}MB),可能构建失败`
)
hasErrors = true
continue
}

try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
if (packageJson.main !== binding.nodeFile) {
warnings.push(
`⚠️ ${binding.name}: package.json 的 main 字段 (${packageJson.main}) 与预期不符 (${binding.nodeFile})`
)
}
} catch (error) {
errors.push(`❌ ${binding.name}: 无法解析 package.json - ${error.message}`)
hasErrors = true
continue
}

console.log(`✅ ${binding.name}: ${binding.nodeFile} (${fileSizeMB}MB)`)
}

console.log('')

if (warnings.length > 0) {
console.log('⚠️ 警告:\n')
warnings.forEach(warning => console.log(warning))
console.log('')
}

if (hasErrors) {
console.log('❌ 验证失败:\n')
errors.forEach(error => console.log(error))
console.log('\n💡 提示:')
console.log(' 1. 确保已运行构建命令: pnpm build:binding:release')
console.log(' 2. 确保 CI 构建产物已正确下载')
console.log(' 3. 确保已运行 artifacts 命令: pnpm artifacts')
console.log('')
process.exit(1)
}

console.log('✨ 所有 Binding 包验证通过!\n')
process.exit(0)