# Builds only the PyTorch-for-Luau plugin, against any PyTorch: what CI runs for each version in env/ml_versions.json
# (.github/workflows/torch-plugins.yml), and what the karasu-ml-versions skill runs locally to see a new version compile.
#   cmake -S env/cmake/torch_plugin -B build-plugin -DTORCH_DIR=<unpacked wheel>/torch -DCMAKE_BUILD_TYPE=Release
#   cmake --build build-plugin -j 4
# TORCH_DIR is the torch/ folder of a PyTorch wheel (include/ and lib/ are all it needs: no Python involved).
cmake_minimum_required(VERSION 3.21)
project(walkenv_torch_plugin CXX)

if(WIN32)
  message(FATAL_ERROR "PyTorch for Luau isn't built for Windows yet (cmake/luau_torch.cmake)")
endif()
if(NOT TORCH_DIR OR NOT EXISTS "${TORCH_DIR}/lib")
  message(FATAL_ERROR "Pass -DTORCH_DIR=<the torch/ folder of an unpacked PyTorch wheel> (it needs include/ and lib/)")
endif()
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

get_filename_component(env_dir "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
set(luau ${env_dir}/third_party/luau)
include(${env_dir}/cmake/torch_plugin.cmake)
walkenv_torch_plugin(walkenv_torch "${TORCH_DIR}"
  "${luau}/Common/include;${luau}/Ast/include;${luau}/Bytecode/include;${luau}/Compiler/include;${luau}/VM/include;${luau}/CodeGen/include"
  ${env_dir})
