fix go linking

This commit is contained in:
MatthieuCoder 2023-01-16 12:06:41 +04:00
parent c599e7cee3
commit a5964c91e0
4 changed files with 15 additions and 10 deletions

View file

@ -130,6 +130,7 @@ jobs:
env: env:
CC: clang CC: clang
run: | run: |
update-alternatives --set ld /usr/bin/lld
make all make all
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
with: with:

View file

@ -9,7 +9,6 @@ import "C"
import ( import (
"fmt" "fmt"
"time" "time"
"unsafe"
"github.com/Jeffail/gabs" "github.com/Jeffail/gabs"
"github.com/alicebob/miniredis/v2" "github.com/alicebob/miniredis/v2"
@ -22,14 +21,6 @@ type AllInOne struct {
instance *C.AllInOneInstance 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) { func NewAllInOne() (*AllInOne, error) {
redis := miniredis.NewMiniRedis() redis := miniredis.NewMiniRedis()
nats, err := server.NewServer(&server.Options{}) nats, err := server.NewServer(&server.Options{})
@ -55,6 +46,7 @@ func (s *AllInOne) Start() error {
if !s.nats.ReadyForConnections(5 * time.Second) { 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") 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) handler := C.ErrorHandler(C.allInOneErrorHandler)
// Set the error handler // Set the error handler
C.set_error_handler(handler) C.set_error_handler(handler)

View file

@ -2,7 +2,6 @@ extern void goErrorHandler(int, char*);
typedef void (*ErrorHandler)(int, char*); typedef void (*ErrorHandler)(int, char*);
__attribute__((weak))
void allInOneErrorHandler(int size, char* string) { void allInOneErrorHandler(int size, char* string) {
goErrorHandler(size, string); goErrorHandler(size, string);
} }

View file

@ -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))
}