Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
RUSTFLAGS := RUSTFLAGS='-C link-arg=-s'
BUILD_CMD := cargo build --release

.PHONY: all clean clean-all

golib: rustlib header
go build

rustlib: libzkgroup-amd64 libzkgroup-arm64 libzkgroup-armhf

libzkgroup-amd64:
cd lib/zkgroup && \
$(RUSTFLAGS) $(BUILD_CMD)
cp lib/zkgroup/target/release/libzkgroup.a lib/libzkgroup_linux_amd64.a

libzkgroup-arm64:
cd lib/zkgroup && \
$(RUSTFLAGS) CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-unknown-linux-gnu-gcc $(BUILD_CMD) --target=aarch64-unknown-linux-gnu
cp lib/zkgroup/target/aarch64-unknown-linux-gnu/release/libzkgroup.a lib/libzkgroup_linux_arm64.a

libzkgroup-armhf:
cd lib/zkgroup && \
$(RUSTFLAGS) CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=armv7l-unknown-linux-gnueabihf-gcc $(BUILD_CMD) --target=armv7-unknown-linux-gnueabihf
cp lib/zkgroup/target/armv7-unknown-linux-gnueabihf/release/libzkgroup.a lib/libzkgroup_linux_armhf.a

header:
cbindgen --lang c lib/zkgroup/rust -o lib/zkgroup.h

clean:
go clean
cd lib/zkgroup && \
cargo clean

clean-all: clean
rm lib/*.a
rm lib/*.h
63 changes: 46 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,62 @@ Go library for the Signal Private Group System.

See [github.com/signalapp/zkgroup](https://github.com/signalapp/zkgroup).

# build zkgroup
## Build the Rust library

- checkout git submodules
-
### Build environment

# cross compile
### With [Nix](https://nixos.org/)

`cargo install cross`
`cd lib/zkgroup/`
Simply enter the Nix shell:

## linux aarch64
$ nix-shell

Alternatively, if you are also using [direnv](https://direnv.net/), you can
allow the `.envrc` to enter automatically the Nix shell whenever you enter the
project:

`cross build --target aarch64-unknown-linux-gnu`
$ direnv allow

`cp target/aarch64-unknown-linux-gnu/debug/libzkgroup.so ../libzkgroup_linux_aarch64.so`
### Without Nix

In order to build the Rust library for all three supported platform, you’ll
first need [Rustup](https://rustup.rs/).

## linux,armhf
Then, install the stable Rust toolchain:

`cross build --target armv7-unknown-linux-gnueabihf`
`cp target/armv7-unknown-linux-gnueabihf/debug/libzkgroup.so ../libzkgroup_linux_armhf.so`
$ rustup install stable

or install arm-linux-gnueabihf-gcc and
Install the targets for the mobile platforms:

```
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc
$ rustup target add aarch64-unknown-linux-gnu
$ rustup target add armv7-unknown-linux-gnueabihf

cargo build --target armv7-unknown-linux-gnueabihf --release --verbose
```
Install C compilers for these targets. Instructions depend on your distribution,
but you should have `aarch64-unknown-linux-gnu-gcc` and
`armv7l-unknown-linux-gnueabihf-gcc` in your path.

Install `cbindgen` to generate the C header for the Rust FFI:

$ cargo install cbindgen

### Build instructions

1. Fetch the submodule, if not already done:

$ git submodule init
$ git submodule update

2. Build the library:

$ make

This will build the Rust library into a static library for `amd64`, `arm64` and
`armhf` on Linux, put them in `lib/` and generate `lib/zkgroup.h`.

3. Clean the Rust articafcts:

$ make clean

You can also remove the generated files by running:

$ make clean-all
6 changes: 3 additions & 3 deletions auth_credential.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package zkgroup

/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armhf
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_armhf

#include "lib/zkgroup.h"
*/
Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package zkgroup

/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armhf
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_armhf

#include "lib/zkgroup.h"
*/
Expand Down
6 changes: 3 additions & 3 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package zkgroup

/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armhf
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_armhf

#include "lib/zkgroup.h"
*/
Expand Down
6 changes: 3 additions & 3 deletions group.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package zkgroup

/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armhf
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib -ldl -lzkgroup_linux_armhf

#include "lib/zkgroup.h"
*/
Expand Down
Binary file renamed lib/libzkgroup_linux_arm64.so → lib/libzkgroup_linux_amd64.a
100755 → 100644
Binary file not shown.
Binary file removed lib/libzkgroup_linux_amd64.so
Binary file not shown.
Binary file added lib/libzkgroup_linux_arm64.a
Binary file not shown.
Binary file added lib/libzkgroup_linux_armhf.a
Binary file not shown.
Binary file removed lib/libzkgroup_linux_armhf.so
Binary file not shown.
Loading