Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elixir bindings #535

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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 bindings/elixir/.clang-format
4 changes: 4 additions & 0 deletions bindings/elixir/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
29 changes: 29 additions & 0 deletions bindings/elixir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
ckzg-*.tar

# Temporary files, for example, from tests.
/tmp/

.cache/
priv/build.txt
priv/ckzg_nif.so
.clangd
compile_commands.json
83 changes: 83 additions & 0 deletions bindings/elixir/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
CC = clang
PRIV_DIR = $(MIX_APP_PATH)/priv
NIF_SO = $(PRIV_DIR)/ckzg_nif.so
SRC_ROOT = $(shell pwd)
C_SRC = $(SRC_ROOT)/native/src

CFLAGS += -Wall -Wextra -shared -std=c11 -fPIC -I"$(ERTS_INCLUDE_DIR)"
UNAME_S := $(shell uname -s)
ifndef TARGET_ABI
ifeq ($(UNAME_S),Darwin)
TARGET_ABI = darwin
endif
endif

ifeq ($(TARGET_ABI),darwin)
CFLAGS += -undefined dynamic_lookup -flat_namespace -undefined suppress
endif

ifeq ($(OS),Windows_NT)
ifneq (,$(findstring Git/,$(SHELL)))
BLST_BUILDSCRIPT = ./build.bat
else
BLST_BUILDSCRIPT = .\build.bat
endif
BLST_OBJ = blst.lib
LOCATION ?= win-x64
EXTENSION ?= ".dll"
CKZG_LIBRARY_PATH = $(PRIV_DIR)/ckzg_nif$(EXTENSION)

else
BLST_BUILDSCRIPT = ./build.sh
BLST_OBJ = libblst.a
CFLAGS += -fPIC

UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_S),Linux)
EXTENSION ?= ".so"
ifeq ($(UNAME_M),x86_64)
LOCATION ?= linux-x64
else
LOCATION ?= linux-arm64
endif
endif
ifeq ($(UNAME_S),Darwin)
EXTENSION ?= ".dylib"
ifeq ($(UNAME_M),arm64)
LOCATION ?= osx-arm64
else
LOCATION ?= osx-x64
endif
endif

CKZG_LIBRARY_PATH = $(PRIV_DIR)/ckzg_nif$(EXTENSION)
endif

INCLUDE_DIRS = ../../src ../../blst/bindings $(ERTS_INCLUDE_DIR)
TARGETS = $(C_SRC)/ckzg_wrap.c ../../src/ckzg.c ../../blst/$(BLST_OBJ)

CFLAGS += ${addprefix -I,${INCLUDE_DIRS}}
BLST_BUILDSCRIPT_FLAGS += -D__BLST_PORTABLE__
ifdef ARCH
CFLAGS += --target=$(ARCH)
BLST_BUILDSCRIPT_FLAGS += --target=$(ARCH)
endif

ifdef DEBUG
CFLAGS += -g
else
CFLAGS += -O2
endif

.PHONY: all
all: blst ckzg

.PHONY: blst
blst:
cd ../../blst && $(BLST_BUILDSCRIPT) $(BLST_BUILDSCRIPT_FLAGS)

.PHONY: ckzg
ckzg: blst
$(CC) $(CFLAGS) -o $(CKZG_LIBRARY_PATH) $(TARGETS)
@echo "$(CC_PRECOMPILER_CURRENT_TARGET)" > "$(PRIV_DIR)/build.txt"
20 changes: 20 additions & 0 deletions bindings/elixir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# KZG

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `ckzg` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:ckzg, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/kzg>.
Loading