diff --git a/Makefile b/Makefile index 6161fab..600cc63 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,21 @@ +# 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) @@ -5,19 +23,21 @@ all: $(DEPS) $(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 \ No newline at end of file diff --git a/README.md b/README.md index 62ae5e8..0f3f683 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/rust/rust-toolchain b/rust/rust-toolchain deleted file mode 100644 index df7007c..0000000 --- a/rust/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2024-04-17-aarch64-apple-darwin \ No newline at end of file