Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/control.top.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Build-Depends:
psmisc,
python3,
python3-dev,
python3-pybind11,
python3-tk,
python3-xlib,
tcl,
Expand Down
18 changes: 18 additions & 0 deletions lib/python/hal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,28 @@

import _hal
from _hal import *
from _hal import query
import sys
import warnings
import lcnc_realtime

# _hal exports the IntEnum tagging classes as 'type' and 'dir'. The
# star import binds them here, but those names shadow the builtins used
# inside this module, so unbind them and serve them lazily through
# __getattr__ instead. hal.type.REAL, hal.dir.IN and the HALType/HALDir
# class names (also consulted by pickle) all resolve to the shared
# classes in _hal.
globals().pop('type', None)
globals().pop('dir', None)

# _hal.query is a submodule, not a plain attribute. Registering it in
# sys.modules under its dotted name makes 'import hal.query' and
# 'from hal import query' work as they would for a real package.
sys.modules['hal.query'] = query

def __getattr__(name):
if name in ('type', 'dir', 'HALType', 'HALDir'):
return getattr(_hal, {'HALType': 'type', 'HALDir': 'dir'}.get(name, name))
if name == 'is_rt':
warnings.warn(f"{name} is deprecated, use lcnc_realtime.verify() instead", FutureWarning, stacklevel=2)
return lcnc_realtime.verify()
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ build-software: headers $(INFILES)
#
SRCHEADERS := \
hal/hal.h \
hal/hal.hh \
hal/halenum.hh \
hal/drivers/mesa-hostmot2/hostmot2-serial.h \
emc/linuxcnc.h \
emc/kinematics/kinematics.h \
Expand Down
30 changes: 30 additions & 0 deletions src/hal/Submakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
../include/hal.h: ./hal/hal.h
cp $^ $@

# hal.hh is the C++ interface on top of the public C API
../include/hal.hh: ./hal/hal.hh
cp $^ $@

# halenum.hh builds the shared Python IntEnum tagging classes
../include/halenum.hh: ./hal/halenum.hh
cp $^ $@

HALLIBSRCS := hal/hal_lib.c hal/hal_lib_query.c hal/hal_lib_extra.c $(ULAPISRCS)
$(call TOOBJSDEPS, $(HALLIBSRCS)): EXTRAFLAGS += -fPIC $(ULAPI_CFLAGS)
USERSRCS += $(HALLIBSRCS)
Expand All @@ -28,5 +36,27 @@ $(HALMODULE): $(call TOOBJS, $(HALMODULESRCS)) $(HALLIB)
$(ECHO) Linking python module $(notdir $@)
$(Q)$(CXX) $(LDFLAGS) -shared -o $@ $^

# pybind11 C++ bindings (hal.hh based)
# setps_util.c only exists in the tree with the HAL query API
# pybind11 headers: python3-pybind11 (system include) or pip user site.
# Without them the bindings are skipped, not failed: they are optional
# until the build dependency is made mandatory.
PYBIND11INCLUDES := $(shell $(PYTHON) -m pybind11 --includes 2>/dev/null)
ifneq ($(PYBIND11INCLUDES),)
HALPPSRCS := hal/halpybind.cc $(wildcard hal/utils/setps_util.c)
PYSRCS += $(HALPPSRCS)

$(call TOOBJS, $(HALPPSRCS)): EXTRAFLAGS += $(PYBIND11INCLUDES)

HALPP := ../lib/python/halpp.so
$(HALPP): $(call TOOBJS, $(HALPPSRCS)) $(HALLIB)
$(ECHO) Linking python module $(notdir $@)
$(Q)$(CXX) $(LDFLAGS) -shared -o $@ $^

PYTARGETS += $(HALPP)
else
$(info NOTE: pybind11 headers not found, skipping the halpp bindings (install python3-pybind11))
endif

TARGETS += $(HALLIB) ../lib/liblinuxcnchal.so.0
PYTARGETS += $(HALMODULE)
Loading
Loading