Skip to content
Snippets Groups Projects
Commit fdc9eb06 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

modules: golang/cgo modules compile, but bad linkage

parent 8125631a
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ int worker_init(struct worker_ctx *worker, mm_ctx_t *mm)
kr_context_register(&worker->resolve, "iterate");
kr_context_register(&worker->resolve, "itercache");
kr_context_register(&worker->resolve, "hints");
kr_context_register(&worker->resolve, "gostats");
return KNOT_EOK;
}
......
......@@ -16,4 +16,5 @@ info:
$(info [$(HAS_libuv)] daemon (libuv))
$(info [$(HAS_cmocka)] unit tests (libcmocka))
$(info [$(HAS_python)] integration tests (libpython))
$(info [$(HAS_gccgo)] golang modules (gccgo))
$(info )
......@@ -60,4 +60,4 @@ void kr_module_unload(struct kr_module *module);
* @param module module name (f.e. hints)
*/
#define KR_MODULE_EXPORT(module) \
uint32_t module ## _api() { return KR_MODULE_API; }
\ No newline at end of file
uint32_t module ## _api() { return KR_MODULE_API; }
......@@ -5,7 +5,7 @@ package gostats
#include "lib/module.h"
extern int gostats_begin(knot_layer_t *, void *);
extern int gostats_finish(knot_layer_t *);
static inline const knot_layer_api_t *_layer(void)
static inline const knot_layer_api_t *_gostats_layer(void)
{
static const knot_layer_api_t _module = {
.begin = &gostats_begin,
......@@ -18,6 +18,18 @@ import "C"
import "unsafe"
import "fmt"
//export gostats_init
func gostats_init(module *C.struct_kr_module) C.int {
fmt.Println("go_init()")
return 0
}
//export gostats_deinit
func gostats_deinit(module *C.struct_kr_module) C.int {
fmt.Println("go_deinit()")
return 0
}
//export gostats_begin
func gostats_begin(ctx *C.knot_layer_t, param unsafe.Pointer) C.int {
fmt.Println("go_begin()")
......@@ -32,5 +44,5 @@ func gostats_finish(ctx *C.knot_layer_t) C.int {
//export gostats_layer
func gostats_layer() *C.knot_layer_api_t {
return C._layer()
return C._gostats_layer()
}
\ No newline at end of file
hints_SOURCES := modules/gostats/gostats.g
gostats_SOURCES := modules/gostats/gostats.go
gostats_DEPEND := libkresolve
gostats_LIBS := $(libkresolve_TARGET) $(libkresolve_LIBS)
$(call make_go_module,gostats)
\ No newline at end of file
# List of built-in modules
modules_TARGETS := hints
# List of Golang modules
$(eval $(call find_bin,gccgo))
ifeq ($(HAS_gccgo),yes)
modules_TARGETS += gostats
endif
# Make C module
define make_c_module
$(eval $(call make_module,$(1),modules/$(1)))
endef
# Go target definition
define go_target
$(1): $(2)/$(1)$(LIBEXT)
$(2)/_obj/_cgo_.o: $$($(1)_SOURCES)
$(INSTALL) -d $(2)/_obj
$(call quiet,CGO,$$^) -gccgo=true -objdir=$(2)/_obj -- $(CFLAGS) $$^
$(2)/_obj/$(1).o: $(2)/_obj/_cgo_.o
$(call quiet,GCCGO,$$@) -fPIC -c $(2)/_obj/*.go
$(2)/$(1)$(LIBEXT): $(2)/_obj/$(1).o $$($(1)_DEPEND)
$(call quiet,GCCGO,$$@) $(CFLAGS) -$(LIBTYPE) -fPIC -Wno-return-type -o $$@ $(2)/_obj/*.o $(2)/_obj/*.c -lgcc $$($(1)_LIBS)
$(1)-clean:
$(RM) -r $(2)/_obj $(2)/$(1)$(LIBEXT)
$(1)-install: $(2)/$(1)$(LIBEXT)
$(INSTALL) -d $(PREFIX)/$(MODULEDIR)
$(INSTALL) $$^ $(PREFIX)/$(MODULEDIR)
.PHONY: $(1) $(1)-clean $(1)-install
endef
# Make Go module
define make_go_module
# TODO: compilable only with gccgo -shared
# go tool cgo -- $(CFLAGS) $$($(1)_SOURCES)
$(eval $(call go_target,$(1),modules/$(1)))
endef
# Build rules
......
# Platform-specific
CCLD := $(CC)
CGO := go tool cgo
GCCGO := gccgo
LIBEXT := .so
MODEXT := $(LIBEXT)
LIBTYPE := shared
......@@ -85,6 +87,16 @@ define find_lib
$(call have_lib,$(1))
endef
# Find binary
define find_bin
ifeq ($$(strip $$($(1)_BIN)),)
HAS_$(1) := $(shell $(1) --version >/dev/null && echo yes || echo no)
else
HAS_$(1) := yes
$(1) := $$($(1)_BIN)
endif
endef
# Find Python
define find_python
python_CFLAGS := $(shell $(PYTHON) -c "from distutils import sysconfig as c;print('-I%s' % c.get_python_inc())")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment