From 1435386ba6f826dd73096fa4dbaa4cc8f460af6e Mon Sep 17 00:00:00 2001 From: Richard Pospesel Date: Thu, 14 Mar 2024 20:47:33 +0000 Subject: [PATCH] build: added homebrew formula package format to build --- .github/workflows/build.yml | 4 +- CMakeLists.txt | 1 + README.md | 10 +++++ source/packages/CMakeLists.txt | 1 + .../packages/homebrew-formula/CMakeLists.txt | 9 +++++ source/packages/homebrew-formula/README.md | 9 +++++ .../homebrew-formula/libcgosling.rb.in | 40 +++++++++++++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 source/packages/homebrew-formula/CMakeLists.txt create mode 100644 source/packages/homebrew-formula/README.md create mode 100644 source/packages/homebrew-formula/libcgosling.rb.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ceb7f96..e3860ecf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -124,7 +124,7 @@ jobs: run: | mkdir -p build/debug cd build/debug - cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON + cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON make make install - name: Archive Debug @@ -140,7 +140,7 @@ jobs: run: | mkdir -p build/release cd build/release - cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON + cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON make make install - name: Archive Release diff --git a/CMakeLists.txt b/CMakeLists.txt index 92a7e7e4..68cbda30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ option(BUILD_EXAMPLES "Build example targets" OFF) # Packages options option(BUILD_DEBIAN_SOURCE_PACKAGE "Build debian cgosling source package" OFF) +option(BUILD_HOMEBREW_FORMULA "Build homebrew flask formula" OFF) # Documentation options option(BUILD_PAGES "Build webpages" OFF) diff --git a/README.md b/README.md index 851cecbf..79a7da66 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,16 @@ The following additional dependencies are required for this configure option: See [source/packages/debian-source/README.md](source/packages/debian-source/README.md) for additional information. +### BUILD_HOMEBREW_FORMULA + +```shell +cmake -DBUILD_HOMEBREW_FORMULA=ON +``` + +Builds a homebrew flask formula which installs libcgosling static libs, shared libs, and developemnt headers. + +See [source/packages/homebrew-formula/README.md](source/packages/homebrew-formula/README.md) for more additional information. + ### BUILD_PAGES ```shell diff --git a/source/packages/CMakeLists.txt b/source/packages/CMakeLists.txt index 9d38c63d..48f2e500 100644 --- a/source/packages/CMakeLists.txt +++ b/source/packages/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(debian-source) +add_subdirectory(homebrew-formula) diff --git a/source/packages/homebrew-formula/CMakeLists.txt b/source/packages/homebrew-formula/CMakeLists.txt new file mode 100644 index 00000000..f4877363 --- /dev/null +++ b/source/packages/homebrew-formula/CMakeLists.txt @@ -0,0 +1,9 @@ +if (BUILD_HOMEBREW_FORMULA) + # generate homebrew formula .rb file + set(LIBCGOSLING_RB_IN ${CMAKE_CURRENT_SOURCE_DIR}/libcgosling.rb.in) + set(LIBCGOSLING_RB_OUT ${CMAKE_CURRENT_BINARY_DIR}/libcgosling.rb) + configure_file(${LIBCGOSLING_RB_IN} ${LIBCGOSLING_RB_OUT} @ONLY) + + install(FILES ${LIBCGOSLING_RB_OUT} + DESTINATION ${CMAKE_INSTALL_DATADIR}/gosling/packages/homebrew-formula) +endif() diff --git a/source/packages/homebrew-formula/README.md b/source/packages/homebrew-formula/README.md new file mode 100644 index 00000000..37c6a805 --- /dev/null +++ b/source/packages/homebrew-formula/README.md @@ -0,0 +1,9 @@ +# homebrew-formula + +This buillds a homebrew formula for the cgosling crate which can be used to install the libcgosling shared libs, static libs, and development headers. + +## Building flask + +```bash +brew install --build-from-source --formula /path/to/libcgosling.rb +``` diff --git a/source/packages/homebrew-formula/libcgosling.rb.in b/source/packages/homebrew-formula/libcgosling.rb.in new file mode 100644 index 00000000..3cff1277 --- /dev/null +++ b/source/packages/homebrew-formula/libcgosling.rb.in @@ -0,0 +1,40 @@ +class Libcgosling < Formula + desc "" + homepage "https://gosling.technology" + url "https://github.com/blueprint-freespeech/gosling.git", tag: "cgosling-v@CGOSLING_VERSION@" + license "BSD-3-Clause" + + depends_on "rust" => :build + depends_on "cmake" => :build + depends_on "tor" + + def install + system "cmake", + "-S", ".", + "-B", "build", + "-DCMAKE_BUILD_TYPE=Release", + *std_cmake_args + system "cmake", "--build", "build" + system "cmake", "--install", "build" + end + + test do + (testpath/"test.cpp").write <<~EOS + #include + + int main() { + gosling_library* library = nullptr; + gosling_error* error = nullptr; + ::gosling_library_init(&library, &error); + if (library != nullptr && error == nullptr) { + gosling_library_free(library); + } else { + return -1; + } + return 0; + } + EOS + system ENV.cxx, "-std=c++17", "test.cpp", "-I#{include}", "-L#{lib}", "-lcgosling", "-o", "test" + system "./test" + end +end