Skip to content

Commit

Permalink
添加Action CI编译脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Apr 19, 2023
1 parent e9d4d41 commit 3a4d82a
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 6 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Build

on: [push, pull_request]

jobs:
Build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: 初始化
working-directory: ${{github.workspace}}
run: |
$ProgramFiles = ${env:ProgramFiles(x86)}
if (-not $ProgramFiles)
{
$ProgramFiles = $env:ProgramFiles
}
$BuiltInVsWhereExe = "$ProgramFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $BuiltInVsWhereExe))
{
throw "找不到vswhere.exe!"
}
Write-Output $BuiltInVsWhereExe
$LatestVisualStudioRoot = & $BuiltInVsWhereExe -latest -prerelease -property installationPath
if (-not (Test-Path $LatestVisualStudioRoot))
{
throw "找不到 VisualStudioRoot!"
}
echo "LatestVisualStudioRoot=$LatestVisualStudioRoot" >> $env:GITHUB_ENV
$MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\Current\Bin"
if (-not (Test-Path $MSBuildBinPath))
{
$installationVersion = & $BuiltInVsWhereExe -latest -prerelease -property installationVersion
$majorVersion = "$installationVersion".Split('.')[0]
$MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\$majorVersion.0\Bin"
}
if (-not (Test-Path $MSBuildBinPath))
{
throw "找不到 MSBuildBinPath!"
}
echo "MSBuildBinPath=$MSBuildBinPath" >> $env:GITHUB_ENV
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
{
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
}
- name: 执行编译
working-directory: ${{github.workspace}}
shell: pwsh
run: |
# MSBuild 目录更新到 Path
$Env:Path="${{env.MSBuildBinPath}};${{env.LatestVisualStudioRoot}}\Common7\IDE\CommonExtensions\Microsoft\TestWindow;" + $Env:Path
# 编译项目
&msbuild Build.proj
if($lastexitcode -ne 0)
{
throw "编译失败!退出代码:$lastexitcode"
}
- name: 文件打包
working-directory: ${{github.workspace}}
shell: cmd
run: |
:: 打包Release
pushd Release
7z a -tzip MSBuildCppCrossToolset-${{env.BuildVersion}}-Binary.zip VCTargets
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
popd
7z u -tzip Release\MSBuildCppCrossToolset-${{env.BuildVersion}}-Binary.zip LICENSE.txt README.md
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
- uses: actions/upload-artifact@v2
with:
path: |
Release/*.zip
# 失败时我们收集一些信息,用于诊断
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ErrorLog
path: |
Release/**/*.*
- uses: xresloader/upload-to-github-release@v1
if: contains(github.ref, 'tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: "Release/MSBuildCppCrossToolset-*.zip"
overwrite: true
tags: true
draft: false
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# 关于 MSBuildCppCrossToolset
# 关于 MSBuildCppCrossToolset - 在Linux、MacOS中编译vcxproj
[![license](https://img.shields.io/github/license/Chuyu-Team/MSBuildCppCrossToolset)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/blob/master/LICENSE)
![downloads](https://img.shields.io/github/downloads/Chuyu-Team/MSBuildCppCrossToolset/total)
[![contributors](https://img.shields.io/github/contributors-anon/Chuyu-Team/MSBuildCppCrossToolset)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/graphs/contributors)
[![release](https://img.shields.io/github/v/release/Chuyu-Team/MSBuildCppCrossToolset?include_prereleases)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/releases)
[![Build](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/actions/workflows/Build.yml/badge.svg)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/actions/workflows/Build.yml)

重要提示:VCTargets中的文件从 `Microsoft Visual Studio\?\?\MSBuild\Microsoft\VC` 提取,Microsoft拥有其所有权利。

重要提示:本项目还未完工……

本项目基于微软VCTargets修改,为MSBuild实现了跨平台编译vcxproj。
本项目基于微软VCTargets修改,为MSBuild实现了跨平台编译vcxproj。相关VS配置高度抽象统一,并与目标编译器功能一比一映射。

> 举个例子:代码完全优化(Full选项),微软编译器时中映射为 `-Ox`,而使用GCC时则映射为`-O3`
未来开发计划:
* [ ] 解决增量编译不生效问题。
* [ ] 优化并行生成效率。
* [ ] 单元测试。

# 1. 兼容性
## 1.1. 兼容的操作系统
Expand All @@ -33,19 +42,21 @@
* x86

# 2. 使用方式
# 2.1. 安装 .NET
# 2.1. 安装 .NET SDK
下载地址:https://dotnet.microsoft.com/zh-cn/download

> 目前我使用的是 .NET 6.0,因为它是长期支持,我不确定安装 7.0 是否兼容我的脚本
> 必须选择 .NET 6.0或者更高版本
## 2.2. 配置 MSBuildCppCrossToolset
假设 MSBuildCppCrossToolset 下载到的 `/home/john/Desktop/VCTargets`。首先执行下面二条命令:
首先,我们从[Release](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/releases)产物下载MSBuildCppCrossToolset并解压。

假设最终解压目录是`/home/john/Desktop/VCTargets`。我们执行下面这条命令:

```
export VCTargetsPath=/home/john/Desktop/VCTargets/v170/
```

它们将临时添加VCTargetsPath、VCTargetsPath17二个环境变量,如果需要持久配置,请自行修改系统配置。
它将临时添加`VCTargetsPath`环境变量,如果需要持久配置,请自行修改系统配置。

## 2.3. 编译vcxproj项目
假设项目位置: `/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj`。并且编译 Release x86,那么可以输入如下命令:
Expand All @@ -55,3 +66,16 @@ dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxpr
```

> 温馨提示:`PlatformToolset` 必须从 1.2. 兼容的编译器小节中对应的平台工具集中选择,比如说想用GCC就设置`YY_Cross_GCC_1_0`
# 3. 我怎么自己编译 MSBuildCppCrossToolset?
> 温馨提示:普通用户无需关心如何编译 MSBuildCppCrossToolset。只需要从Release产物中下载即可。
注意:编译MSBuildCppCrossToolset需要安装`.NET 6.0 SDK`

假设MSBuildCppCrossToolset项目源代码存放在: `D:\MSBuildCppCrossToolset`
```
# 也可以使用 dotnet CLI编译
msbuild D:\MSBuildCppCrossToolset\Build.proj
```

执行成功后,Release目录就是输出产物。

0 comments on commit 3a4d82a

Please sign in to comment.