Skip to content

Commit

Permalink
Support homebrew
Browse files Browse the repository at this point in the history
Add homebrew script to support installing cpp-rust-driver to macOS.
  • Loading branch information
syuu1228 committed Jun 3, 2024
1 parent 6b2e2ab commit b7af7e3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
46 changes: 46 additions & 0 deletions dist/homebrew/cpp-rust-driver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "formula"

class CppRustDriver < Formula
homepage "https://github.com/scylladb/cpp-rust-driver"
head "https://github.com/scylladb/cpp-rust-driver.git", branch: "master"

depends_on "openssl"
depends_on "rust"

def install
cass_header = File.open('include/cassandra.h').read()
version_major = cass_header.match(/^#define CASS_VERSION_MAJOR (.+)$/)[1]
version_minor = cass_header.match(/^#define CASS_VERSION_MINOR (.+)$/)[1]
version_patch = cass_header.match(/^#define CASS_VERSION_PATCH (.+)$/)[1]
version = "#{version_major}.#{version_minor}.#{version_patch}"
puts version

ENV["RUSTFLAGS"] = "-Clink-arg=-Wl,-install_name,#{lib}/libscylla-cpp-driver.#{version_major}.dylib -Clink-arg=-Wl,-current_version,#{version} -Clink-arg=-Wl,-compatibility_version,#{version_major}"
chdir "scylla-rust-wrapper" do
system "cargo", "build", "--profile", "packaging", "--verbose"
system "./versioning.sh", "--profile", "packaging"
lib.install Dir["target/packaging/*.dylib","target/packaging/*.a"]
end

cp "dist/common/pkgconfig/scylla-cpp-driver.pc.in", "scylla-cpp-driver.pc"
inreplace "scylla-cpp-driver.pc" do |s|
s.gsub! "@prefix@", "#{prefix}"
s.gsub! "@exec_prefix@", "#{bin}"
s.gsub! "@libdir@", "#{lib}"
s.gsub! "@includedir@", "#{include}"
s.gsub! "@version@", "#{version}"
end

cp "dist/common/pkgconfig/scylla-cpp-driver_static.pc.in", "scylla-cpp-driver_static.pc"
inreplace "scylla-cpp-driver_static.pc" do |s|
s.gsub! "@prefix@", "#{prefix}"
s.gsub! "@exec_prefix@", "#{bin}"
s.gsub! "@libdir@", "#{lib}"
s.gsub! "@includedir@", "#{include}"
s.gsub! "@version@", "#{version}"
end

(lib/"pkgconfig").install Dir["*.pc"]
include.install "include/cassandra.h"
end
end
33 changes: 25 additions & 8 deletions scylla-rust-wrapper/versioning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,29 @@ VERSION_MINOR=$(sed -n -e 's/^#define CASS_VERSION_MINOR \(.*\)/\1/p' ../include
VERSION_PATCH=$(sed -n -e 's/^#define CASS_VERSION_PATCH \(.*\)/\1/p' ../include/cassandra.h)
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"

# library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here
cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.so target/"${TARGET}"/libscylla-cpp-driver.so
cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a
rm -fv target/"${TARGET}"/libscylla_cpp_driver.{so,a}
UNAME="$(uname)"
# On macOS
if [[ "${UNAME}" = "Darwin" ]]; then
# library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here
rm -f target/"${TARGET}"/{libscylla-cpp-driver.dylib,libscylla-cpp-driver_static.a}
cp -v target/"${TARGET}"/libscylla_cpp_driver.dylib target/"${TARGET}"/libscylla-cpp-driver.dylib
cp -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a
rm -fv target/"${TARGET}"/libscylla_cpp_driver.{dylib,a}

# make .so "versioned" style using symlinks
cp --remove-destination -v target/"${TARGET}"/libscylla-cpp-driver.so target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION}"
ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION_MAJOR}"
ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so
# make .so "versioned" style using symlinks
rm -f target/"${TARGET}"/libscylla-cpp-driver."${VERSION}".dylib
cp -v target/"${TARGET}"/libscylla-cpp-driver.dylib target/"${TARGET}"/libscylla-cpp-driver."${VERSION}".dylib
ln -vsf libscylla-cpp-driver."${VERSION}".dylib target/"${TARGET}"/libscylla-cpp-driver."${VERSION_MAJOR}".dylib
ln -vsf libscylla-cpp-driver."${VERSION}".dylib target/"${TARGET}"/libscylla-cpp-driver.dylib
# Linux and other
else
# library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here
cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.so target/"${TARGET}"/libscylla-cpp-driver.so
cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a
rm -fv target/"${TARGET}"/libscylla_cpp_driver.{so,a}

# make .so "versioned" style using symlinks
cp --remove-destination -v target/"${TARGET}"/libscylla-cpp-driver.so target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION}"
ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION_MAJOR}"
ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so
fi

0 comments on commit b7af7e3

Please sign in to comment.