Skip to content

Instantly share code, notes, and snippets.

@matu3ba
Last active December 21, 2022 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matu3ba/1f56669caeab6b3dea53b940407be00c to your computer and use it in GitHub Desktop.
Save matu3ba/1f56669caeab6b3dea53b940407be00c to your computer and use it in GitHub Desktop.
Powershell script to parse devkit version + ninja install path and building (failing with CMAKE_AR-NOTFOUND)
# powershell script to parse devkit version and install Zig
# assume: 1. devkit in dir devkit, zig in dir zig in same dir
# 2. cmake installed (download possible on https://cmake.org/download/)
# 3. ninja installed (pip install ninja) + in path
# 4. powershell scripts executable (execution in shell):
# Get-Content bZig.ps1 | PowerShell.exe -noprofile -
## current error:
#[10/21] Linking CXX static library zigcpp\libzigcpp.a
#FAILED: zigcpp/libzigcpp.a
#cmd.exe /C "cd . && C:\Users\user\Desktop\cmake\bin\cmake.exe -E rm -f zigcpp\libzigcpp.a && CMAKE_AR-NOTFOUND qc zigcpp\libzigcpp.a CMakeFiles/zigcpp.dir/src/zig_llvm.cpp.obj CMakeFiles/zigcpp.dir/src/zig_llvm-ar.cpp.obj CMakeFiles/zigcpp.dir/src/zig_clang.cpp.obj CMakeFiles/zigcpp.dir/src/zig_clang_driver.cpp.obj CMakeFiles/zigcpp.dir/src/zig_clang_cc1_main.cpp.obj CMakeFiles/zigcpp.dir/src/zig_clang_cc1as_main.cpp.obj CMakeFiles/zigcpp.dir/src/windows_sdk.cpp.obj && cd ."
# problem: no llvm-ar included in the devkit (should be linked together with VSCode)
# parse pip install
$draftpathninja = pip show ninja
$pathninja = $draftpathninja[7].Split(" ")[1]
$joinpath = -join($pathninja, "\ninja\data\bin")
$env:Path += $joinpath
$joinpath
$env:Path
function CheckLastExitCode {
if (!$?) {
exit 1
}
return 0
}
# replace with other dir, if needed
$COMMON_DIR = -join('C:\Users\', $env:UserName, '\Desktop')
Set-Location -Path $COMMON_DIR
$line = Get-ChildItem -Path .\zig\ci\x86_64-windows.ps1 -Recurse | Select-String -Pattern 'ZIG_LLVM_CLANG_LLD_NAME ='
$splitted = $line -split "-"
$version_raw = -join($splitted[3], "-", $splitted[4])
$VERSION = $version_raw.Substring(0,$version_raw.Length-1)
$TARGET = "x86_64-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-$VERSION"
$MCPU = "baseline"
$PREFIX_PATH = "$(Get-Location)\devkit\$ZIG_LLVM_CLANG_LLD_NAME"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\zig\lib"
$CMAKE = -join('C:\Users\', $env:UserName, '\Desktop\cmake\bin\cmake.exe')
Set-Location -Path 'zig'
Write-Output "Preparing dirs.."
Remove-Item -Path 'build' -Recurse -Force -ErrorAction Ignore
New-Item -Path 'build' -ItemType Directory
Set-Location -Path 'build'
# TODO: llvm-ar missing
#-DCMAKE_AR="%ROOTDIR_CMAKE%%OUTDIR%/host/bin/llvm-ar.exe"
# -DCMAKE_AR="$($ZIG -Replace "\\", "/");ar" `
Write-Output "Preparing cmake.."
& $CMAKE .. `
-GNinja `
-DCMAKE_INSTALL_PREFIX="stage3-release" `
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" `
-DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" `
-DZIG_TARGET_TRIPLE="$TARGET" `
-DZIG_TARGET_MCPU="$MCPU" `
-DZIG_STATIC=ON
CheckLastExitCode
Write-Output "building+installing.."
ninja install
CheckLastExitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment