Aller Anfang ist schwer.

This commit is contained in:
saces 2026-01-09 18:52:31 +01:00
commit 16f964f41d
5 changed files with 74 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.venv
compose.override.yaml

36
Containerfile.debian Normal file
View file

@ -0,0 +1,36 @@
# syntax=docker/dockerfile:1
ARG GOLANG_VERSION=1.25
ARG DEBIAN_VERSION=trixie
ARG PYTHON_VERSION=3.14
FROM docker.io/library/golang:${GOLANG_VERSION}-${DEBIAN_VERSION} AS gobuilder
RUN --mount=type=bind,source=./libmxclient,target=/build <<EOF
cd /build
CGO_ENABLED=1 GOARCH=${GOARCH} go build -buildmode=c-shared -o /pygomx-build/libmxclient.so .
EOF
FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION} AS pybuilder
COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/libmxclient.so
COPY --from=gobuilder /pygomx-build/libmxclient.h /usr/local/include/libmxclient.h
RUN pip install cffi setuptools
COPY pygomx /pygomx
RUN <<EOF
cd /pygomx
python3 build_ffi.py
ls -la
EOF
FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION}
RUN pip install cffi
COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/
COPY --from=pybuilder /pygomx/_pygomx.cpython-314-x86_64-linux-gnu.so /usr/local/lib/python3.14/site-packages/
RUN ldconfig

3
libmxclient/go.mod Normal file
View file

@ -0,0 +1,3 @@
module mxclientlib
go 1.23.5

View file

@ -0,0 +1,12 @@
package main
import "C"
//export hello
func hello(name *C.char) *C.char {
goName := C.GoString(name)
result := "Hello " + goName
return C.CString(result)
}
func main() {}

21
pygomx/build_ffi.py Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/python
from cffi import FFI
ffibuilder = FFI()
ffibuilder.set_source(
module_name="_pygomx",
source=""" //passed to the real C compiler
#include "libmxclient.h"
""",
libraries=["mxclient"],
)
ffibuilder.cdef(
csource="""
extern char* hello(char* p0);
"""
)
if __name__ == "__main__":
ffibuilder.compile(verbose=True)