Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build universal installer for Windows #7300

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ members = [
"talpid-wireguard",
"tunnel-obfuscation",
"wireguard-go-rs",
"windows-installer",
]
# The default members may exclude packages that cannot be built for all targets, or that do not always
# need to be built
default-members = [
"android/translations-converter",
"desktop/packages/nseventforwarder",
"mullvad-api",
"mullvad-cli",
"mullvad-daemon",
"mullvad-exclude",
"mullvad-fs",
"mullvad-ios",
"mullvad-jni",
"mullvad-management-interface",
"mullvad-nsis",
"mullvad-encrypted-dns-proxy",
"mullvad-paths",
"mullvad-problem-report",
"mullvad-relay-selector",
"mullvad-setup",
"mullvad-types",
"mullvad-types/intersection-derive",
"mullvad-version",
"talpid-core",
"talpid-dbus",
"talpid-future",
"talpid-macos",
"talpid-net",
"talpid-openvpn",
"talpid-openvpn-plugin",
"talpid-platform-metadata",
"talpid-routing",
"talpid-time",
"talpid-tunnel",
"talpid-tunnel-config-client",
"talpid-windows",
"talpid-wireguard",
"tunnel-obfuscation",
"wireguard-go-rs",
]

# Keep all lints in sync with `test/Cargo.toml`
Expand Down
33 changes: 25 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ OPTIMIZE="false"
SIGN="false"
# If the produced app and pkg should be notarized by apple (macOS only)
NOTARIZE="false"
# If a macOS build should create an installer artifact working on both
# Intel and Apple Silicon Macs
# If a macOS or Windows build should create an installer artifact working on both
# x86 and arm64
UNIVERSAL="false"

while [[ "$#" -gt 0 ]]; do
Expand All @@ -38,8 +38,8 @@ while [[ "$#" -gt 0 ]]; do
--sign) SIGN="true";;
--notarize) NOTARIZE="true";;
--universal)
if [[ "$(uname -s)" != "Darwin" ]]; then
log_error "--universal only works on macOS"
if [[ "$(uname -s)" != "Darwin" && "$(uname -s)" != "MINGW"* ]]; then
log_error "--universal only works on macOS and Windows"
exit 1
fi
UNIVERSAL="true"
Expand Down Expand Up @@ -79,18 +79,20 @@ if [[ "$UNIVERSAL" == "true" ]]; then
log_error "'TARGETS' and '--universal' cannot be specified simultaneously."
exit 1
else
log_info "Building universal macOS distribution"
log_info "Building universal distribution"
fi

# Universal macOS builds package targets for both aarch64-apple-darwin and x86_64-apple-darwin.
# We leave the target corresponding to the host machine empty to avoid rebuilding multiple times.
# Universal builds package targets for both aarch64 and x86_64. We leave the target
# corresponding to the host machine empty to avoid rebuilding multiple times.
# When the --target flag is provided to cargo it always puts the build in the target/$ENV_TARGET
# folder even when it matches you local machine, as opposed to just the target folder.
# This causes the cached build not to get used when later running e.g.
# 'cargo run --bin mullvad --shell-completions'.
case $HOST in
x86_64-apple-darwin) TARGETS=("" aarch64-apple-darwin);;
aarch64-apple-darwin) TARGETS=("" x86_64-apple-darwin);;
x86_64-pc-windows-msvc) TARGETS=("" aarch64-pc-windows-msvc);;
aarch64-pc-windows-msvc) TARGETS=("" x86_64-pc-windows-msvc);;
esac

NPM_PACK_ARGS+=(--universal)
Expand Down Expand Up @@ -311,7 +313,7 @@ function build {

if [[ "$(uname -s)" == "MINGW"* ]]; then
for t in "${TARGETS[@]:-"$HOST"}"; do
case $t in
case "${t:-"$HOST"}" in
x86_64-pc-windows-msvc) CPP_BUILD_TARGET=x64;;
aarch64-pc-windows-msvc) CPP_BUILD_TARGET=ARM64;;
*)
Expand Down Expand Up @@ -384,6 +386,21 @@ if [[ "$SIGN" == "true" && "$(uname -s)" == "MINGW"* ]]; then
done
fi

# pack universal installer on Windows
if [[ "$UNIVERSAL" == "true" && "$(uname -s)" == "MINGW"* ]]; then
WIN_PACK_ARGS=()
if [[ "$OPTIMIZE" == "true" ]]; then
WIN_PACK_ARGS+=(--optimize)
fi
./desktop/scripts/pack-universal-win.sh \
--x64-installer "$SCRIPT_DIR/dist/"*"$PRODUCT_VERSION"_x64.exe \
--arm64-installer "$SCRIPT_DIR/dist/"*"$PRODUCT_VERSION"_arm64.exe \
"${WIN_PACK_ARGS[@]}"
if [[ "$SIGN" == "true" ]]; then
sign_win "dist/MullvadVPN-${PRODUCT_VERSION}.exe"
fi
fi

# notarize installer on macOS
if [[ "$NOTARIZE" == "true" && "$(uname -s)" == "Darwin" ]]; then
log_info "Notarizing pkg"
Expand Down
14 changes: 10 additions & 4 deletions ci/buildserver-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ function build_ref {
if [[ "$(uname -s)" == "Darwin" ]]; then
build_args+=(--universal --notarize)
fi
if [[ "$(uname -s)" == "MINGW"* ]]; then
# Check if the windows-installer crate is present, and if so, build a universal installer.
# The check is needed for compatibility with older commits that don't have the crate/flag.
# It was added in December 2024. The condition can be removed when supporting commits
# older than that is no longer necessary.
if [[ -d "$BUILD_DIR/windows-installer" ]]; then
build_args+=(--universal)
fi
fi

artifact_dir=$artifact_dir build "${build_args[@]}" || return 1
if [[ "$(uname -s)" == "Linux" ]]; then
Expand All @@ -205,9 +214,6 @@ function build_ref {

case "$(uname -s)" in
MINGW*|MSYS_NT*)
echo "Building ARM64 installers"
target=aarch64-pc-windows-msvc artifact_dir=$artifact_dir build "${build_args[@]}" || return 1

echo "Packaging all PDB files..."
find ./windows/ \
./target/release/mullvad-daemon.pdb \
Expand All @@ -226,7 +232,7 @@ function build_ref {
# Pipes all matching names and their new name to mv
pushd "$artifact_dir"
for original_file in MullvadVPN-*-dev-*{.deb,.rpm,.exe,.pkg}; do
new_file=$(echo "$original_file" | perl -pe "s/^(MullvadVPN-.*?)(_arm64|_aarch64|_amd64|_x86_64)?(\.deb|\.rpm|\.exe|\.pkg)$/\1$version_suffix\2\3/p")
new_file=$(echo "$original_file" | perl -pe "s/^(MullvadVPN-.*?)(_x64|_arm64|_aarch64|_amd64|_x86_64)?(\.deb|\.rpm|\.exe|\.pkg)$/\1$version_suffix\2\3/p")
mv "$original_file" "$new_file"
done
popd
Expand Down
Loading
Loading