Skip to content

Conversation

@alireza-nobakht
Copy link
Collaborator

@alireza-nobakht alireza-nobakht commented Jul 14, 2025

Automate Rust FFI Build & Improve Cross-Platform Support

Summary

This PR adds a new script build_ffi.sh to automate:

  • Cloning or updating the Rust repo valkey-glide
  • Building the Rust FFI shared library (.so on Linux, .dylib on macOS) via cargo build --release
  • Copying the compiled shared library into the Ruby gem’s lib/valkey folder

Why?

The Rust shared library must be rebuilt and copied manually before, which is error-prone and tedious. This script simplifies and automates that, keeping the library up-to-date locally.


Prerequisites

Rust toolchain (includes cargo)

Install via official Rust installer:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

Protocol Buffers compiler (protoc)

Required by the Rust build process. On macOS, install with:

brew install protobuf

How to run

From your valkey-glide-ruby gem root, run:

./build_ffi.sh

This will clone/update Rust repo, build the FFI shared library, and copy it to your gem folder.

Important: Cargo.toml change needed

To support building a dynamic shared library for Ruby FFI, the Rust crate’s Cargo.toml (in ffi/) must include:

[lib]
crate-type = ["cdylib"]

Currently it only builds static libs (staticlib, rlib), which are incompatible with Ruby FFI.

I’m happy to prepare a PR for this change in the Rust repo if the maintainers agree.

Signed-off-by: Alireza Nobakht <[email protected]>
@alireza-nobakht alireza-nobakht force-pushed the feature-macos-shared-object branch from d56fd42 to be8e862 Compare July 15, 2025 13:52
@mohsen-alizadeh mohsen-alizadeh self-requested a review July 16, 2025 20:44
@mohsen-alizadeh mohsen-alizadeh marked this pull request as draft July 17, 2025 13:37
@mohsen-alizadeh mohsen-alizadeh changed the title adding macos shared object WIP adding macos shared object Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants