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

refactor: Replace connor package with rust implementation #2555

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/start-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Checkout code into the directory
uses: actions/checkout@v3

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ crash.log

# Ignore .zip files, such as Lambda Function code slugs.
**.zip

# Ignore compiled dynamic libraries.
libs/*.so
libs/*.dylib
libs/*.dll
47 changes: 45 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@ else ifeq ($(OS_GENERAL),Windows)
OS_PACKAGE_MANAGER := choco
endif

# Directory where binaries will be placed
BIN_DIR := ./libs

# Set the library file name based on the operating system
ifeq ($(OS_GENERAL),Linux)
LIB_EXT := .so
endif
ifeq ($(OS_GENERAL),Darwin)
LIB_EXT := .dylib
endif
ifeq ($(OS_GENERAL),Windows)
LIB_EXT := .dll
endif

RUST_REPO_URL := [email protected]:sourcenetwork/defradb-rs.git
#RUST_REPO_URL := https://github.com/sourcenetwork/defradb-rs.git
RUST_REPO_BRANCH := main
RUST_DIR := ./build/defradb-rs

# Initialize the Rust library by checking out the repository and compiling the library.
.PHONY: init
init_rust: checkout_rust compile_rust

# Checkout the Rust repository if it doesn't exist, otherwise pull the latest changes.
.PHONY: checkout_rust
checkout_rust: $(BIN_DIR)
@if [ -d "$(RUST_DIR)" ]; then \
cd $(RUST_DIR) && git pull; \
else \
git clone --branch $(RUST_REPO_BRANCH) $(RUST_REPO_URL) $(RUST_DIR); \
fi

# Compile the Rust library and copy it to the libs directory.
.PHONY: compile_rust
compile_rust: $(BIN_DIR)
cargo build --release --manifest-path=$(RUST_DIR)/Cargo.toml
cp $(RUST_DIR)/target/release/libabi$(LIB_EXT) $(BIN_DIR)/libabi$(LIB_EXT)

# Provide info from git to the version package using linker flags.
ifeq (, $(shell which git))
$(error "No git in $(PATH), version information won't be included")
Expand Down Expand Up @@ -95,7 +133,7 @@ endif
# - make build
# - make build path="path/to/defradb-binary"
.PHONY: build
build:
build: init_rust
ifeq ($(path),)
@go build $(BUILD_FLAGS) -o build/defradb cmd/defradb/main.go
else
Expand Down Expand Up @@ -205,7 +243,7 @@ tidy:
go mod tidy -go=1.21.3

.PHONY: clean
clean:
clean: clean\:rust
go clean cmd/defradb/main.go
rm -f build/defradb

Expand All @@ -218,6 +256,11 @@ clean\:coverage:
rm -rf $(COVERAGE_DIRECTORY)
rm -f $(COVERAGE_FILE)

.PHONY: clean\:rust
clean\:rust:
cargo clean --manifest-path=${RUST_DIR}/Cargo.toml
rm -f $(BIN_DIR)/*$(LIB_EXT)

# Example: `make tls-certs path="~/.defradb/certs"`
.PHONY: tls-certs
tls-certs:
Expand Down
4 changes: 4 additions & 0 deletions internal/connor/connor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ func Match(conditions map[FilterKey]any, data any) (bool, error) {
return eq(conditions, data)
}

func MatchJSON(conditions, data string) (bool, error) {
return callMatchConditionsABI(conditions, data)
}

// matchWith can be used to specify the exact operator to use when performing
// a match operation. This is primarily used when building custom operators or
// if you wish to override the behavior of another operator.
Expand Down
Loading
Loading