Skip to content

Commit

Permalink
Update to Rust/Cargo v1.75 and simplify Windows Conda setup (#9935)
Browse files Browse the repository at this point in the history
* Split Conda into Unix/Windows variants, update to rust 1.75
* Add some helpers to get toolchain from conda env
* Remove MSM/MergeModules from Wix installer
* Bump to Clang/llvm 16.0.6 for better Windows SDK detection
* Simplify windows conda activation
* Install xwin and set winsysroot args to clang when present
* Install conda-pack into the environment too
* Write a wrapper script for lld-link instead
* Generate a rust cargo.config to use the CMake toolchain on Windows
* Bump minimum Cargo to 1.75 for Linux packaging
* Remove Android tooling from env-windows.yml
* Bump to Clang 16.0.6 for UNIX too
* Add script to fetch addition Visual Studio components
* Download VS Redist merge modules into xwin SDK too
* Put the VCRedist MergeModule back
  • Loading branch information
oskirby authored Oct 28, 2024
1 parent 0675d4a commit 0d8d2be
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 226 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if(NOT (IS_MULTI_CONFIG OR DEFINED CMAKE_BUILD_TYPE))
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type" FORCE)
message("Setting build type ${CMAKE_BUILD_TYPE}")
endif()
if(WIN32 AND DEFINED ENV{CONDA_PREFIX})
include(scripts/windows/conda-toolchain.cmake)
endif()

file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/version.txt" APP_VERSION)
message(APP_VERSION=${APP_VERSION})
Expand Down Expand Up @@ -56,6 +59,11 @@ if(WIN32)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/unsigned"
CACHE PATH "default install path" FORCE)
endif()

