Skip to content

Commit 2c6a91e

Browse files
committed
Fix up python_bindings build
- support run_apps, run_apps_headless without first installing globally. - fix dependencies in basic build rules. - make setup.py support `$BUILD_PREFIX` as used by the main Halide build.
1 parent 678ef1d commit 2c6a91e

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

python_bindings/Makefile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
21
all: halide/cHalide_wrap.cxx halide/_cHalide.so
32

4-
halide/_cHalide.so: halide/*.py halide/cHalide.i ../src/*.cpp ../src/runtime/*.cpp ../src/*.h ../include/*.h halide/py_util.cpp halide/py_util.h halide/expand_types.h
3+
halide/_cHalide.so: halide/cHalide_wrap.cxx halide/*.py halide/cHalide.i ../src/*.cpp ../src/runtime/*.cpp ../src/*.h ../include/*.h halide/py_util.cpp halide/py_util.h halide/expand_types.h setup.py
54
python setup.py build_ext --inplace
65

7-
halide/cHalide_wrap.cxx: halide/cHalide.i ../src/*.cpp ../src/runtime/*.cpp ../src/*.h ../include/*.h halide/py_util.cpp halide/py_util.h halide/expand_types.h
6+
halide/cHalide_wrap.cxx: halide/cHalide.i ../src/*.cpp ../src/runtime/*.cpp ../src/*.h ../include/*.h halide/py_util.cpp halide/py_util.h halide/expand_types.h setup.py
87
make -C ..
98
swig -c++ -python -w362,325,314,389,381,382,361,401,503,509 -I../include halide/cHalide.i
109

11-
install: halide/cHalide_wrap.cxx
10+
install: all
1211
python setup.py install
1312

1413
clean:
@@ -19,18 +18,18 @@ clean:
1918
rm -f halide/cHalide.py halide/*.pyc
2019

2120
run_apps:
22-
python apps/local_laplacian.py
23-
python apps/interpolate.py
24-
python apps/bilateral_grid.py
25-
python apps/erode.py
26-
python apps/blur.py
21+
PYTHONPATH=.:$(PYTHONPATH) python apps/local_laplacian.py
22+
PYTHONPATH=.:$(PYTHONPATH) python apps/interpolate.py
23+
PYTHONPATH=.:$(PYTHONPATH) python apps/bilateral_grid.py
24+
PYTHONPATH=.:$(PYTHONPATH) python apps/erode.py
25+
PYTHONPATH=.:$(PYTHONPATH) python apps/blur.py
2726

2827
run_apps_headless:
29-
python apps/local_laplacian.py apps/out_local_laplacian.png
30-
python apps/interpolate.py apps/out_interpolate.png
31-
python apps/bilateral_grid.py apps/out_bilateral_grid.png
32-
python apps/erode.py apps/out_erode.png
33-
python apps/blur.py apps/out_blur.png
28+
PYTHONPATH=.:$(PYTHONPATH) python apps/local_laplacian.py apps/out_local_laplacian.png
29+
PYTHONPATH=.:$(PYTHONPATH) python apps/interpolate.py apps/out_interpolate.png
30+
PYTHONPATH=.:$(PYTHONPATH) python apps/bilateral_grid.py apps/out_bilateral_grid.png
31+
PYTHONPATH=.:$(PYTHONPATH) python apps/erode.py apps/out_erode.png
32+
PYTHONPATH=.:$(PYTHONPATH) python apps/blur.py apps/out_blur.png
3433

3534
test:
36-
python test_halide.py
35+
PYTHONPATH=.:$(PYTHONPATH) python test_halide.py

python_bindings/setup.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@
66
import subprocess
77
import shutil
88

9+
build_prefix = os.getenv('BUILD_PREFIX')
10+
if not build_prefix:
11+
build_prefix = ''
12+
halide_root = '..'
13+
include_path = os.path.join(halide_root, 'include')
14+
bin_path = os.path.join(halide_root, 'bin', build_prefix)
15+
image_path = os.path.join(halide_root, 'apps', 'images')
16+
917
png_cflags = subprocess.check_output('libpng-config --cflags', shell=True).strip()
1018
png_ldflags = subprocess.check_output('libpng-config --ldflags', shell=True).strip()
1119

1220
ext_modules = [Extension("halide/_cHalide", ["halide/cHalide_wrap.cxx", 'halide/py_util.cpp'],
13-
include_dirs=['../include'],
21+
include_dirs=[include_path],
1422
extra_compile_args=('-ffast-math -O3 -msse -Wl,-dead_strip -fno-common' + ' ' + png_cflags).split(),
15-
extra_link_args=['../bin/libHalide.a', '-lpthread', '-ldl', '-lstdc++', '-lc']+png_ldflags.split(),
23+
extra_link_args=[os.path.join(bin_path, 'libHalide.a'), '-lpthread', '-ldl', '-lstdc++', '-lc']+png_ldflags.split(),
1624
language='c++')]
1725

1826
if glob.glob('halide/data/*.png') == []:
19-
shutil.copytree('../apps/images/', 'halide/data')
27+
shutil.copytree(image_path, 'halide/data')
2028

2129
setup(
2230
name = 'halide',

0 commit comments

Comments
 (0)