Skip to content

Commit

Permalink
Install xwin and set winsysroot args to clang when present
Browse files Browse the repository at this point in the history
  • Loading branch information
oskirby committed Oct 6, 2024
1 parent 7b7d7ad commit d38112a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
35 changes: 35 additions & 0 deletions scripts/windows/conda-setup-xwin-sdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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("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
15 changes: 9 additions & 6 deletions scripts/windows/conda-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ if(NOT PYTHON_EXECUTABLE)
find_program(PYTHON_EXECUTABLE PATHS "$ENV{CONDA_PREFIX}" NAMES python REQUIRED DOC "Python Interpreter (Conda)")
endif()

# Write a cargo config file to pass the compiler to Rust too.
function(generate_cargo_config RUST_TARGET_ARCH)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/cargo_home)
configure_file(${CMAKE_SOURCE_DIR}/scripts/windows/cargo-config.toml.in ${CMAKE_BINARY_DIR}/cargo_home/config.toml)
endfunction()
generate_cargo_config(x86_64-pc-windows-msvc)
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")

# See: https://github.com/llvm/llvm-project/issues/54409
set(CMAKE_EXE_LINKER_FLAGS "/winsysroot:${XWIN_PREFIX} /machine:x64")
endif()
8 changes: 4 additions & 4 deletions src/cmake/sentry.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ if( ${_SUPPORTED} GREATER -1 )
target_link_libraries(shared-sources INTERFACE breakpad_client.lib)
target_link_libraries(shared-sources INTERFACE dbghelp.lib)
target_link_libraries(shared-sources INTERFACE version.lib)
SET(SENTRY_ARGS
-DCMAKE_MT=${CMAKE_MT}
-DSENTRY_BACKEND=breakpad
)
SET(SENTRY_ARGS -DSENTRY_BACKEND=breakpad)
if(DEFINED ENV{CONDA_PREFIX})
LIST(APPEND SENTRY_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/scripts/windows/conda-toolchain.cmake)
endif()
endif()

if(ANDROID)
Expand Down
7 changes: 1 addition & 6 deletions taskcluster/scripts/toolchain/conda_pack_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ $env:PATH ="$CONDA_DIR;$FETCHES_PATH;$QTPATH;$env:PATH"
## Conda is now ready - let's enable the env
conda env create --force -f $REPO_ROOT_PATH/env-windows.yml -n VPN
conda run -n VPN conda info

conda activate VPN
. "$REPO_ROOT_PATH\scripts\windows\conda_setup_win_sdk.ps1" # <- This download's all sdk things we need :3
. "$REPO_ROOT_PATH\scripts\windows\conda_install_extras.ps1" # <- Tweaks the conda env for Clang/LLVM
conda deactivate
conda activate VPN
conda run -n VPN powershell -file "$REPO_ROOT_PATH\scripts\windows\conda-setup-xwin-sdk.ps1"

conda install conda-pack

Expand Down

0 comments on commit d38112a

Please sign in to comment.