Last active
February 16, 2025 07:18
-
-
Save soda92/a255d1f8a4ff38ca9d7075f677089e62 to your computer and use it in GitHub Desktop.
windows clangd fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 10, | |
"cmakeMinimumRequired": { | |
"major": 3, | |
"minor": 23, | |
"patch": 0 | |
}, | |
// "$comment": "An example CMakePresets.json file", | |
// "include": [ | |
// "otherThings.json", | |
// "moreThings.json" | |
// ], | |
"configurePresets": [ | |
{ | |
// "$comment": [ | |
// "This is a comment row.", | |
// "This is another comment,", | |
// "just because we can do it" | |
// ], | |
"name": "default", | |
"displayName": "Default Config", | |
"description": "Default build using Ninja generator", | |
"generator": "Ninja", | |
"binaryDir": "${sourceDir}/build", | |
"cacheVariables": { | |
"FIRST_CACHE_VARIABLE": { | |
"type": "BOOL", | |
"value": "OFF" | |
}, | |
"SECOND_CACHE_VARIABLE": "ON" | |
}, | |
"environment": { | |
// "MY_ENVIRONMENT_VARIABLE": "Test", | |
// "PATH": "$env{HOME}/ninja/bin:$penv{PATH}" | |
}, | |
"vendor": { | |
"example.com/ExampleIDE/1.0": { | |
"autoFormat": true | |
} | |
} | |
}, | |
{ | |
"name": "ninja-multi", | |
"inherits": "default", | |
"displayName": "Ninja Multi-Config", | |
"description": "Default build using Ninja Multi-Config generator", | |
"generator": "Ninja Multi-Config" | |
}, | |
{ | |
"name": "windows-only", | |
"inherits": "default", | |
"displayName": "Windows-only configuration", | |
"description": "This build is only available on Windows", | |
"condition": { | |
"type": "equals", | |
"lhs": "${hostSystemName}", | |
"rhs": "Windows" | |
} | |
} | |
], | |
"buildPresets": [ | |
{ | |
"name": "default", | |
"configurePreset": "default" | |
}, | |
{ | |
"name": "windows", | |
"configurePreset": "windows-only" | |
} | |
], | |
"testPresets": [ | |
{ | |
"name": "default", | |
"configurePreset": "default", | |
"output": { | |
"outputOnFailure": true | |
}, | |
"execution": { | |
"noTestsAction": "error", | |
"stopOnFailure": true | |
} | |
} | |
], | |
"packagePresets": [ | |
{ | |
"name": "default", | |
"configurePreset": "default", | |
"generators": [ | |
"TGZ" | |
] | |
} | |
], | |
"workflowPresets": [ | |
{ | |
"name": "default", | |
"steps": [ | |
{ | |
"type": "configure", | |
"name": "default" | |
}, | |
{ | |
"type": "build", | |
"name": "default" | |
}, | |
{ | |
"type": "test", | |
"name": "default" | |
}, | |
{ | |
"type": "package", | |
"name": "default" | |
} | |
] | |
} | |
], | |
"vendor": { | |
"example.com/ExampleIDE/1.0": { | |
"autoFormat": false | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 10, | |
"cmakeMinimumRequired": { | |
"major": 3, | |
"minor": 23, | |
"patch": 0 | |
}, | |
"configurePresets": [ | |
{ | |
"name": "windows2", | |
"inherits": "windows-only", | |
"displayName": "Windows-only configuration", | |
"cacheVariables": { | |
"CMAKE_CXX_COMPILER": { | |
"type": "STRING", | |
"value": "C:/TDM-GCC-64/bin/g++.exe" | |
}, | |
"CMAKE_C_COMPILER": "C:/TDM-GCC-64/bin/gcc.exe", | |
"SECOND_CACHE_VARIABLE": "ON" | |
} | |
} | |
], | |
"buildPresets": [ | |
{ | |
"name": "windows2", | |
"configurePreset": "windows2" | |
} | |
] | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import json | |
import os | |
import functools | |
from sodatools import read_path, write_path, str_path | |
CURRENT = Path(__file__).resolve().parent | |
commands = CURRENT.joinpath("build").joinpath("compile_commands.json") | |
commands2 = commands.parent.joinpath(commands.stem) | |
if commands.exists(): | |
if commands2.exists(): | |
commands2.unlink() | |
commands.rename(commands2) | |
commands = commands2 | |
def which(name): | |
path = os.environ["PATH"] | |
for p in path.split(";"): | |
exe = Path(p).joinpath(name) | |
if exe.exists(): | |
return exe | |
def str_(s): | |
return s.replace("\\", "/") | |
@functools.cache | |
def get_gcc_path(): | |
# out = which("gcc.exe") | |
# return out.resolve().parent.parent | |
return str_(r"C:\TDM-GCC-64\virtual") | |
def get_includes(): | |
ret = [] | |
includes = [ | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++", | |
r"{gcc}x86_64-w64-mingw32\include", | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32", | |
] | |
for i in includes: | |
i = str_(i) | |
i = i.replace("{gcc}", str_path(get_gcc_path()) + "/") | |
ret.append("-isystem " + i) | |
return ret | |
def fix_command(c) -> str: | |
list_ = c.replace("\\", "/").split() | |
list_.extend(get_includes()) | |
return " ".join(list_) | |
def fix_commands(): | |
c = read_path(commands) | |
obj = json.loads(c) | |
for item in obj: | |
item["command"] = fix_command(item["command"]) | |
s = json.dumps(obj, indent=2) | |
write_path(CURRENT.parent.joinpath("compile_commands.json"), s) | |
if __name__ == "__main__": | |
fix_commands() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import json | |
import os | |
import functools | |
from sodatools import read_path, write_path, str_path | |
CURRENT = Path(__file__).resolve().parent | |
commands = CURRENT.joinpath("build").joinpath("compile_commands.json") | |
commands2 = commands.parent.joinpath(commands.stem) | |
if commands.exists(): | |
if commands2.exists(): | |
commands2.unlink() | |
commands.rename(commands2) | |
commands = commands2 | |
def which(name): | |
path = os.environ["PATH"] | |
for p in path.split(";"): | |
exe = Path(p).joinpath(name) | |
if exe.exists(): | |
return exe | |
def str_(s): | |
return s.replace("\\", "/") | |
@functools.cache | |
def get_gcc_path(): | |
# out = which("gcc.exe") | |
# return out.resolve().parent.parent | |
return str_(r"C:\TDM-GCC-64\virtual") | |
def get_includes(): | |
ret = [] | |
includes = [ | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++", | |
r"{gcc}x86_64-w64-mingw32\include", | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32", | |
] | |
for i in includes: | |
i = str_(i) | |
i = i.replace("{gcc}", str_path(get_gcc_path()) + "/") | |
ret.append("-isystem " + i) | |
return ret | |
def fix_command(c) -> str: | |
list_ = c.replace("\\", "/").split() | |
list_.extend(get_includes()) | |
return " ".join(list_) | |
def fix_commands(): | |
c = read_path(commands) | |
obj = json.loads(c) | |
for item in obj: | |
item["command"] = fix_command(item["command"]) | |
s = json.dumps(obj, indent=2) | |
write_path(CURRENT.parent.joinpath("compile_commands.json"), s) | |
if __name__ == "__main__": | |
fix_commands() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import glob | |
from pathlib import Path | |
from sodatools import write_path, str_path, read_path | |
def get_file_list(i: str): | |
lis = list(glob.glob("**/*", recursive=True, root_dir=i)) | |
ret = [] | |
for p in lis: | |
ret.append(Path(i).joinpath(p)) | |
# print(i) | |
return ret | |
def fix_content(c): | |
c = c.replace("__MINGW_ATTRIB_NORETURN", "") | |
c = c.replace("__MINGW_NOTHROW", "") | |
return c | |
def write_virtual(f): | |
if f.is_dir(): | |
return | |
global cnt | |
base = Path(r"c:\TDM-GCC-64") | |
virtual = Path(r"c:\TDM-GCC-64\virtual") | |
rel = Path(f).relative_to(base) | |
vfile = virtual.joinpath(rel) | |
vfile.parent.mkdir(parents=True, exist_ok=True) | |
try: | |
c = fix_content(read_path(f)) | |
write_path(vfile, c) | |
except UnicodeDecodeError: | |
return | |
CURRENT = Path(__file__).resolve().parent | |
sys.path.insert(0, str_path(CURRENT)) | |
tdm_dir = r"c:/TDM-GCC-64" | |
tdm_dir_v = r"c:/TDM-GCC-64/virtual" | |
db = Path(tdm_dir_v).joinpath("compile_commands.json") | |
dirs = [ | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++", | |
r"{gcc}x86_64-w64-mingw32\include", | |
r"{gcc}lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32", | |
] | |
includes_list = [] | |
for i in dirs: | |
i = i.replace("\\", "/") | |
source = i.replace("{gcc}", tdm_dir + "/") | |
virtual = i.replace("{gcc}", tdm_dir_v + "/") | |
includes_list.append("-isystem " + virtual) | |
includes = " ".join(includes_list) | |
objs = [] | |
dummy_cc = str_path(Path(tdm_dir_v).joinpath("demo.cc")) | |
write_path(Path(dummy_cc), "") | |
for i in dirs: | |
i = i.replace("\\", "/") | |
i = i.replace("{gcc}", tdm_dir + "/") | |
files = get_file_list(i) | |
for f in files: | |
write_virtual(f) | |
obj = { | |
"directory": tdm_dir_v, | |
"command": f"C:/TDM-GCC-64/bin/g++.exe {includes} {dummy_cc}", | |
"file": dummy_cc, | |
"output": str_path(Path(tdm_dir_v).joinpath("a.obj")), | |
} | |
objs.append(obj) | |
s = json.dumps(objs, indent=2) | |
write_path(db, s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMAKE ?= cmake | |
BUILD_DIR ?= build | |
.PHONY: all build clean configure install | |
all: build | |
configure: | |
python ../gen_cmake.py | |
python ../reformat.py | |
cmake --preset windows2 | |
build: configure | |
cmake --build --preset windows2 | |
python gen_lsp_tdm.py | |
run_a: all | |
./build/six-degrees.exe | |
run_b: all | |
./build/imdb-test.exe | |
package: | |
fyne package | |
clean: | |
pwsh -c "rm -r $(BUILD_DIR)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment