forked from mullvad/mullvadvpn-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-windows-modules.sh
More file actions
executable file
·168 lines (142 loc) · 4.58 KB
/
build-windows-modules.sh
File metadata and controls
executable file
·168 lines (142 loc) · 4.58 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
set -eu
function usage {
echo "usage: $0 [clean|build] [--max-concurrent-processes <n>] [solution...]"
echo " --max-concurrent-processes <n> Limit concurrent processes that msbuild can spawn to <n>. Defaults to number of processor cores."
exit 1
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
source scripts/utils/host
source scripts/utils/log
case $HOST in
x86_64-pc-windows-msvc) HOST_TARGET=x64;;
aarch64-pc-windows-msvc) HOST_TARGET=ARM64;;
*)
log_error "Unknown Windows target: $HOST"
exit 1
;;
esac
ACTION=build
SOLUTIONS=()
while [[ "$#" -gt 0 ]]; do
case $1 in
clean) ACTION="clean";;
build) ACTION="build";;
winfw) SOLUTIONS+=(winfw);;
nsis-plugins) SOLUTIONS+=(nsis-plugins);;
--max-concurrent-processes)
MAX_CPUS="$2"
shift
;;
help | --help) usage;;
*)
log_error "Unknown parameter: $1"
exit 1
;;
esac
shift
done
if [[ -z "${SOLUTIONS[*]}" ]]; then
SOLUTIONS=(winfw nsis-plugins)
fi
BUILD_WINFW=false
BUILD_NSIS=false
for sln in "${SOLUTIONS[@]}"; do
case $sln in
winfw) BUILD_WINFW=true;;
nsis-plugins) BUILD_NSIS=true;;
esac
done
# List of solution configurations to build.
# Default configurations generated by Visual Studio are "Release" and "Debug".
CPP_BUILD_MODES=${CPP_BUILD_MODES:-"Debug"}
# List of target platforms to build for.
# Common platforms include "x86" and "x64".
CPP_BUILD_TARGETS=${CPP_BUILD_TARGETS:-"$HOST_TARGET"}
function clean_solution {
local path="$1"
# Clean all intermediate and output files
echo "Removing ${path:?}..."
rm -r "${path:?}/bin/"* 2>/dev/null || true
}
function build_solution_config {
local sln="$1"
local config="$2"
local platform="$3"
if [ -z ${MAX_CPUS+x} ]; then
MAX_CPU_COUNT_ARG="/m"
else
MAX_CPU_COUNT_ARG="/m:${MAX_CPUS}"
fi
set -x
# Note: We've seen issues in CI (Windows ARM) indicating that the amount of memory that VS is allowed to reserve
# for pre-compiled headers is too small. '/Zm' allow us to tweak this value. /Zm100 is the default, and the value
# represents a multiplier expressed in percents. That is, /Zm400 equates to 4x the amount of memory VS is allowed
# to reserve compared to the default value. This parameter may be subject to tweaking if the issue persists.
# /Zm200 was not enough from our empirical testing, so /Zm400 was semi-arbitrarily chosen for now.
cmd.exe "/c msbuild.exe $MAX_CPU_COUNT_ARG $(to_win_path "$sln") /p:Configuration=$config /p:Platform=$platform /p:AdditionalOptions=/Zm400"
set +x
}
# Builds visual studio solution in all (specified) configurations
function build_solution {
local path="$1"
local sln="$1/$2"
for mode in $CPP_BUILD_MODES; do
for target in $CPP_BUILD_TARGETS; do
build_solution_config "$sln" "$mode" "$target"
done
done
}
function to_win_path {
local unixpath="$1"
# if it's a relative path and starts with a dot (.), don't transform the
# drive prefix (/c/ -> C:\)
if echo "$unixpath" | grep '^\.' >/dev/null; then
echo "$unixpath" | sed -e 's/^\///' -e 's/\//\\/g'
# if it's an absolute path, transform the drive prefix
else
# remove the cygdrive prefix if it's there
unixpath=$(echo "$unixpath" | sed -e 's/^\/cygdrive//')
echo "$unixpath" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'
fi
}
function get_solution_output_path {
local solution_root="$1"
local build_target="$2"
local build_mode="$3"
case $build_target in
"x86") echo "$solution_root/bin/Win32-$build_mode";;
"x64") echo "$solution_root/bin/x64-$build_mode";;
"ARM64") echo "$solution_root/bin/ARM64-$build_mode";;
*)
echo "Unknown build target: $build_target"
exit 1
;;
esac
}
function build_nsis_plugins {
cargo build --release --target i686-pc-windows-msvc -p mullvad-nsis
}
function clean_all {
cargo clean -p mullvad-nsis
clean_solution "./windows/libshared"
clean_solution "./windows/windows-libraries"
clean_solution "./windows/libwfp"
}
function build {
if [[ $BUILD_WINFW == "true" ]]; then
build_solution "./windows/winfw" "winfw.sln"
fi
if [[ $BUILD_NSIS == "true" ]]; then
build_nsis_plugins
fi
}
case $ACTION in
"build") build;;
"clean") clean_all;;
*)
echo "Unknown build action: $ACTION"
exit 1
;;
esac