Skip to content

Commit

Permalink
[build] 改进Windows构建流程并引入新的配置脚本
Browse files Browse the repository at this point in the history
- 移除了原有的`Configure msvc for amd64`步骤,替换为`Configure and build windows`,以简化配置流程并整合构建步骤
- 将`shell`从`bash`更改为`pwsh`(PowerShell),以提升Windows环境下的脚本兼容性和现代性
- 引入了新的PowerShell脚本`setVsDev.ps1`,用于自动化设置Visual Studio开发环境,包括定位安装路径和启动开发命令行
- 通过`setVsDev.ps1`脚本,可以自动选择最新版本的Visual Studio,或者根据提供的版本范围参数选择特定版本
- 脚本支持指定目标架构(如`x64`),并能够在找不到Visual Studio安装时提供反馈
- 优化了`cmake`命令的执行,添加了错误检查和反馈机制,确保在配置失败时能够提供有用的信息
- 移除了`Configure macos or ubuntu`和`Build`步骤中的重复错误检查和反馈逻辑,因为这些现在可以通过`cmake`命令的错误检查来处理
- 更新了`.github/workflows/build.yml`文件,以反映新的配置和构建流程
- 在`scripts/windows/`目录下添加了新的`setVsDev.ps1`脚本,为Windows构建流程提供了更强的灵活性和鲁棒性
  • Loading branch information
RealChuan committed May 13, 2024
1 parent fccbdf0 commit b6ad46a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
44 changes: 13 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
name: CMake Build

on:
# push代码时触发workflow
push:
paths-ignore: # 下列文件的变更不触发部署,可以自行添加
- '.github/workflows/clean_cache.yml'
- '.github/workflows/delete_workflow.yml'
- '.github/workflows/readme.yml'
- '.github/workflows/toolchain.yml'
paths-ignore:
- '.clang*'
- '.gitignore'
- 'LICENSE'
- 'README*'
pull_request:
paths-ignore: # 下列文件的变更不触发部署,可以自行添加
- '.github/workflows/clean_cache.yml'
- '.github/workflows/delete_workflow.yml'
- '.github/workflows/readme.yml'
- '.github/workflows/toolchain.yml'
paths-ignore:
- '.clang*'
- '.gitignore'
- 'LICENSE'
Expand Down Expand Up @@ -99,25 +90,19 @@ jobs:
${{ matrix.os }}-
save-always: true

- name: Configure msvc for amd64
- name: Configure and build windows
if: startsWith(matrix.os, 'windows')
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64

- name: Configure windows
if: startsWith(matrix.os, 'windows')
shell: bash
shell: pwsh
run: |
cmake \
-S . \
-B ./build \
-DCMAKE_C_COMPILER=cl \
-DCMAKE_CXX_COMPILER=cl \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-G "${{ matrix.generators }}" \
|| (cat ./build/vcpkg_installed/vcpkg/issue_body.md && exit 1)
- name: Configure macos or ubuntu
.\scripts\windows\setVsDev.ps1
cmake `
-S . `
-B ./build `
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} `
-G "${{ matrix.generators }}" `
; if (-not $?) { Get-Content ./build/vcpkg_installed/vcpkg/issue_body.md; exit 1 }
cmake --build ./build --config ${{ matrix.build_type }}
- name: Configure and build macos or ubuntu
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
Expand All @@ -127,9 +112,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-G "${{ matrix.generators }}" \
|| (cat ./build/vcpkg_installed/vcpkg/issue_body.md && exit 1)
- name: Build
shell: bash
run: |
cmake --build ./build --config ${{ matrix.build_type }}
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delete_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
delete_run_by_conclusion_pattern:
description: 'Remove runs based on conclusion: action_required, cancelled, failure, skipped, success'
required: true
default: "failure"
default: "Unsuccessful: action_required,cancelled,failure,skipped"
type: choice
options:
- "ALL"
Expand Down
62 changes: 62 additions & 0 deletions scripts/windows/setVsDev.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
param(
[Parameter(Mandatory = $false)]
[string]$VersionRange,
[Parameter(Mandatory = $false)]
[string]$Arch
)


$vswhereArgs = @()

if ($VersionRange) {
$vswhereArgs += "-version"
$vswhereArgs += $VersionRange
}
else {
$vswhereArgs += "-latest"
}


$vswhereArgs += "-property"
$vswhereArgs += "installationPath"

if ([string]::IsNullOrEmpty($Arch)) {
$Arch = "x64"
}

Write-Host "Architecture: $Arch"
Write-Host "VSWhere Args: $vswhereArgs"

# 使用 vswhere 获取 Visual Studio 的安装路径
$vswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstallPath = & $vswherePath $vswhereArgs | ForEach-Object { $_ }
# Output the results
Write-Host "Visual Studio installation paths:"
$vsInstallPath

if ($null -ne $vsInstallPath) {
$vsDevShell = Join-Path $vsInstallPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
if (-not (Test-Path $vsDevShell)) {
Write-Host "Failed to find Visual Studio DevShell DLL: $vsDevShell"
exit 1
}
Import-Module $vsDevShell
Enter-VsDevShell -VsInstallPath $vsInstallPath -DevCmdArguments "-arch=$Arch -host_arch=$Arch" -SkipAutomaticLocation

if ($LASTEXITCODE -eq 0) {
Write-Host "Development environment set up successfully."
}
else {
Write-Host "Failed to set up the development environment."
}
}
else {
Write-Host "Using Custom Visual Studio installation path."
$vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
if (-not (Test-Path $vsInstallPath)) {
$vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise"
}
$vsDevShell = Join-Path $vsInstallPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Import-Module $vsDevShell
Enter-VsDevShell -VsInstallPath $vsInstallPath -DevCmdArguments "-arch=x64 -host_arch=x64" -SkipAutomaticLocation
}

0 comments on commit b6ad46a

Please sign in to comment.