From a5964c91e018acaef22896f1e4357181df838dd2 Mon Sep 17 00:00:00 2001 From: MatthieuCoder Date: Mon, 16 Jan 2023 12:06:41 +0400 Subject: [PATCH] fix go linking --- .github/workflows/build.yml | 1 + internal/pkg/all-in-one/all-in-one.go | 10 +--------- internal/pkg/all-in-one/error_handler.h | 1 - internal/pkg/all-in-one/handler.go | 13 +++++++++++++ 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 internal/pkg/all-in-one/handler.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2bb06e..1f9073f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -130,6 +130,7 @@ jobs: env: CC: clang run: | + update-alternatives --set ld /usr/bin/lld make all - uses: actions/upload-artifact@v3 with: diff --git a/internal/pkg/all-in-one/all-in-one.go b/internal/pkg/all-in-one/all-in-one.go index 76c11f2..b95d515 100644 --- a/internal/pkg/all-in-one/all-in-one.go +++ b/internal/pkg/all-in-one/all-in-one.go @@ -9,7 +9,6 @@ import "C" import ( "fmt" "time" - "unsafe" "github.com/Jeffail/gabs" "github.com/alicebob/miniredis/v2" @@ -22,14 +21,6 @@ type AllInOne struct { instance *C.AllInOneInstance } -//export goErrorHandler -func goErrorHandler(size C.int, start *C.char) { - dest := make([]byte, size) - copy(dest, (*(*[1024]byte)(unsafe.Pointer(start)))[:size:size]) - - println("Error from all in one runner: %s", string(dest)) -} - func NewAllInOne() (*AllInOne, error) { redis := miniredis.NewMiniRedis() nats, err := server.NewServer(&server.Options{}) @@ -55,6 +46,7 @@ func (s *AllInOne) Start() error { if !s.nats.ReadyForConnections(5 * time.Second) { return fmt.Errorf("nats server didn't start after 5 seconds, please check if there is another service listening on the same port as nats") } + handler := C.ErrorHandler(C.allInOneErrorHandler) // Set the error handler C.set_error_handler(handler) diff --git a/internal/pkg/all-in-one/error_handler.h b/internal/pkg/all-in-one/error_handler.h index e04f68d..8fe1a60 100644 --- a/internal/pkg/all-in-one/error_handler.h +++ b/internal/pkg/all-in-one/error_handler.h @@ -2,7 +2,6 @@ extern void goErrorHandler(int, char*); typedef void (*ErrorHandler)(int, char*); -__attribute__((weak)) void allInOneErrorHandler(int size, char* string) { goErrorHandler(size, string); } \ No newline at end of file diff --git a/internal/pkg/all-in-one/handler.go b/internal/pkg/all-in-one/handler.go new file mode 100644 index 0000000..b92493e --- /dev/null +++ b/internal/pkg/all-in-one/handler.go @@ -0,0 +1,13 @@ +package allinone + +import "C" +import "unsafe" + +//go:linkname goErrorHandler c.goErrorHandler +//export goErrorHandler +func goErrorHandler(size C.int, start *C.char) { + dest := make([]byte, size) + copy(dest, (*(*[1024]byte)(unsafe.Pointer(start)))[:size:size]) + + println("Error from all in one runner: %s", string(dest)) +} -- 2.39.5