Skip to content
Merged
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
63 changes: 53 additions & 10 deletions apps/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,86 @@
},
"configurePresets": [
{
"name": "default",
"name": "base",
"hidden": true,
"binaryDir": "build/${presetName}",
"installDir": "install/${presetName}"
"binaryDir": "${sourceDir}/../build/apps/${presetName}"
},
{
"name": "ci",
"hidden": true,
"inherits": "default",
"inherits": "base",
"toolchainFile": "${sourceDir}/../cmake/toolchain.${presetName}.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "debug",
"inherits": "base",
"displayName": "Debug",
"description": "Debug build with no special settings",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "base",
"displayName": "Release",
"description": "Release build with no special settings",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-x64-asan",
"inherits": "ci",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled",
"cacheVariables": {
"LLVM_ROOT": "$penv{LLVM_ROOT}",
"ENABLE_APPS_BGU": "OFF"
"LLVM_ROOT": "$penv{LLVM_ROOT}"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug",
"displayName": "Debug",
"description": "Debug build with no special settings"
},
{
"name": "release",
"configurePreset": "release",
"displayName": "Release",
"description": "Release build with no special settings"
},
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled",
"environment": {
"ASAN_OPTIONS": "detect_leaks=0:detect_container_overflow=0"
}
"description": "Build everything with ASAN enabled"
}
],
"testPresets": [
{
"name": "debug",
"configurePreset": "debug",
"displayName": "Debug",
"description": "Test everything with Debug build",
"output": {
"outputOnFailure": true
}
},
{
"name": "release",
"configurePreset": "release",
"displayName": "Release",
"description": "Test everything with Release build",
"output": {
"outputOnFailure": true
}
},
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include(HalideGeneratorHelpers)
include(TargetExportScript)
cmake_minimum_required(VERSION 3.22)

include(${CMAKE_CURRENT_LIST_DIR}/HalideGeneratorHelpers.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/TargetExportScript.cmake)

set(_STUB_DIR "${Halide_SOURCE_DIR}/python_bindings/stub")

Expand Down Expand Up @@ -28,9 +30,13 @@ set(_STUB_DIR "${Halide_SOURCE_DIR}/python_bindings/stub")
# suffixed with "_stub" for Stub extensions. (TODO: this is unsatisfyingly hackish; better suggestions
# would be welcome.)

function(target_export_single_symbol TARGET SYMBOL)
configure_file("${_STUB_DIR}/ext.ldscript.apple.in" "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.ldscript.apple")
configure_file("${_STUB_DIR}/ext.ldscript.linux.in" "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.ldscript")
function(_target_export_single_symbol TARGET SYMBOL)
file(WRITE
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.ldscript.apple"
"_${SYMBOL}\n")
file(WRITE
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.ldscript"
"{ global: ${SYMBOL}; local: *; };\n")
target_export_script(
${TARGET}
APPLE_LD "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.ldscript.apple"
Expand Down Expand Up @@ -73,20 +79,10 @@ function(add_python_aot_extension TARGET)
PARAMS ${ARG_PARAMS}
TARGETS cmake)

# Take the native-code output of the Generator, add the Python-Extension
# code (to make it callable from Python), and build it into the AOT Extension we need.
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
# Add soabi info (like cpython-310-x86_64-linux-gnu)
# when CMake is new enough to know how to do it.
set(abi_flags WITH_SOABI)
else ()
set(abi_flags "")
endif ()

Python3_add_library(${TARGET} MODULE ${abi_flags} ${${TARGET}.py.cpp})
Python3_add_library(${TARGET} MODULE WITH_SOABI ${${TARGET}.py.cpp})
target_link_libraries(${TARGET} PRIVATE aot_${TARGET})
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${ARG_FUNCTION_NAME})
target_export_single_symbol(${TARGET} ${ARG_FUNCTION_NAME})
_target_export_single_symbol(${TARGET} "PyInit_${ARG_FUNCTION_NAME}")
endfunction()