## Generate a cargo/config.toml file to pass the Conda toolchain into rust too.
if(DEFINED ENV{CONDA_PREFIX})
configure_file(scripts/windows/cargo-config.toml.in ${CMAKE_BINARY_DIR}/cargo_home/config.toml)
endif()
endif()
if(APPLE)
enable_language(OBJC)
Expand Down
8 changes: 3 additions & 5 deletions docs/Building/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ You may need to enable [powershell scripts.](https://learn.microsoft.com/en-us/p
For the setup you need to use powershell.

```powershell
$ conda env create -f env.yml
$ conda env create -f env-windows.yml
$ conda activate vpn
# Setup the conda env for clang-cl compilation
$ ./scripts/windows/conda_setup_win_sdk.ps1
# Download the Windows SDK using Xwin
$ ./scripts/windows/conda-setup-xwin-sdk.ps1
# Setup the conda env to use a prebuild Qt from Moz-CI
$ ./scripts/windows/conda_setup_win_qt.ps1
# Install conda Packages only needed on Windows
$ ./scripts/windows/conda_install_extras.ps1
# Reactivate the env to apply the changes:
$ conda deactivate
$ conda activate vpn
Expand Down
24 changes: 24 additions & 0 deletions env-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: vpn
channels:
- conda-forge
dependencies:
- clang=16.0.6
- clang-tools=16.0.6
- clangxx=16.0.6
- llvm=16.0.6
- llvmdev=16.0.6
- lld=16.0.6
- python=3.9
- nodejs=18.16.*
- pip=22.3.1
- rust=1.75
- compiler-rt
- cmake=3.26.3
- ninja=1.11.0
- conda-pack=0.8.0
- vswhere=3.1.7
- pip:
- -r requirements.txt
- -r taskcluster/scripts/requirements.txt
variables:
QT_VERSION: 6.6.3
24 changes: 12 additions & 12 deletions env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ name: vpn
channels:
- conda-forge
dependencies:
- clang=14.0.6
- clang-tools=14.0.6
- clangxx=14.0.6
- clang=16.0.6
- clang-tools=16.0.6
- clangxx=16.0.6
- python=3.9
- nodejs=18.16.*
- pip=22.3.1
- rust=1.69
- rust-std-aarch64-apple-darwin=1.69
- rust-std-x86_64-apple-darwin=1.69
- rust-std-aarch64-apple-ios=1.69
- rust-std-x86_64-apple-ios=1.69
- rust-std-armv7-linux-androideabi=1.69
- rust-std-x86_64-linux-android=1.69
- rust-std-i686-linux-android=1.69
- rust-std-aarch64-linux-android=1.69
- rust=1.75
- rust-std-aarch64-apple-darwin=1.75
- rust-std-x86_64-apple-darwin=1.75
- rust-std-aarch64-apple-ios=1.75
- rust-std-x86_64-apple-ios=1.75
- rust-std-armv7-linux-androideabi=1.75
- rust-std-x86_64-linux-android=1.75
- rust-std-i686-linux-android=1.75
- rust-std-aarch64-linux-android=1.75
- go=1.18
- compiler-rt
- cmake=3.26.3
Expand Down
4 changes: 2 additions & 2 deletions extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(APPLE AND CMAKE_OSX_ARCHITECTURES)
string(REPLACE "arm64" "aarch64" OSXARCH ${OSXARCH})
add_custom_target(cargo_mozillavpnnp_${OSXARCH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bridge
COMMAND ${CMAKE_COMMAND} -E env CARGO_HOME=${CMAKE_CURRENT_BINARY_DIR}/.cargo_home
COMMAND ${CMAKE_COMMAND} -E env CARGO_HOME=${CMAKE_BINARY_DIR}/cargo_home
cargo build --release --target-dir "${CMAKE_CURRENT_BINARY_DIR}/bridge"
--target "${OSXARCH}-apple-darwin"
)
Expand All @@ -32,7 +32,7 @@ else()
add_custom_target(cargo_mozillavpnnp ALL
COMMENT "Building web extension crate"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bridge
COMMAND ${CMAKE_COMMAND} -E env CARGO_HOME=${CMAKE_CURRENT_BINARY_DIR}/.cargo_home
COMMAND ${CMAKE_COMMAND} -E env CARGO_HOME=${CMAKE_BINARY_DIR}/cargo_home
cargo build --release --target-dir ${CMAKE_CURRENT_BINARY_DIR}/bridge/target
)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/bridge/target)
Expand Down
2 changes: 1 addition & 1 deletion linux/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 11.2),
gcc (>=4:8.0.0~),
g++ (>=4:8.0.0~),
golang (>=2:1.18~) | golang-1.18,
cargo,
cargo (>=1.75),
python3-yaml,
python3-jinja2,
python3-click,
Expand Down
2 changes: 1 addition & 1 deletion linux/mozillavpn.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requires: qt6-qtsvg >= 6.0
Requires: qt6-qt5compat >= 6.0
Requires: wireguard-tools

BuildRequires: cargo
BuildRequires: cargo >= 1.75
BuildRequires: golang >= 1.18
BuildRequires: libcap-devel
BuildRequires: libsecret-devel
Expand Down
10 changes: 10 additions & 0 deletions scripts/windows/cargo-config.toml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Auto generated by: ${CMAKE_CURRENT_LIST_FILE}
[target.x86_64-pc-windows-msvc]
linker="${CMAKE_LINKER}"

[env]
CC_x86_64-pc-windows-msvc="${CMAKE_C_COMPILER}"
CXX_x86_64-pc-windows-msvc="${CMAKE_CXX_COMPILER}"
AR_x86_64-pc-windows-msvc="${CMAKE_AR}"
CFLAGS_x86_64-pc-windows-msvc="${CMAKE_C_FLAGS}"
CXXFLAGS_x86_64-pc-windows-msvc="${CMAKE_CXX_FLAGS}"
38 changes: 38 additions & 0 deletions scripts/windows/conda-setup-xwin-sdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


$X_WIN_VERSION = "0.6.5"

$conda_env = conda info --json | ConvertFrom-Json

if( $conda_env.active_prefix_name -eq "base"){
Write-Output("Not in an active conda env. abort")
return -1
}
$conda_folder = $conda_env.active_prefix
Write-Output("Downloading x-win")
# Small X-Win appretiation comment.
# It's really great,
# it can process windows store manifests, request files from MS-servers and unpack it.
# we can use it to get the offical SDK files from microsoft.
# We can't cargo-install it because to use the clang-msvc compat mode,
#
Invoke-WebRequest -Uri "https://github.com/Jake-Shadle/xwin/releases/download/$X_WIN_VERSION/xwin-$X_WIN_VERSION-x86_64-pc-windows-msvc.tar.gz" -OutFile "$conda_folder\xwin.tar.gz"
$ProgressPreference = 'Continue'
Write-Output("Unpack x-win")
Start-Process -WorkingDirectory "$conda_folder" -Wait tar -ArgumentList @('-xf', "xwin.tar.gz")

# Splat the CRT and SDK file to /xwin/crt and /xwin/sdk respectively
Write-Output("Downloading the windows SDK")
$env:PATH ="$conda_folder\xwin-$X_WIN_VERSION-x86_64-pc-windows-msvc;$env:PATH"
xwin --accept-license --manifest-version 16 splat --include-debug-symbols --include-debug-libs --use-winsysroot-style --preserve-ms-arch-notation --disable-symlinks --output "$conda_folder\xwin"

Write-Output("Downloading Microsoft.VisualStudio.Component.VC.Redist.MSM")
python "$PSScriptRoot\fetch-vsix-package.py" --manifest-version 16 --output "$conda_folder\xwin" Microsoft.VisualStudio.Component.VC.Redist.MSM

Write-Output("Cleaning Up")
Remove-Item "$conda_folder\xwin-$X_WIN_VERSION-x86_64-pc-windows-msvc" -ErrorAction SilentlyContinue -Force -Recurse
Remove-Item ".xwin-cache" -ErrorAction SilentlyContinue -Force -Recurse
Remove-Item "xwin.tar.gz" -ErrorAction SilentlyContinue -Force
43 changes: 43 additions & 0 deletions scripts/windows/conda-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is intended to be used as a CMake toolchain file, and selects the
# clang-cl (MSVC compatible) compiler from the current conda prefix for use in
# building the application.
#
# To use this, set the CMAKE_TOOLCHAIN_FILE argument when setting up the Cmake
# project. For example:
# cmake .. -DCMAKE_TOOLCHAIN_FILE=scripts/windows/conda-toolchain.cmake
if(NOT DEFINED ENV{CONDA_PREFIX})
message(WARNING "Conda toolchain specified, but not in a Conda environment")
return()
endif()

# Set the C++ compiler and tools.
if(NOT CMAKE_C_COMPILER)
find_program(CMAKE_C_COMPILER NAMES clang-cl REQUIRED DOC "Clang C Compiler (MSVC Compatible)")
endif()
if(NOT CMAKE_CXX_COMPILER)
find_program(CMAKE_CXX_COMPILER NAMES clang-cl REQUIRED DOC "Clang C++ Compiler (MSVC Compatible)")
endif()
if(NOT CMAKE_RC_COMPILER)
find_program(CMAKE_RC_COMPILER NAMES llvm-rc REQUIRED DOC "LLVM Resource Compiler")
endif()
if(NOT CMAKE_MT)
find_program(CMAKE_MT NAMES llvm-mt REQUIRED DOC "LLVM Manifest Tool")
endif()
if(NOT PYTHON_EXECUTABLE)
find_program(PYTHON_EXECUTABLE PATHS "$ENV{CONDA_PREFIX}" NAMES python REQUIRED DOC "Python Interpreter (Conda)")
endif()

if(EXISTS $ENV{CONDA_PREFIX}/xwin)
cmake_path(CONVERT "$ENV{CONDA_PREFIX}\\xwin" TO_CMAKE_PATH_LIST XWIN_PREFIX)

set(CMAKE_C_FLAGS_INIT "/winsysroot ${XWIN_PREFIX} -fuse-ld=lld-link")
set(CMAKE_CXX_FLAGS_INIT "/winsysroot ${XWIN_PREFIX} -fuse-ld=lld-link")
set(CMAKE_RC_FLAGS_INIT "/winsysroot ${XWIN_PREFIX} -fuse-ld=lld-link")
set(CMAKE_LINKER ${CMAKE_CURRENT_LIST_DIR}/xwin-link.bat CACHE FILEPATH "LLD Linker for the Xwin SDK")
elseif(NOT CMAKE_LINKER)
find_program(CMAKE_LINKER NAMES lld-link REQUIRED DOC "LLD Linker (MSVC Compatible)")
endif()
23 changes: 0 additions & 23 deletions scripts/windows/conda_install_extras.ps1

This file was deleted.

121 changes: 0 additions & 121 deletions scripts/windows/conda_setup_win_sdk.ps1

This file was deleted.

Loading

0 comments on commit 0d8d2be

Please sign in to comment.