Skip to content

Commit

Permalink
python: expose FEATURES variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Feb 7, 2025
1 parent 5baf921 commit f3e0613
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PY ?= python3

# =====
all: root
root: $(shell find src -type f,l)
root: $(shell find src -type f,l) setup.py
$(info == PY_BUILD ustreamer-*.so)
rm -rf root
$(ECHO) $(PY) -m build --skip-dependency-check --no-isolation
Expand Down
37 changes: 33 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,41 @@


# =====
def _find_sources(suffix: str) -> list[str]:
def _find_sources() -> list[str]:
sources: list[str] = []
for (root_path, _, names) in os.walk("src"):
for name in names:
if name.endswith(suffix):
if name.endswith(".c"):
sources.append(os.path.join(root_path, name))
return sources


def _find_flags() -> dict[str, bool]:
return {
key: bool(int(value))
for (key, value) in sorted(os.environ.items())
if key.startswith("WITH_")
}


def _make_d_flags(flags: dict[str, bool]) -> list[str]:
return [
f"-D{key}"
for (key, value) in flags.items()
if value
]


def _make_d_features(flags: dict[str, bool]) -> str:
features = " ".join([
f"{key}={int(value)}"
for (key, value) in flags.items()
])
return f"-DUS_FEATURES=\"{features}\""


if __name__ == "__main__":
flags = _find_flags()
setup(
name="ustreamer",
version="6.29",
Expand All @@ -26,9 +51,13 @@ def _find_sources(suffix: str) -> list[str]:
Extension(
"ustreamer",
libraries=["rt", "m", "pthread"],
extra_compile_args=["-std=c17", "-D_GNU_SOURCE"],
extra_compile_args=[
"-std=c17", "-D_GNU_SOURCE",
_make_d_features(flags),
*_make_d_flags(flags),
],
undef_macros=["NDEBUG"],
sources=_find_sources(".c"),
sources=_find_sources(),
),
],
)
1 change: 1 addition & 0 deletions python/src/ustreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ PyMODINIT_FUNC PyInit_ustreamer(void) {
ADD(StringConstant, "VERSION", US_VERSION);
ADD(IntConstant, "VERSION_MAJOR", US_VERSION_MAJOR);
ADD(IntConstant, "VERSION_MINOR", US_VERSION_MINOR);
ADD(StringConstant, "FEATURES", US_FEATURES); // Defined in setup.py
ADD(ObjectRef, "Memsink", (PyObject*)&_MemsinkType);
# undef ADD
return module;
Expand Down

0 comments on commit f3e0613

Please sign in to comment.