Skip to content

Commit

Permalink
build: added homebrew formula package format to build
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Pospesel committed Mar 14, 2024
1 parent 6f4db2e commit 1435386
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/packages/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(debian-source)
add_subdirectory(homebrew-formula)
9 changes: 9 additions & 0 deletions source/packages/homebrew-formula/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions source/packages/homebrew-formula/README.md
Original file line number Diff line number Diff line change
@@ -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
```
40 changes: 40 additions & 0 deletions source/packages/homebrew-formula/libcgosling.rb.in
Original file line number Diff line number Diff line change
@@ -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 <cgosling.hpp>

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

0 comments on commit 1435386

Please sign in to comment.