summaryrefslogtreecommitdiff
path: root/wrappers/python/setup.py
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2025-09-24 13:47:01 +0200
committerjwijenbergh <jwijenbergh@noreply.codeberg.org>2025-09-24 13:53:38 +0200
commit2a41e2e31aa2887812e2cb00f913992e7106e8de (patch)
treef8c79c3a1a8fc826cc6a23dbf09f2074ccc55b3d /wrappers/python/setup.py
parentab1326fc9a3fc25160659bd3dadaf0e5ed1fb2e4 (diff)
Python: Optionally build SO file in setup.py
Diffstat (limited to 'wrappers/python/setup.py')
-rw-r--r--wrappers/python/setup.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py
index 6068493..086d8c0 100644
--- a/wrappers/python/setup.py
+++ b/wrappers/python/setup.py
@@ -1,3 +1,38 @@
+import os
+import subprocess
+
from setuptools import setup
+from setuptools.command.build_py import build_py
+
+COMMON_VERSION = "3.0.0"
+SETUP_PATH = os.path.abspath(__file__)
+COMMON_EXPORTS_PATH = os.path.abspath(os.path.join(SETUP_PATH, "../../../exports"))
+
+
+class CommonBuild(build_py):
+ def run(self):
+ if os.environ.get("EDUVPN_COMMON_BUILD_SO", "0") == "1":
+ try:
+ subprocess.run(
+ [
+ "go",
+ "build",
+ "-o",
+ f"eduvpn_common/lib/libeduvpn_common-{COMMON_VERSION}.so",
+ "-buildmode=c-shared",
+ COMMON_EXPORTS_PATH,
+ ],
+ env={**os.environ, "CGO_ENABLED": "1"},
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ except subprocess.CalledProcessError as e:
+ print("eduvpn-common build failed with exit code:", e.returncode)
+ print("standard output:", e.stdout)
+ print("error output:", e.stderr)
+ raise
+ super().run()
+
-setup()
+setup(cmdclass={"build_py": CommonBuild})