-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.win.ps1
128 lines (112 loc) · 5.22 KB
/
build.win.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
$root_dir = (Get-Location).Path
function exit_if_fail {
if ($LastExitCode -ne 0) {
Write-Host -ForegroundColor Red Sub cmd failed!
Exit -1
}
}
function cmake_configure() {
if ($LT_DUMP_URL) {
Invoke-Expression "cmake -B build/$script:build_type -DLT_DUMP=ON -DLT_DUMP_URL=`"$LT_DUMP_URL`" -DCMAKE_BUILD_TYPE=$script:build_type -DCMAKE_INSTALL_PREFIX=install/$script:build_type"
} else {
Invoke-Expression "cmake -B build/$script:build_type -DCMAKE_BUILD_TYPE=$script:build_type -DCMAKE_INSTALL_PREFIX=install/$script:build_type"
}
exit_if_fail
}
function cmake_build() {
# Github Actions runners only have 2 cores
Invoke-Expression "cmake --build build/$script:build_type --parallel 2 --config $script:build_type --target install"
exit_if_fail
}
function cmake_clean() {
Invoke-Expression "cmake --build build/$script:build_type --target clean"
}
function check_build_type() {
if ($script:build_type -ieq "debug") {
$script:build_type = "Debug"
Write-Host -ForegroundColor Green Debug
} elseif (($script:build_type -ieq "release") -or ($script:build_type -ieq "RelWithDebInfo")) {
Write-Host -ForegroundColor Green RelWithDebInfo
$script:build_type = "RelWithDebInfo"
} else {
Write-Host -ForegroundColor Red 'Please specify target type [ Debug | Release ]'
Exit -1
}
}
function rtc_fetch() {
$RtcUri = "https://github.com/numbaa/rtc-prebuilt/releases/download/v0.7.9/rtc.win.zip"
New-Item -ItemType Directory -ErrorAction SilentlyContinue src/transport/rtc/win
echo "Fetch $RtcUri"
Invoke-WebRequest -Uri $RtcUri -OutFile ./third_party/prebuilt/rtc.win.zip
Expand-Archive ./third_party/prebuilt/rtc.win.zip -DestinationPath ./src/transport/rtc/win
}
class BuiltLib {
[string]$Name
[string]$Uri
BuiltLib([string]$n, [string]$u) {
$this.Uri = $u
$this.Name = $n
}
}
function prebuilt_fetch() {
$libs = @(
[BuiltLib]::new("mbedtls", "https://github.com/numbaa/mbedtls-build/releases/download/v3.5.2-3/mbedtls.win.v3.5.2-3.zip"),
[BuiltLib]::new("sdl", "https://github.com/numbaa/sdl-build/releases/download/v2.28.4-5/sdl.win.v2.28.4-5.zip"),
[BuiltLib]::new("vigemclient", "https://github.com/numbaa/vigemclient-build/releases/download/v1/vigemclient.zip"),
[BuiltLib]::new("libuv", "https://github.com/numbaa/libuv-build/releases/download/v1.44.1-3/libuv.win.v1.44.1-3.zip"),
[BuiltLib]::new("onevpl", "https://github.com/numbaa/onevpl-build/releases/download/v2023.3.1-3/onevpl.win.v2023.3.1-3.zip"),
[BuiltLib]::new("opus", "https://github.com/numbaa/opus-build/releases/download/v1.4-2/opus.win.v1.4-2.zip"),
[BuiltLib]::new("g3log", "https://github.com/numbaa/g3log-build/releases/download/v2.3-6/g3log.win.v2.3-6.zip"),
[BuiltLib]::new("googletest", "https://github.com/numbaa/googletest-build/releases/download/v1.13.0-2/googletest.win.v1.13.0-2.zip"),
[BuiltLib]::new("ffmpeg", "https://github.com/numbaa/ffmpeg-build/releases/download/v5.1.3-16/ffmpeg.win.v5.1.3-16.zip"),
[BuiltLib]::new("protobuf", "https://github.com/numbaa/protobuf-build/releases/download/v3.24.3-2/protobuf.win.v3.24.3-2.zip")
[BuiltLib]::new("sqlite", "https://github.com/numbaa/sqlite-build/releases/download/v3.43.1-6/sqlite3.win.v3.43.1-6.zip")
[BuiltLib]::new("openh264", "https://github.com/numbaa/openh264-prebuilt/releases/download/v2.4.0-1/openh264.win.v2.4.0-1.zip")
[BuiltLib]::new("nbclipboard", "https://github.com/numbaa/nbclipboard-prebuilt/releases/download/v0.0.3/nbclipboard.win.v0.0.3.zip")
)
New-Item -ItemType Directory -ErrorAction SilentlyContinue third_party/prebuilt
foreach ($lib in $libs) {
$LibName = $lib.Name
$LibUri = $lib.Uri
echo "Fetch $LibUri"
Invoke-WebRequest -Uri $lib.Uri -OutFile ./third_party/prebuilt/$LibName.win.zip
# exit_if_fail
echo "Unzip $LibName.win.zip"
Expand-Archive ./third_party/prebuilt/$LibName.win.zip -DestinationPath ./third_party/prebuilt/$LibName/win
# exit_if_fail
}
rtc_fetch
}
function prebuilt_clean() {
Remove-Item -Force -Recurse third_party/prebuilt
Remove-Item -Force -Recurse transport/rtc
}
function print_usage() {
Write-Host -ForegroundColor Green 'Usage: '
Write-Host -ForegroundColor Green ' build.ps1 prebuilt [ fetch | clean ]'
Write-Host -ForegroundColor Green ' build.ps1 build [ Debug | Release ]'
Write-Host -ForegroundColor Green ' build.ps1 clean [ Debug | Release ]'
Exit -1
}
$action = $args[0]
if ($action -eq "prebuilt") {
if ($args[1] -eq "fetch") {
prebuilt_fetch
} elseif ($args[1] -eq "clean") {
prebuilt_clean
} else {
Write-Host -ForegroundColor Red 'Please specify prebuilt type [ fetch | clean ]'
Exit -1
}
} elseif ($action -eq "clean") {
$script:build_type=$args[1]
check_build_type
cmake_clean
} elseif ($action -eq "build") {
$script:build_type=$args[1]
check_build_type
cmake_configure
cmake_build
} else {
print_usage
}