Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial 10 needs to be skipped for Python when targeting Wasm (just as non-Python does) #6932

Merged
merged 3 commits into from
Aug 11, 2022
Merged
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
74 changes: 43 additions & 31 deletions python_bindings/tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,64 @@ set(tests
lesson_14_types.py
)

set(PYPATH_lesson_10_aot_compilation_run "$<TARGET_FILE_DIR:lesson_10_halide>")

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 ()

cmake_path(GET test STEM test_name)
add_python_test(
FILE "${test}"
LABEL python_tutorial
PYTHONPATH "$<TARGET_FILE_DIR:lesson_10_halide>"
PYTHONPATH "${PYPATH_${test_name}}"
)
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that, the packaging stuff below won't be processed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This particular tutorial really just needs to be rewritten to be way less janky; using PyGen when it lands is arguably the right thing, but for now, yuck)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh GitHub's interface was confusing me. I thought this was the end of the file.

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 $<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 $<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
Expand Down