forked from ao-space/gt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
153 lines (135 loc) · 5.39 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
$WORK_DIR = $PSScriptRoot
$WEBRTC_DIR="$WORK_DIR/libcs/dep/_google-webrtc"
$MSQUIC_DIR="$WORK_DIR/libcs/dep/_msquic"
$WEBRTC_OUT_DIR="$WEBRTC_DIR/src/out/release/obj"
$MSQUIC_OUT_DIR="$MSQUIC_DIR/build/windows/x64_schannel/obj/Release"
$WEB_FRONT="$WORK_DIR/libcs/web/front"
$env:CC="clang"
$env:CXX="clang++"
$env:CGO_CXXFLAGS="-I$WEBRTC_DIR/src -I$WEBRTC_DIR/src/third_party/abseil-cpp -I$MSQUIC_DIR/src/inc -std=c++17 -DWEBRTC_WIN -DQUIC_API_ENABLE_PREVIEW_FEATURES -DNOMINMAX"
$env:CGO_LDFLAGS="-L$MSQUIC_DIR/build/windows/x64_schannel/obj/Release -L$WEBRTC_DIR/src/out/release/obj -lmsquic.lib -lwebrtc.lib"
$env:CARGO_CFG_TARGET_OS="windows"
$env:RUSTFLAGS="-L $MSQUIC_OUT_DIR -l msquic -L $WEBRTC_OUT_DIR -l webrtc"
$env:DEPOT_TOOLS_WIN_TOOLCHAIN="0"
$env:GYP_GENERATORS="msvs-ninja,ninja"
$env:GYP_MSVS_OVERRIDE_PATH="C:\Program Files\Microsoft Visual Studio\2022\Community"
$env:GYP_MSVS_VERSION="2022"
$env:PATH+=";C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja"
# 检查 Pscx 模块是否已安装
if (-not (Get-Module -Name Pscx -ListAvailable)) {
Write-Host "安装Pscx PowerShell插件"
Install-Module -Name Pscx -AllowPrerelease -Force
}
# 检查 VSSetup 模块是否已安装
if (-not (Get-Module -Name VSSetup -ListAvailable)) {
Write-Host "安装VSSetup PowerShell插件"
Install-Module -Name VSSetup -AllowPrerelease -Force
}
Import-VisualStudioVars 2022 amd64
Set-Location $WORK_DIR
function complie_webrtc{
Set-Location "$WEBRTC_DIR/src"
Write-Host "开始编译webrtc"
gn gen out/release --args="clang_use_chrome_plugins=false is_clang=true enable_libaom=false is_component_build=false is_debug=false libyuv_disable_jpeg=true libyuv_include_tests=false rtc_build_examples=false rtc_build_tools=false rtc_enable_grpc=false rtc_enable_protobuf=false rtc_include_builtin_audio_codecs=false rtc_include_dav1d_in_internal_decoder_factory=false rtc_include_ilbc=false rtc_include_internal_audio_device=false rtc_include_tests=false rtc_use_h264=false rtc_use_x11=false treat_warnings_as_errors=false use_custom_libcxx=false use_gold=false use_lld=true use_rtti=true use_sysroot=false"
ninja -C out/release
if (Test-Path -Path "$WEBRTC_OUT_DIR/webrtc.lib")
{
Write-Host "webrtc编译完成"
}
else
{
Write-Host "webrtc编译失败"
Set-Location $WORK_DIR
exit
}
}
function CheckAdministrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function complie_msquic{
Set-Location $MSQUIC_DIR
if (!(Test-Path -Path "$MSQUIC_DIR/artifacts")){
Write-Host "msquic未初始化依赖项,正在初始化"
if (CheckAdministrator) {
&./scripts/prepare-machine.ps1
} else {
Write-Output "当前未以管理员权限运行"
Set-Location $WORK_DIR
exit
}
}
Write-Host "msquic开始编译"
&./scripts/build.ps1 -Config Release -Clean -Static -DisableTest -DisableTools -StaticCRT
if (Test-Path -Path "$MSQUIC_OUT_DIR/msquic.lib")
{
Write-Host "msquic编译完成"
}
else
{
Write-Host "msquic编译失败"
Set-Location $WORK_DIR
exit
}
}
function release_front{
Set-Location $WEB_FRONT
$npmCommand = Get-Command npm -ErrorAction SilentlyContinue
if ($null -ne $npmCommand) {
Write-Output "npm 命令可用,进行下一步"
} else {
Write-Output "npm 命令不可用,正在安装node.js"
winget install --id=OpenJS.NodeJS -e
}
if(Test-Path -Path "$WORK_DIR/libcs/client/web/dist"){
Remove-Item -Path "$WORK_DIR/libcs/client/web/dist" -Recurse -Force
}
if(Test-Path -Path "$WORK_DIR/libcs/server/web/dist"){
Remove-Item -Path "$WORK_DIR/libcs/server/web/dist" -Recurse -Force
}
if (Test-Path -Path "$WEB_FRONT/dist")
{
Remove-Item -Path "$WEB_FRONT/dist" -Recurse -Force
}
npm install
npm run "build:pro"
if (Test-Path -Path "$WEB_FRONT/dist")
{
Copy-Item -Path "$WEB_FRONT/dist" -Destination "$WORK_DIR/libcs/client/web/dist" -Recurse
Copy-Item -Path "$WEB_FRONT/dist" -Destination "$WORK_DIR/libcs/server/web/dist" -Recurse
Write-Host "web front编译完成"
}
}
function release_gt_lib{
release_front
Set-Location "$WORK_DIR/libcs"
Write-Host "开始编译gt server/client"
go build -tags release -trimpath -ldflags "-s -w" -buildmode=c-archive -o release/windows/gt.lib ./lib/export
if (Test-Path -Path "./release/windows/gt.lib")
{
Write-Host "gt server/client编译完成"
}
else
{
Write-Host "gt server/client编译失败"
Set-Location $WORK_DIR
exit
}
}
function release_gt_exe{
Set-Location $WORK_DIR
Write-Host "开始编译gt"
cargo build --target x86_64-pc-windows-msvc -r
Write-Host "gt编译完成"
}
if (!(Test-Path -Path "$WEBRTC_OUT_DIR/webrtc.lib")){
complie_webrtc
}
if (!(Test-Path -Path "$MSQUIC_OUT_DIR/msquic.lib")){
complie_msquic
}
release_gt_lib
release_gt_exe
New-Item -ItemType Directory -Force -Path "$WORK_DIR/release"
Copy-Item -Path "$WORK_DIR/target/x86_64-pc-windows-msvc/release/gt.exe" -Destination "$WORK_DIR/release/gt-win-x86_64.exe"