Configure clangd for the native Windows x86 toolchain
This commit is contained in:
parent
a47d20f8be
commit
63cca8868e
2 changed files with 60 additions and 0 deletions
2
.clangd
2
.clangd
|
|
@ -1,2 +1,4 @@
|
|||
CompileFlags:
|
||||
CompilationDatabase: build/editor-x86
|
||||
Add: [--driver-mode=cl, --target=i686-pc-windows-msvc, -fms-compatibility-version=19.29]
|
||||
Remove: [/FS, /O2, /Ob2]
|
||||
|
|
|
|||
58
configure-clangd.ps1
Normal file
58
configure-clangd.ps1
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = $PSScriptRoot.Replace('\', '/')
|
||||
$project = Get-Content -LiteralPath "$PSScriptRoot/decomp.json" -Raw | ConvertFrom-Json
|
||||
$compile = Get-Content -LiteralPath "$PSScriptRoot/$($project.compileCommands)" -Raw | ConvertFrom-Json
|
||||
$workspace = Get-Content -LiteralPath "$PSScriptRoot/.td/config.json" -Raw | ConvertFrom-Json
|
||||
$runner = $workspace.runners.PSObject.Properties[$project.toolchain].Value
|
||||
|
||||
if (-not $runner -or $runner.type -ne 'native' -or -not $runner.toolchainRoot) {
|
||||
throw "clangd configuration requires this workspace's native Windows toolchain."
|
||||
}
|
||||
|
||||
$toolchain = $runner.toolchainRoot.Replace('\', '/')
|
||||
$compiler = $compile.compiler.Replace('${TC}', $toolchain).Replace('${SRC}', $root)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $compiler -PathType Leaf)) {
|
||||
throw "Configured compiler not found: $compiler"
|
||||
}
|
||||
|
||||
$systemIncludes = @($compile.env.INCLUDE.Replace('${TC}', $toolchain).Replace('${SRC}', $root).Split(';') | Where-Object { $_ })
|
||||
|
||||
foreach ($include in $systemIncludes) {
|
||||
if (-not (Test-Path -LiteralPath $include -PathType Container)) {
|
||||
throw "Configured include directory not found: $include"
|
||||
}
|
||||
}
|
||||
|
||||
$commands = @(
|
||||
foreach ($unit in $compile.units.PSObject.Properties) {
|
||||
$file = "$root/$($unit.Name)"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $file -PathType Leaf)) {
|
||||
throw "Configured source file not found: $file"
|
||||
}
|
||||
|
||||
$arguments = @($compiler)
|
||||
$arguments += @($compile.shapes[[int]$unit.Value] | ForEach-Object {
|
||||
$_.Replace('${TC}', $toolchain).Replace('${SRC}', $root)
|
||||
})
|
||||
$arguments += @($systemIncludes | ForEach-Object { "/imsvc$_" })
|
||||
$arguments += $file
|
||||
|
||||
[ordered]@{
|
||||
directory = $root
|
||||
file = $file
|
||||
arguments = $arguments
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$outputDirectory = Join-Path $PSScriptRoot 'build/editor-x86'
|
||||
[void](New-Item -ItemType Directory -Path $outputDirectory -Force)
|
||||
$output = Join-Path $outputDirectory 'compile_commands.json'
|
||||
$json = ConvertTo-Json -InputObject $commands -Depth 6
|
||||
[System.IO.File]::WriteAllText($output, $json + "`n", [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output "Generated $($commands.Count) clangd compilation commands: $output"
|
||||
Loading…
Add table
Add a link
Reference in a new issue