function(add_python_stub_extension TARGET)
Expand All @@ -109,7 +105,7 @@ function(add_python_stub_extension TARGET)
#
# Note that we set HALIDE_PYSTUB_MODULE_NAME to $*_stub (e.g. foo_stub) but
# set HALIDE_PYSTUB_GENERATOR_NAME to the unadorned name of the Generator.
Python3_add_library(${TARGET} MODULE ${_STUB_DIR}/PyStub.cpp ${ARG_SOURCES})
Python3_add_library(${TARGET} MODULE WITH_SOABI ${_STUB_DIR}/PyStub.cpp ${ARG_SOURCES})
set_target_properties(${TARGET} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
Expand All @@ -119,5 +115,5 @@ function(add_python_stub_extension TARGET)
"HALIDE_PYSTUB_MODULE_NAME=${ARG_MODULE}")
target_link_libraries(${TARGET} PRIVATE Halide::PyStubs ${ARG_LINK_LIBRARIES})
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${ARG_MODULE})
target_export_single_symbol(${TARGET} ${ARG_MODULE})
_target_export_single_symbol(${TARGET} "PyInit_${ARG_MODULE}")
endfunction()
14 changes: 8 additions & 6 deletions cmake/TargetExportScript.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.22)

include(CheckLinkerFlag)

function(target_export_script TARGET)
Expand All @@ -19,19 +21,19 @@ function(target_export_script TARGET)
endif ()

## More linkers support the GNU syntax (ld, lld, gold), so try it first.
check_linker_flag(CXX "LINKER:--version-script=${ARG_GNU_LD}" LINKER_HAS_FLAG_VERSION_SCRIPT)

set(VERSION_SCRIPT_FLAG "LINKER:--version-script=${ARG_GNU_LD}")
check_linker_flag(CXX "${VERSION_SCRIPT_FLAG}" LINKER_HAS_FLAG_VERSION_SCRIPT)
if (LINKER_HAS_FLAG_VERSION_SCRIPT)
target_link_options(${TARGET} PRIVATE "${version_script}")
target_link_options(${TARGET} PRIVATE "${VERSION_SCRIPT_FLAG}")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_GNU_LD}")
return()
endif ()

## The Apple linker expects a different flag.
check_linker_flag(CXX "LINKER:-exported_symbols_list,${ARG_APPLE_LD}" LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST)

set(EXPORTED_SYMBOLS_FLAG "LINKER:-exported_symbols_list,${ARG_APPLE_LD}")
check_linker_flag(CXX "${EXPORTED_SYMBOLS_FLAG}" LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST)
if (LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST)
target_link_options(${TARGET} PRIVATE "${exported_symbols_list}")
target_link_options(${TARGET} PRIVATE "${EXPORTED_SYMBOLS_FLAG}")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_APPLE_LD}")
return()
endif ()
Expand Down
2 changes: 2 additions & 0 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/HalideHelpersConfigVersion.cmake
${Halide_SOURCE_DIR}/cmake/HalideGeneratorHelpers.cmake
${Halide_SOURCE_DIR}/cmake/HalideTargetHelpers.cmake
${Halide_SOURCE_DIR}/cmake/HalidePythonExtensionHelpers.cmake
${Halide_SOURCE_DIR}/cmake/TargetExportScript.cmake
DESTINATION ${Halide_INSTALL_HELPERSDIR}
COMPONENT Halide_Development)

Expand Down
2 changes: 2 additions & 0 deletions packaging/common/HalideHelpersConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ find_dependency(Threads)
include(${CMAKE_CURRENT_LIST_DIR}/Halide-Interfaces.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/HalideTargetHelpers.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/HalideGeneratorHelpers.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/HalidePythonExtensionHelpers.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/TargetExportScript.cmake)
1 change: 0 additions & 1 deletion python_bindings/stub/ext.ldscript.apple.in

This file was deleted.

4 changes: 0 additions & 4 deletions python_bindings/stub/ext.ldscript.linux.in

This file was deleted.

2 changes: 1 addition & 1 deletion python_bindings/test/generators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(PythonExtensionHelpers)
include(HalidePythonExtensionHelpers)

set(GENERATORS
addconstant
Expand Down