Skip to content

Proposal - Refactor: Replace shell/Python build scripts with pure CMake#57

Open
jpola-amd wants to merge 1 commit intoGPUOpen-LibrariesAndSDKs:mainfrom
jpola-amd:dev/move-to_cmake
Open

Proposal - Refactor: Replace shell/Python build scripts with pure CMake#57
jpola-amd wants to merge 1 commit intoGPUOpen-LibrariesAndSDKs:mainfrom
jpola-amd:dev/move-to_cmake

Conversation

@jpola-amd
Copy link
Contributor

Summary

The old build system relied on platform-specific shell scripts (bakeKernel.bat/.sh), ad-hoc Python compilation scripts (compile.py, precompile_bitcode.py, common_tools.py), and a Premake5 alternative build path. This PR replaces all of them with a clean, self-contained CMake build.

This still need to be carefully tested across platforms and code generators


Changes

Removed

  • tools/bakeKernel.bat, tools/bakeKernel.sh — Windows/Linux bake wrappers
  • tools/stringify.py, tools/genArgs.py — low-quality helper scripts
  • scripts/bitcodes/compile.py, precompile_bitcode.py, common_tools.py — Python kernel compilation pipeline
  • premake5.lua, tools/functions.lua, tools/premake5/ — Premake build system
  • scripts/unittest*.bat, scripts/unittest*.sh — manual test runner scripts

Added

  • bake_kernels.py — single clean Python script replacing the 4 old bake scripts; callable via --source-dir; no CWD dependency
  • FindHIP.cmake — HIP SDK discovery, version detection, hip_get_gpu_architectures() (ported from common_tools.py), optional NVIDIA support via find_package(CUDAToolkit)
  • compile_kernels.cmake — kernel compilation via add_custom_command invoking hipcc/amdclang++/nvcc directly; replaces all Python compilation scripts
  • bake_kernels.cmake — configure-time bake invocation (cross-platform, no bat/sh branching)
  • embed_kernels.cmake — compiled kernel binary embedding with optional Zstd compression
  • convert_binary_to_array.cmake — CMake script-mode replacement for convert_binary_to_array.py
  • install_rules.cmake — proper install layout using GNUInstallDirs (bin/, lib/, include/)
  • CMakePresets.json — canonical presets for all build configurations

Modified

  • CMakeLists.txt — rewritten; bumped to CMake 3.20; uses target_compile_definitions instead of add_definitions; PROJECT_SOURCE_DIR throughout for FetchContent safety
  • README.md — updated build instructions to use CMake presets; removed Premake instructions
  • .gitignore — added generated Orochi cache headers, CMakeUserPresets.json

Build configurations

Build process still keeps the same CMAKE options.

Added support for presets

cmake --list-presets         # see all options
cmake --preset plain-vs2022  # configure
cmake --build --preset plain-vs2022-release
Preset Description
plain JIT mode (default)
bake-kernel Source strings embedded in binary
precompile External .hipfb at build time
bake-compiled Compiled kernels embedded in binary
no-tests Library-only (FetchContent consumers)
plain-vs2022 / plain-vs2019 Visual Studio generator variants

Notes

  • PRECOMPILE=ON now drives kernel compilation entirely through CMake add_custom_command — no Python subprocess needed
  • GPU architecture list (gfx1100, gfx1030, ...) is now a CMake function in FindHIP.cmake, versioned against HIP_VERSION_NUM
  • The project can be used as a top-level build or consumed via FetchContent — all install() and DLL-copy calls are guarded by PROJECT_IS_TOP_LEVEL
  • amd_comgr is now a soft dependency (warning, not error) to support minimal SDK installations

@meistdan
Copy link
Collaborator

meistdan commented Mar 9, 2026

Thank you for your proposal. This is a big change. I'm not sure if we should replace everything with cmake. We still use premake in some projects, and for example, cmake doesn't work well with WSL. The testing scripts are shipped with our CI builds and used by CQE. The baking scripts (sh and bat) could be replaced by platform independent python scripts. Python's syntax is much better than cmake in my opinion. Let me discuss with others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants