signal icon indicating copy to clipboard operation
signal copied to clipboard

Compilation errors in pkg/libsignalgo due to CFixedBytes() type mismatch

Open Dr-Deep opened this issue 8 months ago • 1 comments

When building the Go wrapper (pkg/libsignalgo), I encounter multiple errors like:

cannot use NewACIServiceID(aci).CFixedBytes() (value of pointer type cPNIType) 
       as *_Ctype_SignalServiceIdFixedWidthBinaryBytes in variable declaration

It appears that CFixedBytes() currently returns a *cPNIType, whereas the C functions expect a *_Ctype_SignalServiceIdFixedWidthBinaryBytes. This mismatch was introduced by a recent change in the libsignal bridge code.

Steps to Reproduce:

  1. Clone the repository and checkout the main branch (or tag v0.8.1).
    git clone https://github.com/mautrix/signal.git
    cd signal
    
  2. Initialize and update submodules:
    git submodule update --init --recursive
    
  3. Build the Rust bridge:
    cd rust/bridge
    cargo build --release
    
  4. Return to the project root and build the Go wrapper:
    cd ../../
    CGO_CFLAGS="-I/usr/local/include" CGO_LDFLAGS="-L/usr/local/lib" go build ./pkg/libsignalgo
    
  5. Observe the compilation errors as shown above.

Expected Behavior:
pkg/libsignalgo should compile successfully, with CFixedBytes() returning the correct pointer type (*C.SignalServiceIdFixedWidthBinaryBytes) so that the C FFI calls match their signatures.

Environment:

  • OS: HardenedBSD (FreeBSD fork)
  • Go: go1.20.4 freebsd/amd64
  • Rust: rustc 1.70.0
  • Submodule (libsignal) pinned at: efe13e9b363d2c115dba61b76e5e53bbfc2874bc (pre-breaking change)
  • Repo tag: v0.8.1 (Commit 03d675c)

Workaround:
Manually pinning the libsignal submodule to the pre-update commit (efe13e9b…) restores compatibility and allows the build to succeed.

Proposed Fix:

  1. Update CFixedBytes() in pkg/libsignalgo to explicitly return *C.SignalServiceIdFixedWidthBinaryBytes (for example, via an unsafe.Pointer cast).
  2. Alternatively, adjust the underlying C type definitions in the libsignal bridge so they remain compatible with the existing Go bindings.

Thank you for your help!

Dr-Deep avatar Apr 21 '25 17:04 Dr-Deep

There haven't been any breaking changes. efe13e9b is the last commit of upstream libsignal, so not sure how you figured it's "pre-breaking change"

The bridge just doesn't currently support using clang outside macOS. Support for that could perhaps be added using a custom build tag, or assuming that gcc is only used on linux (see serviceid_gcc.go)

Other notes:

  • Compiling the bridge with anything else than the pinned libsignal version is completely unsupported, so you should never change it yourself. The release notes also include the expected libsignal version for your convenience.
  • v0.8.1 is not the latest release. Old releases are completely unsupported.
  • Go 1.20 is EOL and can't be used to compile the bridge: https://endoflife.date/go
  • Rust 1.70 is quite old too, it's best to use the version that upstream libsignal has pinned https://github.com/signalapp/libsignal/blob/main/rust-toolchain

tulir avatar Apr 21 '25 17:04 tulir