From aad1b2234b832f0ab6615acae280e86fec556648 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Fri, 11 Oct 2019 18:01:02 +0200 Subject: [PATCH] Debug build for ds_ctcdecoder package --- native_client/ctcdecode/Makefile | 16 +++++++++++++++- native_client/ctcdecode/build_common.py | 10 ++++++---- native_client/ctcdecode/setup.py | 10 ++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/native_client/ctcdecode/Makefile b/native_client/ctcdecode/Makefile index 962e917f..c000fc9e 100644 --- a/native_client/ctcdecode/Makefile +++ b/native_client/ctcdecode/Makefile @@ -9,6 +9,12 @@ ifeq ($(TARGET),rpi3-armv8) LDFLAGS_NEEDED += $(RASPBIAN)/lib/aarch64-linux-gnu/libm.so.6 endif +ifeq ($(OS),Darwin) +GENERATE_DEBUG_SYMS := dsymutil temp_build/temp_build/ds_ctcdecoder/_swigwrapper.*.so +else +GENERATE_DEBUG_SYMS := +endif + all: bindings clean-keep-common: @@ -22,5 +28,13 @@ bindings: clean-keep-common pip install --quiet $(PYTHON_PACKAGES) wheel==0.31.0 setuptools==39.1.0 AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py build_ext --num_processes $(NUM_PROCESSES) $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) find temp_build -type f -name "*.o" -delete - AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py bdist_wheel --num_processes $(NUM_PROCESSES) $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) + AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py bdist_wheel $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) + rm -rf temp_build + +bindings-debug: clean-keep-common + pip install --quiet $(PYTHON_PACKAGES) wheel==0.31.0 setuptools==39.1.0 + AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py build_ext --debug --num_processes $(NUM_PROCESSES) $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) + $(GENERATE_DEBUG_SYMS) + find temp_build -type f -name "*.o" -delete + AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py bdist_wheel $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) rm -rf temp_build diff --git a/native_client/ctcdecode/build_common.py b/native_client/ctcdecode/build_common.py index 8bd65811..1965287e 100644 --- a/native_client/ctcdecode/build_common.py +++ b/native_client/ctcdecode/build_common.py @@ -9,8 +9,9 @@ import sys from multiprocessing.dummy import Pool -ARGS = ['-O3', '-DNDEBUG', '-DKENLM_MAX_ORDER=6', '-std=c++11', - '-Wno-unused-local-typedefs', '-Wno-sign-compare'] +ARGS = ['-DKENLM_MAX_ORDER=6', '-std=c++11', '-Wno-unused-local-typedefs', '-Wno-sign-compare'] +OPT_ARGS = ['-O3', '-DNDEBUG'] +DBG_ARGS = ['-O0', '-g', '-UNDEBUG'] INCLUDES = [ '..', @@ -33,11 +34,12 @@ COMMON_FILES = [ COMMON_FILES += glob.glob('*.cpp') -def build_common(out_name='common.a', build_dir='temp_build/temp_build', num_parallel=1): +def build_common(out_name='common.a', build_dir='temp_build/temp_build', debug=False, num_parallel=1): compiler = os.environ.get('CXX', 'g++') ar = os.environ.get('AR', 'ar') libtool = os.environ.get('LIBTOOL', 'libtool') cflags = os.environ.get('CFLAGS', '') + os.environ.get('CXXFLAGS', '') + args = ARGS + (DBG_ARGS if debug else OPT_ARGS) for file in COMMON_FILES: outfile = os.path.join(build_dir, os.path.splitext(file)[0] + '.o') @@ -54,7 +56,7 @@ def build_common(out_name='common.a', build_dir='temp_build/temp_build', num_par cmd = '{cc} -fPIC -c {cflags} {args} {includes} {infile} -o {outfile}'.format( cc=compiler, cflags=cflags, - args=' '.join(ARGS), + args=' '.join(args), includes=' '.join('-I' + i for i in INCLUDES), infile=file, outfile=outfile, diff --git a/native_client/ctcdecode/setup.py b/native_client/ctcdecode/setup.py index c6c256cc..e50cac82 100644 --- a/native_client/ctcdecode/setup.py +++ b/native_client/ctcdecode/setup.py @@ -31,10 +31,11 @@ parser.add_argument( default=1, type=int, help="Number of cpu processes to build package. (default: %(default)d)") -args = parser.parse_known_args() +known_args, unknown_args = parser.parse_known_args() +debug = '--debug' in unknown_args # reconstruct sys.argv to pass to setup below -sys.argv = [sys.argv[0]] + args[1] +sys.argv = [sys.argv[0]] + unknown_args def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() @@ -50,7 +51,8 @@ if not os.path.exists(common_build): build_common(out_name='common.a', build_dir=build_dir, - num_parallel=args[0].num_processes) + num_parallel=known_args.num_processes, + debug=debug) decoder_module = Extension( name='ds_ctcdecoder._swigwrapper', @@ -58,7 +60,7 @@ decoder_module = Extension( swig_opts=['-c++', '-extranative'], language='c++', include_dirs=INCLUDES + [numpy_include], - extra_compile_args=ARGS, + extra_compile_args=ARGS + (DBG_ARGS if debug else OPT_ARGS), extra_link_args=[common_build], )