open-quantum-safe / liboqs-go

Go bindings for liboqs
https://openquantumsafe.org/
MIT License
69 stars 24 forks source link

Link liboqs statically #25

Closed stv0g closed 5 months ago

stv0g commented 1 year ago

Does liboqs-go support static linking against liboqs?

I would like to build a statically linked Go executable without external depdendencies..

stv0g commented 1 year ago

Here is an example as used by go-rosenpass: https://github.com/stv0g/go-rosenpass/commit/fb93e83dbddd92b60da5feef68f5d0230d4a3684

vsoftco commented 1 year ago

@stv0g Thanks, I'll look into it this week

vsoftco commented 10 months ago

@stv0g The only way to link statically is a bit hacky.

In the cgo preamble of oqs.go, immediately after the line https://github.com/open-quantum-safe/liboqs-go/blob/e3e87437a36ce5f154ad38f81b11278187c896a5/oqs/oqs.go#L5 add the line #cgo LDFLAGS: /usr/local/liboqs.a (of course with the path corresponding to your location of liboqs.a). Make sure you don't add any additional new line(s).

Next, comment (add a # in front of) the last line of .config/liboqs.pc (the line starting with Libs:), i.e., https://github.com/open-quantum-safe/liboqs-go/blob/e3e87437a36ce5f154ad38f81b11278187c896a5/.config/liboqs.pc#L9

Finally, do a go clean -cache to force pkg-config to use the updated liboqs.pc.

As far as I know, there's no elegant way of statically linking by only modifying the liboqs.pc file.

vsoftco commented 5 months ago

Fixed by #37