Skip to content
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
38 changes: 29 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
# Determine the OS
UNAME_S := $(shell uname -s)

# Rust toolchain and target
ifeq ($(UNAME_S),Darwin)
RUST_TOOLCHAIN := nightly-2024-04-17
RUST_TARGET := aarch64-apple-darwin
else ifeq ($(UNAME_S),Linux)
RUST_TOOLCHAIN := nightly
RUST_TARGET := x86_64-unknown-linux-gnu
else
$(error Unsupported OS: $(UNAME_S))
endif

# variables
RUST_TARGET_DIR := ./rust/target/$(RUST_TARGET)/release
CGO_DIR := ./cgo
LIB_INSTALL_DIR := /usr/local/lib
DEPS:=ezkl-ffi.h libezkl-ffi.a

all: $(DEPS)
.PHONY: all

$(DEPS): .install-ezkl-ffi ;

# Compile the Rust library and generate the required files
.install-ezkl-ffi: rust
cd rust && cargo build --release --all; cd ..
find ./rust/target/release -type f -name "ezkl-ffi.h" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} cp {} ./cgo/ezkl-ffi.h
find ./rust/target/release -type f -name "libezkl_ffi.a" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} cp {} ./cgo/libezkl_ffi.a
find ./rust/target/release -type f -name "libezkl_ffi.a" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} sudo cp {} /usr/local/lib/libezkl_ffi.a
rustup override set $(RUST_TOOLCHAIN)
cd rust && cargo build --release --target $(RUST_TARGET) --all; cd ..
find $(RUST_TARGET_DIR) -type f -name "ezkl-ffi.h" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} cp {} $(CGO_DIR)/ezkl-ffi.h
find $(RUST_TARGET_DIR) -type f -name "libezkl_ffi.a" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} cp {} $(CGO_DIR)/libezkl_ffi.a
find $(RUST_TARGET_DIR) -type f -name "libezkl_ffi.a" -print0 | xargs -0 ls -t | head -n 1 | xargs -I {} sudo cp {} $(LIB_INSTALL_DIR)/libezkl_ffi.a
c-for-go --ccincl ezkl-ffi.yml
@touch $@

clean:
rm -rf $(DEPS) .install-ezkl-ffi
rm -rf ./rust/target/release/build/ezkl-ffi-*
rm -rf cgo/*.go
rm -rf cgo/*.h
rm -rf cgo/*.a
sudo rm /usr/local/lib/libezkl_ffi.a
rm -rf $(RUST_TARGET_DIR)/build/ezkl-ffi-*
rm -rf $(CGO_DIR)/*.go
rm -rf $(CGO_DIR)/*.h
rm -rf $(CGO_DIR)/*.a
sudo rm -f $(LIB_INSTALL_DIR)/libezkl_ffi.a
.PHONY: clean
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# EZKL FFI

C and CGO bindings for the EZKL library.

# Setup
## Requirements

1. **Go and `c-for-go`:**
- Install Go.
- Install `c-for-go` using the following command:
```bash
go install github.com/xlab/c-for-go@latest
```
- Ensure that `$GOPATH/bin` is added to your `$PATH`.

2. **Rust Toolchain:**
- With the actual version, we require the nightly Rust toolchain to be installed.

## Setup

1. To compile the library and copy it to `LIBRARY_PATH` so the library can be found by compilers, run:
```bash
make

1. Install `c-for-go`: `go get github.com/xlab/c-for-go` (Make sure `$GOPATH` is added to your `$PATH` env variable)
2. Run `make` - this will compile the library and copy it to `LIBRARY_PATH` so the library can be found by compilers.
2. To clean up the generated files, run:
```bash
make clean
1 change: 0 additions & 1 deletion rust/rust-toolchain

This file was deleted.