✨ feat(native-planning): 更新 Rust ICSP 原生库及构建脚本
* 将 Rust ICSP 原生库名称更改为 `flyshot_planning`,更新相关引用。 * 修改构建脚本以支持新的库名称,并确保库文件复制到正确的目录。 * 添加对 Rust ICSP 原生库的依赖检查,确保发布时包含必要的库文件。 * 更新测试项目以加载新的原生库,确保兼容性和功能完整性。
This commit is contained in:
@@ -1,94 +1,76 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
构建 Rust ICSP 原生规划库并复制到 src/Libs 与可选目标目录。
|
||||
|
||||
.DESCRIPTION
|
||||
在 Windows x64 上通过 cargo release 构建 flyshot_planning,默认写入
|
||||
src/Libs/flyshot_planning.dll;Linux x64 写入 src/Libs/libflyshot_planning.so。
|
||||
可通过 -DestinationDirectories 额外复制到测试或发布输出目录。
|
||||
|
||||
.PARAMETER Configuration
|
||||
传递给 dotnet 相关路径的构建配置名,默认 Release。
|
||||
|
||||
.PARAMETER DestinationDirectories
|
||||
除 src/Libs 外需要覆盖复制的额外目标目录列表。
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[ValidateSet("Debug", "Release")]
|
||||
[string]$Configuration = "Release",
|
||||
[ValidateSet('Debug', 'Release')]
|
||||
[string]$Configuration = 'Release',
|
||||
|
||||
[string[]]$DestinationDirectories = @()
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
# 从脚本位置定位仓库根目录,确保从任意工作目录调用都得到一致结果。
|
||||
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||||
$manifestPath = Join-Path $repositoryRoot "native/flyshot-native-planning/Cargo.toml"
|
||||
$cargoExecutable = if ($IsWindows) { "cargo.exe" } else { "cargo" }
|
||||
$cargoPath = Join-Path $HOME ".cargo/bin/$cargoExecutable"
|
||||
if (-not (Test-Path -LiteralPath $cargoPath)) {
|
||||
throw "未找到 Rust Cargo:$cargoPath。请先通过 rustup 安装 stable-x86_64-pc-windows-msvc。"
|
||||
$repositoryRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
$cargoManifest = Join-Path $repositoryRoot 'native\flyshot-native-planning\Cargo.toml'
|
||||
$libsDirectory = Join-Path $repositoryRoot 'src\Libs'
|
||||
$cargoProfile = if ($Configuration -eq 'Debug') { 'debug' } else { 'release' }
|
||||
$targetDirectory = Join-Path $repositoryRoot "native\flyshot-native-planning\target\$cargoProfile"
|
||||
|
||||
if ($IsLinux -or (-not $IsWindows -and -not $IsMacOS))
|
||||
{
|
||||
$artifactFileName = 'libflyshot_planning.so'
|
||||
}
|
||||
else
|
||||
{
|
||||
$artifactFileName = 'flyshot_planning.dll'
|
||||
}
|
||||
|
||||
$cargoArguments = @("build", "--manifest-path", $manifestPath)
|
||||
if ($Configuration -eq "Release") {
|
||||
$cargoArguments += "--release"
|
||||
$builtArtifactPath = Join-Path $targetDirectory $artifactFileName
|
||||
$libsArtifactPath = Join-Path $libsDirectory $artifactFileName
|
||||
|
||||
Write-Host "正在构建 Rust 原生规划库 ($Configuration) ..."
|
||||
& cargo build --manifest-path $cargoManifest --$Configuration
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
throw "cargo build 失败,退出码:$LASTEXITCODE"
|
||||
}
|
||||
|
||||
if ($IsWindows) {
|
||||
# Windows MSVC 目标必须在 VS C++ 开发者环境中运行,避免 PATH 中其他 link.exe 抢占。
|
||||
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
if (-not (Test-Path -LiteralPath $vswherePath)) {
|
||||
throw "未找到 vswhere.exe,无法定位 Visual Studio C++ Build Tools。"
|
||||
if (-not (Test-Path -LiteralPath $builtArtifactPath -PathType Leaf))
|
||||
{
|
||||
throw "未找到构建产物:$builtArtifactPath"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $libsDirectory -Force | Out-Null
|
||||
Copy-Item -LiteralPath $builtArtifactPath -Destination $libsArtifactPath -Force
|
||||
Write-Host "已复制到:$libsArtifactPath"
|
||||
|
||||
$defaultTestOutput = Join-Path $repositoryRoot "tests\Flyshot.Core.Tests\bin\$Configuration\net8.0"
|
||||
$allDestinations = @($DestinationDirectories) + @($defaultTestOutput)
|
||||
|
||||
foreach ($destination in $allDestinations | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique)
|
||||
{
|
||||
$absoluteDestination = [System.IO.Path]::GetFullPath($destination)
|
||||
if (-not (Test-Path -LiteralPath $absoluteDestination -PathType Container))
|
||||
{
|
||||
Write-Host "跳过不存在的目标目录:$absoluteDestination"
|
||||
continue
|
||||
}
|
||||
|
||||
$installationPath = & $vswherePath -latest -products * `
|
||||
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
|
||||
-property installationPath
|
||||
if ([string]::IsNullOrWhiteSpace($installationPath)) {
|
||||
throw "未找到已安装的 Visual Studio C++ x64 编译工具。"
|
||||
}
|
||||
|
||||
$vcvarsPath = Join-Path $installationPath "VC/Auxiliary/Build/vcvars64.bat"
|
||||
if (-not (Test-Path -LiteralPath $vcvarsPath)) {
|
||||
throw "未找到 VS x64 开发者环境脚本:$vcvarsPath"
|
||||
}
|
||||
|
||||
$quotedArguments = $cargoArguments | ForEach-Object { '"' + $_.Replace('"', '\"') + '"' }
|
||||
$command = 'call "{0}" >nul && "{1}" {2}' -f `
|
||||
$vcvarsPath, $cargoPath, ($quotedArguments -join " ")
|
||||
& cmd.exe /d /c $command
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Rust 原生规划库构建失败,退出码:$LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
else {
|
||||
& $cargoPath @cargoArguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Rust 原生规划库构建失败,退出码:$LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
$profileDirectory = if ($Configuration -eq "Release") { "release" } else { "debug" }
|
||||
$libraryName = if ($IsWindows) {
|
||||
"flyshot_native_planning.dll"
|
||||
}
|
||||
elseif ($IsLinux) {
|
||||
"libflyshot_native_planning.so"
|
||||
}
|
||||
else {
|
||||
throw "当前脚本仅支持 Windows x64 和 Linux x64。"
|
||||
}
|
||||
$sourcePath = Join-Path $repositoryRoot "native/flyshot-native-planning/target/$profileDirectory/$libraryName"
|
||||
if (-not (Test-Path -LiteralPath $sourcePath)) {
|
||||
throw "Rust 构建已结束,但未找到原生库:$sourcePath"
|
||||
}
|
||||
|
||||
# 未显式指定目标时,默认复制到对应配置的 Core 测试输出目录。
|
||||
if ($DestinationDirectories.Count -eq 0) {
|
||||
$DestinationDirectories = @(
|
||||
(Join-Path $repositoryRoot "tests/Flyshot.Core.Tests/bin/$Configuration/net8.0")
|
||||
)
|
||||
}
|
||||
|
||||
foreach ($destinationDirectory in $DestinationDirectories) {
|
||||
$destinationPath = if ([System.IO.Path]::IsPathRooted($destinationDirectory)) {
|
||||
$destinationDirectory
|
||||
}
|
||||
else {
|
||||
Join-Path $repositoryRoot $destinationDirectory
|
||||
}
|
||||
$resolvedDestination = [System.IO.Path]::GetFullPath(
|
||||
$destinationPath)
|
||||
New-Item -ItemType Directory -Force -Path $resolvedDestination | Out-Null
|
||||
Copy-Item -LiteralPath $sourcePath `
|
||||
-Destination (Join-Path $resolvedDestination $libraryName) `
|
||||
-Force
|
||||
Write-Host "已复制原生规划库到:$resolvedDestination"
|
||||
Copy-Item -LiteralPath $builtArtifactPath -Destination (Join-Path $absoluteDestination $artifactFileName) -Force
|
||||
Write-Host "已复制到:$absoluteDestination\$artifactFileName"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user