91 lines
2.7 KiB
Ruby
91 lines
2.7 KiB
Ruby
class Libffi < Formula
|
|
bottle do
|
|
root_url "https://homebrew.hyprnet/bottles"
|
|
sha256 cellar: :any, arm64_sequoia: "ba141e26c8d3b55fa4534317c474b34d649355d93299e35aa33a6eebf60117f8"
|
|
sha256 cellar: :any, arm64_tahoe: "a36f51cb6041fb1c5e70a6300a05a58dfc3b3503e621f83198731f1eaed63f2f"
|
|
sha256 cellar: :any, x86_64_linux: "250d5150db65018e524595cae9de93f8d72ebe8a078bfde968eae51bdc1787fc"
|
|
end
|
|
desc "Portable Foreign Function Interface library"
|
|
homepage "https://sourceware.org/libffi/"
|
|
url "https://github.com/libffi/libffi/releases/download/v3.8.0/libffi-3.8.0.tar.gz"
|
|
sha256 "7da3e2d9a171eb0a038f592ecad3ff2bb2550f3496d87b3b29ad0cf4430c0db4"
|
|
license "MIT"
|
|
compatibility_version 1
|
|
|
|
livecheck do
|
|
url :stable
|
|
strategy :github_latest
|
|
end
|
|
|
|
|
|
|
|
head do
|
|
url "https://github.com/libffi/libffi.git", branch: "master"
|
|
depends_on "autoconf" => :build
|
|
depends_on "automake" => :build
|
|
depends_on "libtool" => :build
|
|
end
|
|
|
|
keg_only :provided_by_macos
|
|
|
|
def install
|
|
system "./autogen.sh" if build.head?
|
|
system "./configure", *std_configure_args
|
|
system "make", "install"
|
|
end
|
|
|
|
test do
|
|
(testpath/"closure.c").write <<~C
|
|
#include <stdio.h>
|
|
#include <ffi.h>
|
|
|
|
/* Acts like puts with the file given at time of enclosure. */
|
|
void puts_binding(ffi_cif *cif, void *ret, void** args, void *stream)
|
|
{
|
|
*(unsigned int *)ret = fputs(*(char **)args[0], (FILE *)stream);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
ffi_cif cif;
|
|
ffi_type *args[1];
|
|
ffi_closure *closure;
|
|
|
|
int (*bound_puts)(char *);
|
|
int rc;
|
|
|
|
/* Allocate closure and bound_puts */
|
|
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
|
|
|
|
if (closure)
|
|
{
|
|
/* Initialize the argument info vectors */
|
|
args[0] = &ffi_type_pointer;
|
|
|
|
/* Initialize the cif */
|
|
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
&ffi_type_uint, args) == FFI_OK)
|
|
{
|
|
/* Initialize the closure, setting stream to stdout */
|
|
if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
|
stdout, bound_puts) == FFI_OK)
|
|
{
|
|
rc = bound_puts("Hello World!");
|
|
/* rc now holds the result of the call to fputs */
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Deallocate both closure, and bound_puts */
|
|
ffi_closure_free(closure);
|
|
|
|
return 0;
|
|
}
|
|
C
|
|
|
|
flags = ["-L#{lib}", "-lffi", "-I#{include}"]
|
|
system ENV.cc, "-o", "closure", "closure.c", *(flags + ENV.cflags.to_s.split)
|
|
system "./closure"
|
|
end
|
|
end
|