fix go linking
This commit is contained in:
parent
c599e7cee3
commit
a5964c91e0
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
|
@ -130,6 +130,7 @@ jobs:
|
|||
env:
|
||||
CC: clang
|
||||
run: |
|
||||
update-alternatives --set ld /usr/bin/lld
|
||||
make all
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
13
internal/pkg/all-in-one/handler.go
Normal file
13
internal/pkg/all-in-one/handler.go
Normal 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))
|
||||
}
|
Loading…
Reference in a new issue