Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit 9855e2c

Browse files
Missing Windows knobs to make it compatible with kernels (#277)
- Make sure the `platform` template variable is provided through `build2cmake` - Ensure correct install target is being called - Use "common" cmake ordering to invoke install target --------- Co-authored-by: medmekk <mekk.cyber@gmail.com>
1 parent 889428e commit 9855e2c

4 files changed

Lines changed: 27 additions & 32 deletions

File tree

build2cmake/src/templates/windows.cmake

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,27 @@ function(add_kernels_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME)
103103
set(ARG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
104104
endif()
105105

106-
# Create the kernels_install target if it doesn't exist
107-
if(NOT TARGET kernels_install)
108-
add_custom_target(kernels_install ALL
109-
COMMENT "Installing all kernels to hub-compatible layout"
110-
VERBATIM)
111-
endif()
112-
113-
# Create a custom target for this specific kernel
114-
set(KERNEL_INSTALL_TARGET "${TARGET_NAME}_kernel_install")
106+
# Set the installation directory
115107
set(KERNEL_INSTALL_DIR "${ARG_INSTALL_PREFIX}/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
116108

117-
add_custom_target(${KERNEL_INSTALL_TARGET} ALL
118-
COMMAND ${CMAKE_COMMAND} -E make_directory "${KERNEL_INSTALL_DIR}"
119-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}> "${KERNEL_INSTALL_DIR}/"
120-
COMMAND ${CMAKE_COMMAND} -E copy_directory
121-
"${CMAKE_SOURCE_DIR}/torch-ext/${PACKAGE_NAME}"
122-
"${KERNEL_INSTALL_DIR}/"
123-
DEPENDS ${TARGET_NAME}
124-
COMMENT "Installing ${TARGET_NAME} to ${KERNEL_INSTALL_DIR}"
125-
VERBATIM)
126-
127-
# Make kernels_install depend on this specific kernel's install
128-
add_dependencies(kernels_install ${KERNEL_INSTALL_TARGET})
129-
130-
# Set folder for IDE organization
131-
if(MSVC OR XCODE)
132-
set_target_properties(${KERNEL_INSTALL_TARGET} PROPERTIES FOLDER "Install")
133-
endif()
109+
message(STATUS "Using PACKAGE_NAME: ${PACKAGE_NAME}")
110+
111+
# Install the compiled extension using CMake's install() command
112+
# This will be triggered by the standard INSTALL target
113+
install(TARGETS ${TARGET_NAME}
114+
LIBRARY DESTINATION "${KERNEL_INSTALL_DIR}"
115+
RUNTIME DESTINATION "${KERNEL_INSTALL_DIR}"
116+
COMPONENT ${TARGET_NAME})
134117

135-
message(STATUS "Added kernels_install target for ${TARGET_NAME} -> ${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
118+
# Glob Python files to install
119+
file(GLOB PYTHON_FILES "${CMAKE_SOURCE_DIR}/torch-ext/${PACKAGE_NAME}/*.py")
120+
121+
# Install Python files (__init__.py and _ops.py)
122+
install(FILES ${PYTHON_FILES}
123+
DESTINATION "${KERNEL_INSTALL_DIR}"
124+
COMPONENT ${TARGET_NAME})
125+
126+
message(STATUS "Added install rules for ${TARGET_NAME} -> ${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
136127
endfunction()
137128

138129
#
@@ -181,4 +172,4 @@ function(add_local_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME)
181172

182173
file(MAKE_DIRECTORY ${LOCAL_INSTALL_DIR})
183174
message(STATUS "Added install rules for ${TARGET_NAME} -> build/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
184-
endfunction()
175+
endfunction()

build2cmake/src/torch/cuda.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ pub fn render_extension(
384384
context! {
385385
name => name,
386386
ops_name => ops_name,
387+
platform => std::env::consts::OS,
387388
},
388389
&mut *write,
389390
)

build2cmake/src/torch/xpu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ pub fn render_extension(
262262
context! {
263263
name => name,
264264
ops_name => ops_name,
265+
platform => std::env::consts::OS
265266
},
266267
&mut *write,
267268
)

scripts/windows/builder.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ function Invoke-CMakeTarget {
365365
)
366366

367367
Write-Status "Running $DisplayName..." -Type Info
368-
cmake --build . --target $Target --config $BuildConfig
368+
369+
# Use cmake --build with proper escaping for Visual Studio generator
370+
cmake --build . --config $BuildConfig --target $Target
369371

370372
if ($LASTEXITCODE -ne 0) {
371373
throw "$DisplayName failed with exit code $LASTEXITCODE"
@@ -418,13 +420,13 @@ function Invoke-CMakeBuild {
418420

419421
Write-Status "Build completed successfully!" -Type Success
420422

421-
# Run install targets if requested
423+
# Run install target if requested
422424
if ($RunLocalInstall) {
423-
Invoke-CMakeTarget -Target 'local_install' -BuildConfig $BuildConfig -DisplayName 'install target (local development layout)'
425+
Invoke-CMakeTarget -Target 'INSTALL' -BuildConfig $BuildConfig -DisplayName 'install target (local development layout)'
424426
}
425427

426428
if ($RunKernelsInstall) {
427-
Invoke-CMakeTarget -Target 'kernels_install' -BuildConfig $BuildConfig -DisplayName 'kernels_install target'
429+
Invoke-CMakeTarget -Target 'INSTALL' -BuildConfig $BuildConfig -DisplayName 'install target'
428430
}
429431
}
430432
finally {

0 commit comments

Comments
 (0)