Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/tools/test_generate_cmake_presets_build_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json

import tools.generate_cmake_presets as presets


def test_generate_presets_uses_requested_build_type(monkeypatch, tmp_path):
output_path = tmp_path / "CMakeUserPresets.json"
nvcc_path = tmp_path / "bin" / "nvcc"
nvcc_path.parent.mkdir()
nvcc_path.write_text("", encoding="utf-8")

monkeypatch.setattr(presets, "CUDA_HOME", str(tmp_path))
monkeypatch.setattr(presets, "which", lambda name: None)
monkeypatch.setattr(presets, "get_cpu_cores", lambda: 8)

presets.generate_presets(
output_path=str(output_path),
force_overwrite=True,
build_type="RelWithDebInfo",
)

data = json.loads(output_path.read_text())
configure = data["configurePresets"][0]
assert configure["name"] == "relwithdebinfo"
assert configure["binaryDir"] == "${sourceDir}/cmake-build-relwithdebinfo"
assert configure["cacheVariables"]["CMAKE_BUILD_TYPE"] == "RelWithDebInfo"
assert data["buildPresets"][0]["configurePreset"] == "relwithdebinfo"
27 changes: 20 additions & 7 deletions tools/generate_cmake_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def get_cpu_cores():
return multiprocessing.cpu_count()


def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False):
def generate_presets(
output_path="CMakeUserPresets.json",
force_overwrite=False,
build_type="Release",
):
"""Generates the CMakeUserPresets.json file."""

print("Attempting to detect your system configuration...")
Expand Down Expand Up @@ -96,7 +100,7 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)

cache_variables = {
"CMAKE_CUDA_COMPILER": nvcc_path,
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_TYPE": build_type,
"VLLM_PYTHON_EXECUTABLE": python_executable,
"CMAKE_INSTALL_PREFIX": "${sourceDir}",
"CMAKE_CUDA_FLAGS": "",
Expand All @@ -116,8 +120,8 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)
print("No compiler cache ('ccache' or 'sccache') found.")

configure_preset = {
"name": "release",
"binaryDir": "${sourceDir}/cmake-build-release",
"name": build_type.lower(),
"binaryDir": f"${{sourceDir}}/cmake-build-{build_type.lower()}",
"cacheVariables": cache_variables,
}
if which("ninja"):
Expand All @@ -134,8 +138,8 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)
"configurePresets": [configure_preset],
"buildPresets": [
{
"name": "release",
"configurePreset": "release",
"name": build_type.lower(),
"configurePreset": build_type.lower(),
"jobs": cmake_jobs,
}
],
Expand Down Expand Up @@ -171,11 +175,20 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--build-type",
default="Release",
choices=("Debug", "Release", "RelWithDebInfo", "MinSizeRel"),
help="CMake build type to write into the generated preset",
)
parser.add_argument(
"--force-overwrite",
action="store_true",
help="Force overwrite existing CMakeUserPresets.json without prompting",
)

args = parser.parse_args()
generate_presets(force_overwrite=args.force_overwrite)
generate_presets(
force_overwrite=args.force_overwrite,
build_type=args.build_type,
)