Skip to content

cmake build, configurable from env #2115

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions cmake/cmake_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def build_extension(self, ext: setuptools.extension.Extension):
print(f"Setting PYTHON_EXECUTABLE to {sys.executable}")
cmake_args += f" -DPYTHON_EXECUTABLE={sys.executable}"

cmake_args += extra_cmake_args
# putting `cmake_args` from env variable ${SHERPA_ONNX_CMAKE_ARGS} last,
# so they can onverride the "defaults" stored in `extra_cmake_args`
cmake_args = extra_cmake_args + cmake_args

if is_windows():
build_cmd = f"""
Expand Down Expand Up @@ -216,12 +218,18 @@ def build_extension(self, ext: setuptools.extension.Extension):
if not src_file.is_file():
src_file = install_dir / ".." / (f + suffix)

if not src_file.is_file():
continue

print(f"Copying {src_file} to {out_bin_dir}/")
shutil.copy(f"{src_file}", f"{out_bin_dir}/")

shutil.rmtree(f"{install_dir}/bin")
shutil.rmtree(f"{install_dir}/share")
shutil.rmtree(f"{install_dir}/lib/pkgconfig")
if Path(f"{install_dir}/bin").is_dir():
shutil.rmtree(f"{install_dir}/bin")
if Path(f"{install_dir}/share").is_dir():
shutil.rmtree(f"{install_dir}/share")
if Path(f"{install_dir}/lib/pkgconfig").is_dir():
shutil.rmtree(f"{install_dir}/lib/pkgconfig")

if is_macos():
os.remove(f"{install_dir}/lib/libonnxruntime.dylib")
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def get_package_version():


def get_binaries_to_install():
cmake_args = os.environ.get("SHERPA_ONNX_CMAKE_ARGS", "")
if '-DSHERPA_ONNX_ENABLE_BINARY=OFF' in cmake_args:
return None

bin_dir = Path("build") / "sherpa_onnx" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
suffix = ".exe" if is_windows() else ""
Expand All @@ -69,7 +73,7 @@ def get_binaries_to_install():
"sherpa_onnx": "sherpa-onnx/python/sherpa_onnx",
},
packages=["sherpa_onnx"],
data_files=[("bin", get_binaries_to_install())],
data_files=[("bin", get_binaries_to_install())] if get_binaries_to_install() else None,
url="https://github.com/k2-fsa/sherpa-onnx",
long_description=read_long_description(),
long_description_content_type="text/markdown",
Expand Down
3 changes: 0 additions & 3 deletions sherpa-onnx/csrc/parse-options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ static bool MustBeQuoted(const std::string &str, ShellType st) {
// pasted into a shell of ShellType "st" (only bash for now), it
// will get passed to the program in the same way.
static std::string QuoteAndEscape(const std::string &str, ShellType /*st*/) {
// Only Bash is supported (for the moment).
SHERPA_ONNX_CHECK_EQ(st, kBash) << "Invalid shell type.";

// For now we use the following rules:
// In the normal case, we quote with single-quote "'", and to escape
// a single-quote we use the string: '\'' (interpreted as closing the
Expand Down
Loading