From 5600b8056baba4fa1cfb75dd55d1f33b156295b7 Mon Sep 17 00:00:00 2001 From: saces Date: Wed, 4 Mar 2026 11:23:54 +0100 Subject: [PATCH] introduce build parameters --- Containerfile.debian | 11 +---------- README.txt | 22 ++++++++++++++++------ pygomx-module/build_ffi.py | 6 +++++- pygomx-module/setup.py | 38 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Containerfile.debian b/Containerfile.debian index c52e22b..07a9c7a 100644 --- a/Containerfile.debian +++ b/Containerfile.debian @@ -25,15 +25,6 @@ FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION} AS pybuilder ENV PYTHONUNBUFFERED=1 ENV PIP_ROOT_USER_ACTION=ignore -RUN <=1.22 and libolm-dev installed + build configuration is done via env vars - (create and activate a venv) + # one of static, shared + PYGOMX_BUILD_MODE=static - cd pygomx-module - pip install . + # one of none, colm, goolm, vodozemac + PYGOMX_OLM_FLAVOR=colm + # for colm you need libolm-dev installed + # vodozemac is not supported yet - cd ../smal - pip install [-e] . + you need go >=1.22 installed + + (create and activate a venv) + + cd pygomx-module + pip install . + + cd ../smal + pip install [-e] . usage: diff --git a/pygomx-module/build_ffi.py b/pygomx-module/build_ffi.py index a7eed44..15d9267 100644 --- a/pygomx-module/build_ffi.py +++ b/pygomx-module/build_ffi.py @@ -7,7 +7,11 @@ lib_list = [ "mxclient", ] -if os.getenv("PYGOMX_LINK_OLM"): +# keep defaults in sync with setup.py +if ( + os.getenv("PYGOMX_BUILD_MODE", "static") == "static" + and os.getenv("PYGOMX_OLM_FLAVOR", colm) == "colm" +): lib_list += ["olm"] print(f"liblist: {lib_list}") diff --git a/pygomx-module/setup.py b/pygomx-module/setup.py index 33c7a48..dbbc7ae 100644 --- a/pygomx-module/setup.py +++ b/pygomx-module/setup.py @@ -1,3 +1,4 @@ +import os import subprocess from contextlib import suppress from setuptools import Command, setup @@ -12,12 +13,45 @@ class CustomCommand(Command): pass def run(self) -> None: + # configure the go build via env vars + # keep defaults in sync with build_ffi.py + go_tags_str = os.getenv("PYGOMX_GO_TAGS") + if go_tags_str and len(go_tags_str.strip()) > 0: + go_tags = go_tags_str.split(",") + else: + go_tags = [] + + match os.getenv("PYGOMX_BUILD_MODE", "static"): + case "static": + build_mode_name = "c-archive" + build_mode_ext = ".a" + case "shared": + build_mode_name = "c-shared" + build_mode_ext = ".so" + case _: + raise ValueError("Invalid PYGOMX_BUILD_MODE.") + + match os.getenv("PYGOMX_OLM_FLAVOR", "colm"): + case "none": + go_tags += ["nocrypto"] + case "colm": + go_tags += ["colm"] + case "goolm": + go_tags += ["goolm"] + case "vodozemac": + go_tags += ["vodozemac"] + raise ValueError("Vodozemac not supported (yet).") + case _: + raise ValueError("Invalid PYGOMX_OLM_FLAVOR.") + go_call = [ "go", "build", - "-buildmode=c-archive", + f"-buildmode=${build_mode_name}", + "-tags", + ",".join(go_tags), "-o", - "../pygomx-module/libmxclient.a", + f"../pygomx-module/libmxclient${build_mode_ext}", ".", ] subprocess.call(go_call, cwd="../libmxclient")