the overkill patch

This commit is contained in:
lda committed 2025-08-04 17:17:20 +07:00
1 parent af1b471799
commit 2dc4784f4b
6 files changed
+361 -14

No files matched your search

+1
View File
@@ -1,2 +1,3 @@
exe exe
*.exe *.exe
build/
+21
View File
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.26100.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe" ,
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
+52
View File
@@ -0,0 +1,52 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C++: Debug with g++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C++: Smart Build (Auto-detect Compiler)",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "C++: Debug with MSVC",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "C++: Smart Build (Auto-detect Compiler)"
},
{
"name": "C++: Run without debugging",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "C++: Smart Build (Auto-detect Compiler)"
}
]
}
+6
View File
@@ -56,5 +56,11 @@
"deque": "cpp", "deque": "cpp",
"queue": "cpp", "queue": "cpp",
"stack": "cpp" "stack": "cpp"
},
"files.exclude": {
"**/*.rpyc": true,
"**/*.rpa": true,
"**/*.rpymc": true,
"**/cache/": true
} }
} }
+97
View File
@@ -0,0 +1,97 @@
param(
[Parameter(Mandatory = $true)]
[string]$SourceFile,
[Parameter(Mandatory = $true)]
[string]$WorkspaceFolder,
[Parameter(Mandatory = $false)]
[string]$BuildType = "debug"
)
# Extract filename without extension
$FileBaseName = [System.IO.Path]::GetFileNameWithoutExtension($SourceFile)
$OutputPath = Join-Path $WorkspaceFolder "build\$BuildType\$FileBaseName.exe"
# Ensure build directory exists
$BuildDir = Join-Path $WorkspaceFolder "build\$BuildType"
if (-not (Test-Path $BuildDir)) {
New-Item -ItemType Directory -Path $BuildDir -Force | Out-Null
}
Write-Host "Building: $SourceFile"
Write-Host "Output: $OutputPath"
Write-Host ""
# Try g++ first
if (Get-Command g++ -ErrorAction SilentlyContinue) {
Write-Host "Using g++ compiler..." -ForegroundColor Green
if ($BuildType -eq "release") {
$gppArgs = @(
"-std=c++17"
"-Wall"
"-Wextra"
"-O2"
"-DNDEBUG"
"`"$SourceFile`""
"-o"
"`"$OutputPath`""
)
}
else {
$gppArgs = @(
"-std=c++17"
"-Wall"
"-Wextra"
"-g"
"-O0"
"`"$SourceFile`""
"-o"
"`"$OutputPath`""
)
}
& g++ @gppArgs
if ($LASTEXITCODE -eq 0) {
Write-Host "Build successful with g++!" -ForegroundColor Green
exit 0
}
else {
Write-Host "g++ build failed, trying MSVC..." -ForegroundColor Yellow
}
}
# Try MSVC as fallback
$VsDevCmd = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
if (Test-Path $VsDevCmd) {
Write-Host "Using MSVC compiler..." -ForegroundColor Green
# Convert to absolute paths for MSVC
$AbsoluteSourceFile = Resolve-Path $SourceFile
$ObjFile = Join-Path $BuildDir "$FileBaseName.obj"
$PdbFile = Join-Path $BuildDir "$FileBaseName.pdb"
if ($BuildType -eq "release") {
$MSVCCommand = "`"$VsDevCmd`" && cl.exe /std:c++17 /W4 /O2 /DNDEBUG /EHsc /MD /Fe:`"$OutputPath`" /Fo:`"$ObjFile`" `"$AbsoluteSourceFile`""
}
else {
$MSVCCommand = "`"$VsDevCmd`" && cl.exe /std:c++17 /W4 /Zi /EHsc /MDd /Fe:`"$OutputPath`" /Fo:`"$ObjFile`" /Fd:`"$PdbFile`" `"$AbsoluteSourceFile`""
}
& cmd /c $MSVCCommand
if ($LASTEXITCODE -eq 0) {
Write-Host "Build successful with MSVC!" -ForegroundColor Green
exit 0
}
else {
Write-Host "MSVC build failed!" -ForegroundColor Red
exit 1
}
}
else {
Write-Error "No C++ compiler found! Please install g++ or Visual Studio."
exit 1
}
+184 -14
View File
@@ -1,27 +1,197 @@
{ {
"version": "2.0.0",
"tasks": [ "tasks": [
{ {
"type": "cppbuild", "type": "shell",
"label": "C/C++: g++.exe build active file", "label": "C++: Smart Build (Auto-detect Compiler)",
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe", "command": "powershell.exe",
"args": [ "args": [
"-fdiagnostics-color=always", "-ExecutionPolicy",
"-g", "Bypass",
"-File",
"${workspaceFolder}\\.vscode\\smartbuild.ps1",
"-SourceFile",
"${file}", "${file}",
"-o", "-WorkspaceFolder",
"${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe" "${workspaceFolder}",
// hey check this line "-BuildType",
], "debug"
"problemMatcher": [
"$gcc"
], ],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc", "$msCompile"],
"group": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
}, },
"detail": "Task generated by Debugger." "detail": "Automatically detects and uses available C++ compiler (g++ or MSVC)",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
} }
},
{
"type": "shell",
"label": "C++: Smart Build (Release)",
"command": "powershell.exe",
"args": [
"-ExecutionPolicy",
"Bypass",
"-File",
"${workspaceFolder}\\.vscode\\smartbuild.ps1",
"-SourceFile",
"${file}",
"-WorkspaceFolder",
"${workspaceFolder}",
"-BuildType",
"release"
], ],
"version": "2.0.0" "options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc", "$msCompile"],
"group": "build",
"detail": "Build optimized release version with auto-detected compiler"
},
{
"type": "cppbuild",
"label": "C++: Build with g++ (Debug)",
"command": "g++",
"args": [
"-std=c++17",
"-Wall",
"-Wextra",
"-g",
"-O0",
"${file}",
"-o",
"${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build current file with g++ in debug mode",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
},
{
"type": "cppbuild",
"label": "C++: Build with g++ (Release)",
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-std=c++17",
"-Wall",
"-Wextra",
"-O2",
"-DNDEBUG",
"${file}",
"-o",
"${workspaceFolder}\\build\\release\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build current file with g++ in release mode"
},
{
"type": "cppbuild",
"label": "C++: Build with g++ (MSYS2 Full Path)",
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-std=c++17",
"-Wall",
"-Wextra",
"-g",
"-O0",
"${file}",
"-o",
"${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "Build current file with g++ using explicit MSYS2 path (backup option)"
},
{
"type": "shell",
"label": "C++: Build with MSVC (Debug)",
"command": "powershell.exe",
"args": [
"-Command",
"& { $buildDir = '${workspaceFolder}\\build\\debug'; if (-not (Test-Path $buildDir)) { New-Item -ItemType Directory -Path $buildDir -Force }; & cmd /c '\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat\" && cd /d \"$buildDir\" && cl.exe /std:c++17 /W4 /Zi /EHsc /MDd /Fe:\"${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe\" /Fo:\"$buildDir\\${fileBasenameNoExtension}.obj\" /Fd:\"$buildDir\\${fileBasenameNoExtension}.pdb\" \"${file}\"' }"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$msCompile"],
"group": "build",
"detail": "Build current file with MSVC in debug mode (clean intermediate files)"
},
{
"type": "shell",
"label": "C++: Run current file",
"command": "\"${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe\"",
"args": [],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
},
"dependsOn": "C++: Smart Build (Auto-detect Compiler)",
"detail": "Build and run the current C++ file"
},
{
"type": "shell",
"label": "C++: Clean build directory",
"command": "powershell.exe",
"args": [
"-Command",
"if (Test-Path \"${workspaceFolder}\\build\") { Remove-Item -Recurse -Force \"${workspaceFolder}\\build\\*\" } else { New-Item -ItemType Directory -Path \"${workspaceFolder}\\build\\debug\", \"${workspaceFolder}\\build\\release\" -Force }"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"detail": "Clean all build artifacts and recreate build directories"
},
{
"type": "shell",
"label": "C++: Setup build directories",
"command": "powershell.exe",
"args": [
"-Command",
"New-Item -ItemType Directory -Path \"${workspaceFolder}\\build\\debug\", \"${workspaceFolder}\\build\\release\" -Force"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"detail": "Create build directories if they don't exist"
}
]
} }