From b4c4da1289f49b02e34b3cc03d38d68c444741c4 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 10 Aug 2022 17:24:40 -0700 Subject: [PATCH 1/3] Tutorial 10 needs to be skipped for Python when targeting Wasm (just as non-Python does) --- python_bindings/tutorial/CMakeLists.txt | 73 ++++++++++++++----------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/python_bindings/tutorial/CMakeLists.txt b/python_bindings/tutorial/CMakeLists.txt index da1a55fd2a86..80eeec92ecc5 100644 --- a/python_bindings/tutorial/CMakeLists.txt +++ b/python_bindings/tutorial/CMakeLists.txt @@ -16,52 +16,63 @@ set(tests lesson_14_types.py ) +set(PYPATH_lesson_10_aot_compilation_generate "$") + foreach (test IN LISTS tests) + if (TARGET_WEBASSEMBLY AND Halide_TARGET MATCHES "wasm" AND test MATCHES "lesson_10") + message(WARNING "Not all tutorials build under WASM.") + continue() + endif () + add_python_test( FILE "${test}" LABEL python_tutorial - PYTHONPATH "$" + PYTHONPATH "${PYPATH_${test}}" ) endforeach () -## Add some hacks for getting CMake to delay compiling lesson_10_halide until after the test has run. The "better" way -## of doing this might be to treat lesson 10 like an app and give it its own CMakeLists.txt, but since this is a one-off -## it is probably less maintenance work to do it like this. +if (TARGET_WEBASSEMBLY AND Halide_TARGET MATCHES "wasm") + message(WARNING "Not all tutorials build under WASM.") +else () + ## Add some hacks for getting CMake to delay compiling lesson_10_halide until after the test has run. The "better" way + ## of doing this might be to treat lesson 10 like an app and give it its own CMakeLists.txt, but since this is a one-off + ## it is probably less maintenance work to do it like this. -# Note that the following tests that are mentioned below were created in the above foreach loop: -# 1. python_tutorial_lesson_10_aot_compilation_generate -# 2. python_tutorial_lesson_10_aot_compilation_run -# The test `python_tutorial_lesson_10_compile` below is responsible for running (1) in service of (2). + # Note that the following tests that are mentioned below were created in the above foreach loop: + # 1. python_tutorial_lesson_10_aot_compilation_generate + # 2. python_tutorial_lesson_10_aot_compilation_run + # The test `python_tutorial_lesson_10_compile` below is responsible for running (1) in service of (2). -# This dummy command "generates" the files that the TEST python_tutorial_lesson_10_aot_compilation_generate will -# actually generate as part of the fixture below. -add_custom_command(OUTPUT lesson_10_halide.py.cpp lesson_10_halide.o - COMMAND "${CMAKE_COMMAND}" -E echo Dummy command for lesson 10 sources. - VERBATIM) + # This dummy command "generates" the files that the TEST python_tutorial_lesson_10_aot_compilation_generate will + # actually generate as part of the fixture below. + add_custom_command(OUTPUT lesson_10_halide.py.cpp lesson_10_halide.o + COMMAND "${CMAKE_COMMAND}" -E echo Dummy command for lesson 10 sources. + VERBATIM) -# This target allows CMake to build lesson_10_halide.so (or whatever the correct extension is) as part of the tests -# later. It is excluded from ALL since it isn't valid to build outside of this context. -Python3_add_library(lesson_10_halide MODULE EXCLUDE_FROM_ALL - lesson_10_halide.py.cpp - lesson_10_halide.o) + # This target allows CMake to build lesson_10_halide.so (or whatever the correct extension is) as part of the tests + # later. It is excluded from ALL since it isn't valid to build outside of this context. + Python3_add_library(lesson_10_halide MODULE EXCLUDE_FROM_ALL + lesson_10_halide.py.cpp + lesson_10_halide.o) -target_link_libraries(lesson_10_halide PRIVATE Halide::Runtime) + target_link_libraries(lesson_10_halide PRIVATE Halide::Runtime) -# The fixture "py_lesson_10" orchestrates running the generator part of the lesson first, then the build for the -# library, and finally runs python_tutorial_lesson_10_aot_compilation_run. The ..._compile test invokes CMake on -# the current build for the above library. -add_test(NAME python_tutorial_lesson_10_compile - COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config $ --target lesson_10_halide) + # The fixture "py_lesson_10" orchestrates running the generator part of the lesson first, then the build for the + # library, and finally runs python_tutorial_lesson_10_aot_compilation_run. The ..._compile test invokes CMake on + # the current build for the above library. + add_test(NAME python_tutorial_lesson_10_compile + COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config $ --target lesson_10_halide) -set_tests_properties(python_tutorial_lesson_10_aot_compilation_generate PROPERTIES - FIXTURES_SETUP py_lesson_10) + set_tests_properties(python_tutorial_lesson_10_aot_compilation_generate PROPERTIES + FIXTURES_SETUP py_lesson_10) -set_tests_properties(python_tutorial_lesson_10_compile PROPERTIES - FIXTURES_SETUP py_lesson_10 - DEPENDS python_tutorial_lesson_10_aot_compilation_generate) + set_tests_properties(python_tutorial_lesson_10_compile PROPERTIES + FIXTURES_SETUP py_lesson_10 + DEPENDS python_tutorial_lesson_10_aot_compilation_generate) -set_tests_properties(python_tutorial_lesson_10_aot_compilation_run PROPERTIES - FIXTURES_REQUIRED py_lesson_10) + set_tests_properties(python_tutorial_lesson_10_aot_compilation_run PROPERTIES + FIXTURES_REQUIRED py_lesson_10) +endif () ## # Packaging From 50452228f4342abf01c98aa124626d85679cdc8f Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 10 Aug 2022 17:32:24 -0700 Subject: [PATCH 2/3] fixes --- python_bindings/tutorial/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python_bindings/tutorial/CMakeLists.txt b/python_bindings/tutorial/CMakeLists.txt index 80eeec92ecc5..ca72978a410b 100644 --- a/python_bindings/tutorial/CMakeLists.txt +++ b/python_bindings/tutorial/CMakeLists.txt @@ -24,10 +24,11 @@ foreach (test IN LISTS tests) continue() endif () + cmake_path(GET test STEM test_name) add_python_test( FILE "${test}" LABEL python_tutorial - PYTHONPATH "${PYPATH_${test}}" + PYTHONPATH "${PYPATH_${test_name}}" ) endforeach () From de34a7270a98264f1154b42286a6d03ff52e2ea7 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Thu, 11 Aug 2022 09:46:40 -0700 Subject: [PATCH 3/3] Update CMakeLists.txt --- python_bindings/tutorial/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_bindings/tutorial/CMakeLists.txt b/python_bindings/tutorial/CMakeLists.txt index ca72978a410b..3c2bcb674060 100644 --- a/python_bindings/tutorial/CMakeLists.txt +++ b/python_bindings/tutorial/CMakeLists.txt @@ -16,7 +16,7 @@ set(tests lesson_14_types.py ) -set(PYPATH_lesson_10_aot_compilation_generate "$") +set(PYPATH_lesson_10_aot_compilation_run "$") foreach (test IN LISTS tests) if (TARGET_WEBASSEMBLY AND Halide_TARGET MATCHES "wasm" AND test MATCHES "lesson_10")