Support building ctc_decoder wheel package on Windows system
This commit is contained in:
parent
5740d64e6e
commit
d7cca2a791
|
@ -15,14 +15,22 @@ else
|
||||||
GENERATE_DEBUG_SYMS :=
|
GENERATE_DEBUG_SYMS :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(findstring _NT,$(OS)),_NT)
|
||||||
|
FIRST_PARTY := first_party.lib
|
||||||
|
THIRD_PARTY := third_party.lib
|
||||||
|
else
|
||||||
|
FIRST_PARTY := first_party.a
|
||||||
|
THIRD_PARTY := third_party.a
|
||||||
|
endif
|
||||||
|
|
||||||
all: bindings
|
all: bindings
|
||||||
|
|
||||||
clean-keep-third-party:
|
clean-keep-third-party:
|
||||||
rm -rf dist temp_build ds_ctcdecoder.egg-info
|
rm -rf dist temp_build ds_ctcdecoder.egg-info
|
||||||
rm -f swigwrapper_wrap.cpp swigwrapper.py first_party.a
|
rm -f swigwrapper_wrap.cpp swigwrapper.py $(FIRST_PARTY)
|
||||||
|
|
||||||
clean: clean-keep-third-party
|
clean: clean-keep-third-party
|
||||||
rm -f third_party.a
|
rm -f $(THIRD_PARTY)
|
||||||
rm workspace_status.cc
|
rm workspace_status.cc
|
||||||
rm -fr bazel-out/
|
rm -fr bazel-out/
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,23 @@ import sys
|
||||||
|
|
||||||
from multiprocessing.dummy import Pool
|
from multiprocessing.dummy import Pool
|
||||||
|
|
||||||
ARGS = ['-DKENLM_MAX_ORDER=6', '-std=c++11', '-Wno-unused-local-typedefs', '-Wno-sign-compare']
|
if sys.platform.startswith('win'):
|
||||||
OPT_ARGS = ['-O3', '-DNDEBUG']
|
ARGS = ['/nologo', '/D KENLM_MAX_ORDER=6', '/EHsc', '/source-charset:utf-8']
|
||||||
DBG_ARGS = ['-O0', '-g', '-UNDEBUG', '-DDEBUG']
|
OPT_ARGS = ['/O2', '/MT', '/D NDEBUG']
|
||||||
|
DBG_ARGS = ['/Od', '/MTd', '/Zi', '/U NDEBUG', '/D DEBUG']
|
||||||
|
OPENFST_DIR = 'third_party/openfst-1.6.9-win'
|
||||||
|
else:
|
||||||
|
ARGS = ['-DKENLM_MAX_ORDER=6', '-std=c++11', '-Wno-unused-local-typedefs', '-Wno-sign-compare']
|
||||||
|
OPT_ARGS = ['-O3', '-DNDEBUG']
|
||||||
|
DBG_ARGS = ['-O0', '-g', '-UNDEBUG', '-DDEBUG']
|
||||||
|
OPENFST_DIR = 'third_party/openfst-1.6.7'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INCLUDES = [
|
INCLUDES = [
|
||||||
'..',
|
'..',
|
||||||
'../kenlm',
|
'../kenlm',
|
||||||
'third_party/openfst-1.6.7/src/include',
|
OPENFST_DIR + '/src/include',
|
||||||
'third_party/ThreadPool'
|
'third_party/ThreadPool'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -24,7 +33,7 @@ KENLM_FILES = (glob.glob('../kenlm/util/*.cc')
|
||||||
+ glob.glob('../kenlm/lm/*.cc')
|
+ glob.glob('../kenlm/lm/*.cc')
|
||||||
+ glob.glob('../kenlm/util/double-conversion/*.cc'))
|
+ glob.glob('../kenlm/util/double-conversion/*.cc'))
|
||||||
|
|
||||||
KENLM_FILES += glob.glob('third_party/openfst-1.6.7/src/lib/*.cc')
|
KENLM_FILES += glob.glob(OPENFST_DIR + '/src/lib/*.cc')
|
||||||
|
|
||||||
KENLM_FILES = [
|
KENLM_FILES = [
|
||||||
fn for fn in KENLM_FILES
|
fn for fn in KENLM_FILES
|
||||||
|
@ -59,6 +68,17 @@ def build_archive(srcs=[], out_name='', build_dir='temp_build/temp_build', debug
|
||||||
if os.path.exists(outfile):
|
if os.path.exists(outfile):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
cmd = '"{cc}" -c {cflags} {args} {includes} {infile} -Fo"{outfile}"'.format(
|
||||||
|
cc=compiler,
|
||||||
|
cflags=cflags,
|
||||||
|
args=' '.join(args),
|
||||||
|
includes=' '.join('-I' + i for i in INCLUDES),
|
||||||
|
infile=file,
|
||||||
|
outfile=outfile,
|
||||||
|
)
|
||||||
|
cmd = cmd.replace('\\', '/')
|
||||||
|
else:
|
||||||
cmd = '{cc} -fPIC -c {cflags} {args} {includes} {infile} -o {outfile}'.format(
|
cmd = '{cc} -fPIC -c {cflags} {args} {includes} {infile} -o {outfile}'.format(
|
||||||
cc=compiler,
|
cc=compiler,
|
||||||
cflags=cflags,
|
cflags=cflags,
|
||||||
|
@ -82,6 +102,15 @@ def build_archive(srcs=[], out_name='', build_dir='temp_build/temp_build', debug
|
||||||
)
|
)
|
||||||
print(cmd)
|
print(cmd)
|
||||||
subprocess.check_call(shlex.split(cmd))
|
subprocess.check_call(shlex.split(cmd))
|
||||||
|
elif sys.platform.startswith('win'):
|
||||||
|
obj_files = [s for s in obj_files if s != None]
|
||||||
|
cmd = '"lib.exe" /OUT:"{outfile}" {infiles} /MACHINE:X64 /NOLOGO'.format(
|
||||||
|
ar=ar,
|
||||||
|
outfile=out_name,
|
||||||
|
infiles=' '.join(obj_files))
|
||||||
|
cmd = cmd.replace('\\', '/')
|
||||||
|
print(cmd)
|
||||||
|
subprocess.check_call(shlex.split(cmd))
|
||||||
else:
|
else:
|
||||||
cmd = '{ar} rcs {outfile} {infiles}'.format(
|
cmd = '{ar} rcs {outfile} {infiles}'.format(
|
||||||
ar=ar,
|
ar=ar,
|
||||||
|
|
|
@ -54,8 +54,12 @@ def maybe_rebuild(srcs, out_name, build_dir):
|
||||||
project_version = read('../../VERSION').strip()
|
project_version = read('../../VERSION').strip()
|
||||||
|
|
||||||
build_dir = 'temp_build/temp_build'
|
build_dir = 'temp_build/temp_build'
|
||||||
third_party_build = 'third_party.a'
|
if sys.platform.startswith('win'):
|
||||||
ctc_decoder_build = 'first_party.a'
|
third_party_build = 'third_party.lib'
|
||||||
|
ctc_decoder_build = 'first_party.lib'
|
||||||
|
else:
|
||||||
|
third_party_build = 'third_party.a'
|
||||||
|
ctc_decoder_build = 'first_party.a'
|
||||||
|
|
||||||
maybe_rebuild(KENLM_FILES, third_party_build, build_dir)
|
maybe_rebuild(KENLM_FILES, third_party_build, build_dir)
|
||||||
maybe_rebuild(CTC_DECODER_FILES, ctc_decoder_build, build_dir)
|
maybe_rebuild(CTC_DECODER_FILES, ctc_decoder_build, build_dir)
|
||||||
|
|
Loading…
Reference in New Issue