If python had a package management, I would hate it.
This commit is contained in:
parent
8a5bebb254
commit
2eec7b4f5e
8 changed files with 67 additions and 92 deletions
|
|
@ -1 +1 @@
|
|||
include *.so
|
||||
exclude build_ffi.py
|
||||
|
|
|
|||
|
|
@ -1,78 +0,0 @@
|
|||
# set some defaults
|
||||
|
||||
# one of static, shared
|
||||
BUILD_MODE ?= static
|
||||
|
||||
# one of none, colm, goolm, vodozemac
|
||||
OLM_FLAVOR ?= colm
|
||||
|
||||
ifndef GO_TAGS
|
||||
GO_TAGS =
|
||||
else
|
||||
GO_TAGS := $(GO_TAGS),
|
||||
endif
|
||||
|
||||
ifeq ($(OLM_FLAVOR),none)
|
||||
GO_TAGS := $(GO_TAGS)nocrypto
|
||||
else ifeq ($(OLM_FLAVOR),colm)
|
||||
GO_TAGS := $(GO_TAGS)colm
|
||||
else ifeq ($(OLM_FLAVOR),goolm)
|
||||
GO_TAGS := $(GO_TAGS)goolm
|
||||
else ifeq ($(OLM_FLAVOR),vodozemac)
|
||||
GO_TAGS := $(GO_TAGS)vodozemac
|
||||
else
|
||||
$(error unknown OLM_FLAVOR $(OLM_FLAVOR))
|
||||
endif
|
||||
|
||||
|
||||
# calculate configuration matrix
|
||||
|
||||
ifeq ($(BUILD_MODE),static)
|
||||
build_mode_name=c-archive
|
||||
build_mode_ext=a
|
||||
else ifeq ($(BUILD_MODE),shared)
|
||||
build_mode_name=c-shared
|
||||
build_mode_ext=so
|
||||
else
|
||||
$(error unknown BUILD_MODE $(BUILD_MODE))
|
||||
endif
|
||||
|
||||
link_list =
|
||||
|
||||
ifeq ($(BUILD_MODE),static)
|
||||
ifeq ($(OLM_FLAVOR),colm)
|
||||
link_list += olm
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
SOURCE_GO=$(shell find ../libmxclient/ -iname "*.go")
|
||||
|
||||
ifndef GO_OUTDIR
|
||||
GO_OUTDIR = ../pygomx-module
|
||||
endif
|
||||
|
||||
.PHONY:
|
||||
all: _pygomx.o libmxclient.h
|
||||
mkdir -p build/lib
|
||||
cp *.so build/lib
|
||||
|
||||
_pygomx.o: libmxclient.h build_ffi.py
|
||||
python3 build_ffi.py $(link_list)
|
||||
|
||||
libmxclient.h: ../libmxclient/go.mod ../libmxclient/go.sum $(SOURCE_GO)
|
||||
cd ../libmxclient/ && \
|
||||
CGO_ENABLED=1 go build -buildmode=$(build_mode_name) -tags $(GO_TAGS) -o $(GO_OUTDIR)/libmxclient.$(build_mode_ext) .
|
||||
|
||||
.PHONY:
|
||||
clean:
|
||||
@rm -f _pygomx.*
|
||||
@rm -f libmxclient.*
|
||||
@rm -rf dist/
|
||||
@rm -rf build/
|
||||
@rm -rf pygomx_module.egg-info
|
||||
|
||||
.PHONY:
|
||||
install: all
|
||||
python setup.py bdist_wheel
|
||||
python setup.py install
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
import os
|
||||
import sys
|
||||
from cffi import FFI
|
||||
|
||||
|
|
@ -6,8 +7,8 @@ lib_list = [
|
|||
"mxclient",
|
||||
]
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
lib_list += sys.argv[1:]
|
||||
if os.getenv("PYGOMX_LINK_OLM"):
|
||||
lib_list += ["olm"]
|
||||
|
||||
print(f"liblist: {lib_list}")
|
||||
|
||||
|
|
|
|||
17
pygomx-module/pyproject.toml
Normal file
17
pygomx-module/pyproject.toml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=80", "cffi>=2.0.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "pygomx-module"
|
||||
version = "0.0.1"
|
||||
requires-python = ">=3.9"
|
||||
description = "python pindings for a golang matrix library"
|
||||
license = "AGPL-3.0-only"
|
||||
readme = "README.txt"
|
||||
|
||||
dependencies = ["cffi>=2.0.0"]
|
||||
|
||||
[project.urls]
|
||||
homepage = "https://codeberg.org/saces/pygomx"
|
||||
heimseite = "https://code.c-base.org/saces/pygomx"
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
cffi
|
||||
setuptools>=80
|
||||
wheel
|
||||
|
|
@ -1,3 +1,33 @@
|
|||
from setuptools import setup
|
||||
import subprocess
|
||||
from contextlib import suppress
|
||||
from setuptools import Command, setup
|
||||
from setuptools.command.build import build
|
||||
|
||||
setup(name="pygomx-module", version="0.0.1", py_modules=["_pygomx"])
|
||||
|
||||
class CustomCommand(Command):
|
||||
def initialize_options(self) -> None:
|
||||
pass
|
||||
|
||||
def finalize_options(self) -> None:
|
||||
pass
|
||||
|
||||
def run(self) -> None:
|
||||
go_call = [
|
||||
"go",
|
||||
"build",
|
||||
"-buildmode=c-archive",
|
||||
"-o",
|
||||
"../pygomx-module/libmxclient.a",
|
||||
".",
|
||||
]
|
||||
subprocess.call(go_call, cwd="../libmxclient")
|
||||
|
||||
|
||||
class CustomBuild(build):
|
||||
sub_commands = [("build_custom", None)] + build.sub_commands
|
||||
|
||||
|
||||
setup(
|
||||
cffi_modules=["build_ffi.py:ffibuilder"],
|
||||
cmdclass={"build": CustomBuild, "build_custom": CustomCommand},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue