Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Add build flags to fix macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 17, 2023
1 parent 49ce1f5 commit 60b9a45
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
5 changes: 0 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ variables:
BUILDER_IMAGE: dock.mau.dev/tulir/gomuks-build-docker/signal
BINARY_NAME: mautrix-signal

# TODO re-enable after macOS builds are fixed
build macos arm64:
rules:
- when: never

# 32-bit arm builds aren't supported
build arm:
rules:
Expand Down
2 changes: 1 addition & 1 deletion pkg/libsignalgo/authcredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ReceiveAuthCredentialWithPni(
if err != nil {
return nil, err
}
var c_pni *[17]C.uint8_t
var c_pni cPNIType
if len(pni) != 16 {
c_pni = nil
} else {
Expand Down
13 changes: 5 additions & 8 deletions pkg/libsignalgo/serviceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,29 @@ import (

type UUID [C.SignalUUID_LEN]byte

// func SignalServiceIdFromUUID(uuid UUID) (*C.SignalServiceIdFixedWidthBinaryBytes, error) {
// The function signature should be as above, but we must hack around a gcc bug, not needed for clang
// https://github.com/golang/go/issues/7270
func SignalServiceIdFromUUID(uuid UUID) (*[17]C.uint8_t, error) {
func SignalServiceIdFromUUID(uuid UUID) (cPNIType, error) {
var result C.SignalServiceIdFixedWidthBinaryBytes
signalFfiError := C.signal_service_id_parse_from_service_id_binary(&result, BytesToBuffer(uuid[:]))
if signalFfiError != nil {
return nil, wrapError(signalFfiError)
}
return (*[17]C.uint8_t)(unsafe.Pointer(&result)), nil
return cPNIType(unsafe.Pointer(&result)), nil
}

func SignalPNIServiceIdFromUUID(uuid UUID) (*[17]C.uint8_t, error) {
func SignalPNIServiceIdFromUUID(uuid UUID) (cPNIType, error) {
var result C.SignalServiceIdFixedWidthBinaryBytes
// Prepend a 0x01 to the UUID to indicate that it is a PNI UUID
pniUUID := append([]byte{0x01}, uuid[:]...)
signalFfiError := C.signal_service_id_parse_from_service_id_binary(&result, BytesToBuffer(pniUUID))
if signalFfiError != nil {
return nil, wrapError(signalFfiError)
}
return (*[17]C.uint8_t)(unsafe.Pointer(&result)), nil
return cPNIType(unsafe.Pointer(&result)), nil
}

func SignalServiceIdToUUID(serviceId *C.SignalServiceIdFixedWidthBinaryBytes) (UUID, error) {
result := C.SignalOwnedBuffer{}
serviceIdBytes := (*[17]C.uchar)(unsafe.Pointer(serviceId)) // Hack around gcc bug, not needed for clang
serviceIdBytes := cPNIType(unsafe.Pointer(serviceId)) // Hack around gcc bug, not needed for clang
signalFfiError := C.signal_service_id_service_id_binary(&result, serviceIdBytes)
if signalFfiError != nil {
return UUID{}, wrapError(signalFfiError)
Expand Down
12 changes: 12 additions & 0 deletions pkg/libsignalgo/serviceid_clang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build darwin

package libsignalgo

/*
#cgo LDFLAGS: -lsignal_ffi -ldl
#include "./libsignal-ffi.h"
#include <stdlib.h>
*/
import "C"

type cPNIType = *C.SignalServiceIdFixedWidthBinaryBytes
15 changes: 15 additions & 0 deletions pkg/libsignalgo/serviceid_gcc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !darwin

package libsignalgo

/*
#cgo LDFLAGS: -lsignal_ffi -ldl
#include "./libsignal-ffi.h"
#include <stdlib.h>
*/
import "C"

// Hack for https://github.com/golang/go/issues/7270
// The clang version is more correct, but doesn't work with gcc

type cPNIType = *[17]C.uint8_t

0 comments on commit 60b9a45

Please sign in to comment.