Skip to content

Commit 7c71bda

Browse files
committed
Go/Core Refactore: Move FFI to a dedicated folder to be reusable for other wrappers
Signed-off-by: barshaul <[email protected]>
1 parent bd36cfa commit 7c71bda

14 files changed

+764
-56
lines changed

.github/workflows/ffi.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Glide FFI CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release-*
8+
- v*
9+
paths:
10+
- glide-core/src/**
11+
- glide-core/redis-rs/redis/src/**
12+
- ffi/**
13+
pull_request:
14+
paths:
15+
- glide-core/src/**
16+
- glide-core/redis-rs/redis/src/**
17+
- ffi/**
18+
workflow_call:
19+
20+
concurrency:
21+
group: ffi-${{ github.head_ref || github.ref }}-${{ toJson(inputs) }}
22+
cancel-in-progress: true
23+
24+
env:
25+
CARGO_TERM_COLOR: always
26+
27+
jobs:
28+
build-and-gen-c:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Install Rust and protoc
33+
uses: ./.github/workflows/install-rust-and-protoc
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build the FFI library
38+
working-directory: ffi
39+
run: |
40+
cargo build --release
41+
- name: Generate the C header file
42+
working-directory: ffi
43+
run: |
44+
cargo install cbindgen
45+
cbindgen --config cbindgen.toml --crate glide_ffi --output lib.h --lang c

.github/workflows/go-cd.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,14 @@ jobs:
119119
working-directory: go
120120
run: |
121121
make install-build-tools
122-
make build-glide-client
123-
# TODO: move generation of protobuf and header file to a non-matrix step
124-
make generate-protobuf
122+
make build
125123
- name: Upload artifacts
126124
continue-on-error: true
127125
uses: actions/upload-artifact@v4
128126
with:
129127
name: ${{ matrix.host.TARGET }}
130128
path: |
131-
go/target/release/libglide_rs.a
129+
ffi/target/release/libglide_ffi.a
132130
go/lib.h
133131
go/protobuf/
134132
@@ -149,7 +147,7 @@ jobs:
149147
for dir in */; do
150148
target_name=${dir%/}
151149
mkdir -p $GITHUB_WORKSPACE/go/rustbin/${target_name}
152-
cp ${target_name}/target/release/libglide_rs.a $GITHUB_WORKSPACE/go/rustbin/${target_name}/
150+
cp ${target_name}/target/release/libglide_ffi.a $GITHUB_WORKSPACE/go/rustbin/${target_name}/
153151
done
154152
# TODO: move generation of protobuf and header file to a non-matrix step
155153
cd x86_64-unknown-linux-gnu

.github/workflows/go.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
paths:
1010
- glide-core/src/**
1111
- glide-core/redis-rs/redis/src/**
12+
- ffi/src/**
1213
- utils/cluster_manager.py
1314
- go/**
1415
- .github/workflows/go.yml
@@ -22,6 +23,7 @@ on:
2223
paths:
2324
- glide-core/src/**
2425
- glide-core/redis-rs/redis/src/**
26+
- ffi/src/**
2527
- utils/cluster_manager.py
2628
- go/**
2729
- .github/workflows/go.yml
@@ -133,11 +135,6 @@ jobs:
133135
steps:
134136
- uses: actions/checkout@v4
135137

136-
- uses: ./.github/workflows/lint-rust
137-
with:
138-
cargo-toml-folder: go
139-
github-token: ${{ secrets.GITHUB_TOKEN }}
140-
141138
- name: Set up Go ${{ matrix.go }}
142139
uses: actions/setup-go@v5
143140
with:

.github/workflows/rust.yml

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- logger_core/**
1111
- glide-core/**
1212
- glide-core/redis-rs/redis/src/**
13+
- ffi/**
1314
- utils/cluster_manager.py
1415
- .github/workflows/rust.yml
1516
- .github/workflows/install-shared-dependencies/action.yml
@@ -23,6 +24,7 @@ on:
2324
- logger_core/**
2425
- glide-core/**
2526
- glide-core/redis-rs/redis/src/**
27+
- ffi/**
2628
- utils/cluster_manager.py
2729
- .github/workflows/rust.yml
2830
- .github/workflows/install-shared-dependencies/action.yml
@@ -127,6 +129,12 @@ jobs:
127129
github-token: ${{ secrets.GITHUB_TOKEN }}
128130
name: lint glide-core
129131

132+
- uses: ./.github/workflows/lint-rust
133+
with:
134+
cargo-toml-folder: ./ffi
135+
github-token: ${{ secrets.GITHUB_TOKEN }}
136+
name: lint glide-ffi
137+
130138
- uses: ./.github/workflows/lint-rust
131139
with:
132140
cargo-toml-folder: ./logger_core

go/.cargo/config.toml ffi/.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[env]
2-
GLIDE_NAME = { value = "GlideGo", force = true }
2+
GLIDE_NAME = { value = "GlideFFI", force = true }
33
GLIDE_VERSION = "0.1.0"
44
# Suppress error
55
# > ... was built for newer 'macOS' version (14.5) than being linked (14.0)

ffi/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cbindgen generated header file
2+
lib.h

go/Cargo.toml ffi/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "glide-rs"
2+
name = "glide-ffi"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
@@ -9,10 +9,10 @@ authors = ["Valkey GLIDE Maintainers"]
99
crate-type = ["staticlib"]
1010

1111
[dependencies]
12-
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tokio-rustls-comp"] }
12+
protobuf = { version = "3", features = [] }
13+
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "tokio-rustls-comp"] }
1314
glide-core = { path = "../glide-core", features = ["proto"] }
1415
tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] }
15-
protobuf = { version = "3.3.0", features = [] }
1616

1717
[profile.release]
1818
lto = true

ffi/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# glide_ffi
2+
3+
## Overview
4+
5+
The glide_ffi crate provides a C-compatible Foreign Function Interface (FFI) for interacting with `glide-core`. It serves as a bridge for internal wrappers written in other languages, such as Go, to integrate seamlessly with `glide-core`.
6+
7+
## Structure
8+
• src/lib.rs: Defines the FFI interface.
9+
• cbindgen.toml: Configuration for generating the C header file (lib.h).
10+
• Cargo.toml: Manages dependencies, including glide-core.
11+
12+
## Building the Library
13+
14+
To build the FFI library:
15+
```
16+
cargo build --release
17+
```
18+
19+
To generate the C header file:
20+
```
21+
cargo install cbindgen
22+
cbindgen --config cbindgen.toml --crate glide_ffi --output lib.h --lang c
23+
```
24+
25+
## Running the linters
26+
27+
```bash
28+
rustup component add clippy rustfmt
29+
cargo clippy --all-features --all-targets -- -D warnings
30+
cargo fmt --manifest-path ./Cargo.toml --all
31+
```

go/cbindgen.toml ffi/cbindgen.toml

File renamed without changes.

0 commit comments

Comments
 (0)