diff --git a/apps/CMakePresets.json b/apps/CMakePresets.json index 788ffeb0b6e1..ad199c5e594c 100644 --- a/apps/CMakePresets.json +++ b/apps/CMakePresets.json @@ -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", diff --git a/cmake/PythonExtensionHelpers.cmake b/cmake/HalidePythonExtensionHelpers.cmake similarity index 82% rename from cmake/PythonExtensionHelpers.cmake rename to cmake/HalidePythonExtensionHelpers.cmake index 1433f6557a73..4996c351a683 100644 --- a/cmake/PythonExtensionHelpers.cmake +++ b/cmake/HalidePythonExtensionHelpers.cmake @@ -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") @@ -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" @@ -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) @@ -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 @@ -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() diff --git a/cmake/TargetExportScript.cmake b/cmake/TargetExportScript.cmake index 36e53558aff6..812d0790d3ab 100644 --- a/cmake/TargetExportScript.cmake +++ b/cmake/TargetExportScript.cmake @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.22) + include(CheckLinkerFlag) function(target_export_script TARGET) @@ -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 () diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt index 56c0f770e57f..5982ee532b4c 100644 --- a/packaging/CMakeLists.txt +++ b/packaging/CMakeLists.txt @@ -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) diff --git a/packaging/common/HalideHelpersConfig.cmake b/packaging/common/HalideHelpersConfig.cmake index 739c465fdd55..12fc03556a50 100644 --- a/packaging/common/HalideHelpersConfig.cmake +++ b/packaging/common/HalideHelpersConfig.cmake @@ -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) diff --git a/python_bindings/stub/ext.ldscript.apple.in b/python_bindings/stub/ext.ldscript.apple.in deleted file mode 100644 index 90695315ccd6..000000000000 --- a/python_bindings/stub/ext.ldscript.apple.in +++ /dev/null @@ -1 +0,0 @@ -_PyInit_${SYMBOL} diff --git a/python_bindings/stub/ext.ldscript.linux.in b/python_bindings/stub/ext.ldscript.linux.in deleted file mode 100644 index b426c20b08b8..000000000000 --- a/python_bindings/stub/ext.ldscript.linux.in +++ /dev/null @@ -1,4 +0,0 @@ -{ -global: PyInit_${SYMBOL}; -local: *; -}; diff --git a/python_bindings/test/generators/CMakeLists.txt b/python_bindings/test/generators/CMakeLists.txt index 8fcfb0734601..c552fdfcd257 100644 --- a/python_bindings/test/generators/CMakeLists.txt +++ b/python_bindings/test/generators/CMakeLists.txt @@ -1,4 +1,4 @@ -include(PythonExtensionHelpers) +include(HalidePythonExtensionHelpers) set(GENERATORS addconstant