mirror of
https://github.com/wisdgod/cursor-api.git
synced 2025-10-09 00:20:06 +08:00
0.3.6: WIP
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
# 参数处理
|
||||
param(
|
||||
[switch]$Static,
|
||||
[switch]$Help,
|
||||
[ValidateSet("x86_64", "aarch64", "i686")]
|
||||
[string]$Architecture
|
||||
)
|
||||
|
||||
# 设置错误时停止执行
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# 颜色输出函数
|
||||
function Write-Info { param($Message) Write-Host "[INFO] $Message" -ForegroundColor Blue }
|
||||
function Write-Warn { param($Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow }
|
||||
function Write-Error { param($Message) Write-Host "[ERROR] $Message" -ForegroundColor Red; exit 1 }
|
||||
|
||||
# 检查必要的工具
|
||||
function Check-Requirements {
|
||||
$tools = @("cargo", "protoc", "npm", "node")
|
||||
$missing = @()
|
||||
|
||||
foreach ($tool in $tools) {
|
||||
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
|
||||
$missing += $tool
|
||||
}
|
||||
}
|
||||
|
||||
if ($missing.Count -gt 0) {
|
||||
Write-Error "缺少必要工具: $($missing -join ', ')"
|
||||
}
|
||||
}
|
||||
|
||||
# 帮助信息
|
||||
function Show-Help {
|
||||
Write-Host @"
|
||||
用法: $(Split-Path $MyInvocation.ScriptName -Leaf) [选项]
|
||||
|
||||
选项:
|
||||
-Static 使用静态链接(默认动态链接)
|
||||
-Help 显示此帮助信息
|
||||
|
||||
不带参数时使用默认配置构建
|
||||
"@
|
||||
}
|
||||
|
||||
# 构建函数
|
||||
function Build-Target {
|
||||
param (
|
||||
[string]$Target,
|
||||
[string]$RustFlags
|
||||
)
|
||||
|
||||
Write-Info "正在构建 $Target..."
|
||||
|
||||
# 设置环境变量
|
||||
$env:RUSTFLAGS = $RustFlags
|
||||
|
||||
# 构建
|
||||
if ($Target -ne (rustc -Vv | Select-String "host: (.*)" | ForEach-Object { $_.Matches.Groups[1].Value })) {
|
||||
cargo build --target $Target --release
|
||||
} else {
|
||||
cargo build --release
|
||||
}
|
||||
|
||||
# 移动编译产物到 release 目录
|
||||
$binaryName = "cursor-api"
|
||||
if ($Static) {
|
||||
$binaryName += "-static"
|
||||
}
|
||||
|
||||
$binaryPath = if ($Target -eq (rustc -Vv | Select-String "host: (.*)" | ForEach-Object { $_.Matches.Groups[1].Value })) {
|
||||
"target/release/cursor-api.exe"
|
||||
} else {
|
||||
"target/$Target/release/cursor-api.exe"
|
||||
}
|
||||
|
||||
if (Test-Path $binaryPath) {
|
||||
Copy-Item $binaryPath "release/$binaryName-$Target.exe"
|
||||
Write-Info "完成构建 $Target"
|
||||
} else {
|
||||
Write-Warn "构建产物未找到: $Target"
|
||||
Write-Warn "查找路径: $binaryPath"
|
||||
Write-Warn "当前目录内容:"
|
||||
Get-ChildItem -Recurse target/
|
||||
return $false
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
if ($Help) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 检查依赖
|
||||
Check-Requirements
|
||||
|
||||
# 创建 release 目录
|
||||
New-Item -ItemType Directory -Force -Path release | Out-Null
|
||||
|
||||
# 设置静态链接标志
|
||||
$rustFlags = ""
|
||||
if ($Static) {
|
||||
$rustFlags = "-C target-feature=+crt-static"
|
||||
}
|
||||
|
||||
# 获取目标架构
|
||||
$arch = if ($Architecture) {
|
||||
$Architecture
|
||||
} else {
|
||||
switch ($env:PROCESSOR_ARCHITECTURE) {
|
||||
"AMD64" { "x86_64" }
|
||||
"ARM64" { "aarch64" }
|
||||
"X86" { "i686" }
|
||||
default { Write-Error "不支持的架构: $env:PROCESSOR_ARCHITECTURE" }
|
||||
}
|
||||
}
|
||||
$target = "$arch-pc-windows-msvc"
|
||||
|
||||
Write-Info "开始构建..."
|
||||
if (-not (Build-Target -Target $target -RustFlags $rustFlags)) {
|
||||
Write-Error "构建失败"
|
||||
}
|
||||
|
||||
Write-Info "构建完成!"
|
53
scripts/package-lock.json
generated
53
scripts/package-lock.json
generated
@@ -19,17 +19,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/gen-mapping": {
|
||||
"version": "0.3.8",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz",
|
||||
"integrity": "sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA==",
|
||||
"version": "0.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.12.tgz",
|
||||
"integrity": "sha512-OuLGC46TjB5BbN1dH8JULVVZY4WTdkF7tV9Ys6wLL1rubZnCMstOhNHueU5bLCrnRuDhKPDM4g6sw4Bel5Gzqg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/set-array": "^1.2.1",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.10",
|
||||
"@jridgewell/sourcemap-codec": "^1.5.0",
|
||||
"@jridgewell/trace-mapping": "^0.3.24"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/resolve-uri": {
|
||||
@@ -41,19 +37,10 @@
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/set-array": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz",
|
||||
"integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/source-map": {
|
||||
"version": "0.3.6",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz",
|
||||
"integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==",
|
||||
"version": "0.3.10",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.10.tgz",
|
||||
"integrity": "sha512-0pPkgz9dY+bijgistcTTJ5mR+ocqRXLuhXHYdzoMmmoJ2C9S46RCm2GMUbatPEUK9Yjy26IrAy8D/M00lLkv+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/gen-mapping": "^0.3.5",
|
||||
@@ -61,15 +48,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/sourcemap-codec": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
|
||||
"integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==",
|
||||
"version": "1.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.4.tgz",
|
||||
"integrity": "sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@jridgewell/trace-mapping": {
|
||||
"version": "0.3.25",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz",
|
||||
"integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==",
|
||||
"version": "0.3.29",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.29.tgz",
|
||||
"integrity": "sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.1.0",
|
||||
@@ -102,9 +89,9 @@
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.14.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
|
||||
"integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
|
||||
"version": "8.15.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
@@ -318,13 +305,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.37.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz",
|
||||
"integrity": "sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA==",
|
||||
"version": "5.43.1",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.43.1.tgz",
|
||||
"integrity": "sha512-+6erLbBm0+LROX2sPXlUYx/ux5PyE9K/a92Wrt6oA+WDAoFTdpHE5tCYCI5PNzq2y8df4rA+QgHLJuR4jNymsg==",
|
||||
"license": "BSD-2-Clause",
|
||||
"dependencies": {
|
||||
"@jridgewell/source-map": "^0.3.3",
|
||||
"acorn": "^8.8.2",
|
||||
"acorn": "^8.14.0",
|
||||
"commander": "^2.20.0",
|
||||
"source-map-support": "~0.5.20"
|
||||
},
|
||||
|
@@ -1,179 +0,0 @@
|
||||
# <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>ʱִֹͣ<D6B9><D6B4>
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProgressPreference = "SilentlyContinue" # <20>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
|
||||
# <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
function Write-Info { param($Message) Write-Host "[INFO] $Message" -ForegroundColor Blue }
|
||||
function Write-Warn { param($Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow }
|
||||
function Write-Success { param($Message) Write-Host "[SUCCESS] $Message" -ForegroundColor Green }
|
||||
function Write-Error { param($Message) Write-Host "[ERROR] $Message" -ForegroundColor Red; exit 1 }
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԱȨ<D4B1><C8A8>
|
||||
function Test-Administrator {
|
||||
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = New-Object Security.Principal.WindowsPrincipal $user
|
||||
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
}
|
||||
|
||||
if (-not (Test-Administrator)) {
|
||||
Write-Error "<EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д˽ű<EFBFBD>"
|
||||
}
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
function Show-Help {
|
||||
Write-Host @"
|
||||
<EFBFBD>÷<EFBFBD>: $(Split-Path $MyInvocation.ScriptName -Leaf) [ѡ<EFBFBD><EFBFBD>]
|
||||
|
||||
ѡ<EFBFBD><EFBFBD>:
|
||||
-NoVS <EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ Visual Studio Build Tools
|
||||
-NoRust <EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ Rust
|
||||
-NoNode <EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ Node.js
|
||||
-Help <EFBFBD><EFBFBD>ʾ<EFBFBD>˰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
|
||||
ʾ<EFBFBD><EFBFBD>:
|
||||
.\setup.ps1
|
||||
.\setup.ps1 -NoVS
|
||||
.\setup.ps1 -NoRust -NoNode
|
||||
"@
|
||||
}
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
param(
|
||||
[switch]$NoVS,
|
||||
[switch]$NoRust,
|
||||
[switch]$NoNode,
|
||||
[switch]$Help
|
||||
)
|
||||
|
||||
if ($Help) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# <20><><EFBFBD>鲢<EFBFBD><E9B2A2>װ Chocolatey
|
||||
function Install-Chocolatey {
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Chocolatey..."
|
||||
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Chocolatey..."
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||
try {
|
||||
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
|
||||
}
|
||||
catch {
|
||||
Write-Error "<EFBFBD><EFBFBD>װ Chocolatey ʧ<><CAA7>: $_"
|
||||
}
|
||||
# ˢ<>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
}
|
||||
}
|
||||
|
||||
# <20><>װ Visual Studio Build Tools
|
||||
function Install-VSBuildTools {
|
||||
if ($NoVS) {
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Visual Studio Build Tools <20><>װ"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Visual Studio Build Tools..."
|
||||
$vsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (-not (Test-Path $vsPath)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Visual Studio Build Tools..."
|
||||
try {
|
||||
# <20><><EFBFBD>ذ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD>
|
||||
$vsInstallerUrl = "https://aka.ms/vs/17/release/vs_BuildTools.exe"
|
||||
$vsInstallerPath = "$env:TEMP\vs_BuildTools.exe"
|
||||
Invoke-WebRequest -Uri $vsInstallerUrl -OutFile $vsInstallerPath
|
||||
|
||||
# <20><>װ
|
||||
$process = Start-Process -FilePath $vsInstallerPath -ArgumentList `
|
||||
"--quiet", "--wait", "--norestart", "--nocache", `
|
||||
"--installPath", "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools", `
|
||||
"--add", "Microsoft.VisualStudio.Workload.VCTools" `
|
||||
-NoNewWindow -Wait -PassThru
|
||||
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Write-Error "Visual Studio Build Tools <20><>װʧ<D7B0><CAA7>"
|
||||
}
|
||||
|
||||
Remove-Item $vsInstallerPath -Force
|
||||
}
|
||||
catch {
|
||||
Write-Error "<EFBFBD><EFBFBD>װ Visual Studio Build Tools ʧ<><CAA7>: $_"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Info "Visual Studio Build Tools <20>Ѱ<EFBFBD>װ"
|
||||
}
|
||||
}
|
||||
|
||||
# <20><>װ Rust
|
||||
function Install-Rust {
|
||||
if ($NoRust) {
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Rust <20><>װ"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Rust..."
|
||||
if (-not (Get-Command rustc -ErrorAction SilentlyContinue)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Rust..."
|
||||
try {
|
||||
$rustupInit = "$env:TEMP\rustup-init.exe"
|
||||
Invoke-WebRequest -Uri "https://win.rustup.rs" -OutFile $rustupInit
|
||||
Start-Process -FilePath $rustupInit -ArgumentList "-y" -Wait
|
||||
Remove-Item $rustupInit -Force
|
||||
|
||||
# ˢ<>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
}
|
||||
catch {
|
||||
Write-Error "<EFBFBD><EFBFBD>װ Rust ʧ<><CAA7>: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ƽ̨
|
||||
Write-Info "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Rust Ŀ<><C4BF>ƽ̨..."
|
||||
$arch = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "i686" }
|
||||
rustup target add "$arch-pc-windows-msvc"
|
||||
}
|
||||
|
||||
# <20><>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
function Install-Tools {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>..."
|
||||
|
||||
# <20><>װ protoc
|
||||
if (-not (Get-Command protoc -ErrorAction SilentlyContinue)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Protocol Buffers..."
|
||||
choco install -y protoc
|
||||
}
|
||||
|
||||
# <20><>װ Git
|
||||
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Git..."
|
||||
choco install -y git
|
||||
}
|
||||
|
||||
# <20><>װ Node.js
|
||||
if (-not $NoNode -and -not (Get-Command node -ErrorAction SilentlyContinue)) {
|
||||
Write-Info "<EFBFBD><EFBFBD>װ Node.js..."
|
||||
choco install -y nodejs
|
||||
}
|
||||
|
||||
# ˢ<>»<EFBFBD><C2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
}
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
try {
|
||||
Write-Info "<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>..."
|
||||
|
||||
Install-Chocolatey
|
||||
Install-VSBuildTools
|
||||
Install-Rust
|
||||
Install-Tools
|
||||
|
||||
Write-Success "<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>"
|
||||
}
|
||||
catch {
|
||||
Write-Error "<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>: $_"
|
||||
}
|
Reference in New Issue
Block a user