From dbab277ffa34a283cf7a2b6a9f4dee388f6d4faf Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 10 Aug 2022 00:26:55 +0800 Subject: [PATCH] duck: use `libffi` from macos Closes #107649. Signed-off-by: BrewTestBot <1589480+BrewTestBot@users.noreply.github.com> --- Formula/duck.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Formula/duck.rb b/Formula/duck.rb index a5194f0bb46..5fc09f38292 100644 --- a/Formula/duck.rb +++ b/Formula/duck.rb @@ -23,10 +23,9 @@ class Duck < Formula depends_on "maven" => :build depends_on "pkg-config" => :build depends_on xcode: ["13.1", :build] - - depends_on "libffi" depends_on "openjdk" + uses_from_macos "libffi", since: :monterey # Uses `FFI_BAD_ARGTYPE`. uses_from_macos "zlib" on_linux do @@ -60,12 +59,18 @@ class Duck < Formula # Consider creating a formula for this if other formulae need the same library resource("jna").stage do os = if OS.mac? - # Add linker flags for libffi because Makefile call to pkg-config doesn't seem to work properly. - inreplace "native/Makefile", "LIBS=", "LIBS=-L#{Formula["libffi"].opt_lib} -lffi" - # Force shared library to have dylib extension on macOS instead of jnilib - inreplace "native/Makefile", - "LIBRARY=$(BUILD)/$(LIBPFX)jnidispatch$(JNISFX)", - "LIBRARY=$(BUILD)/$(LIBPFX)jnidispatch$(LIBSFX)" + inreplace "native/Makefile" do |s| + libffi_libdir = if MacOS.version >= :monterey + MacOS.sdk_path/"usr/lib" + else + Formula["libffi"].opt_lib + end + # Add linker flags for libffi because Makefile call to pkg-config doesn't seem to work properly. + s.change_make_var! "LIBS", "-L#{libffi_libdir} -lffi" + library_var = s.get_make_var("LIBRARY") + # Force shared library to have dylib extension on macOS instead of jnilib + s.change_make_var! "LIBRARY", library_var.sub("JNISFX", "LIBSFX") + end "mac" else @@ -89,10 +94,12 @@ class Duck < Formula ENV.deparallelize ENV["JAVA_HOME"] = Language::Java.java_home(Formula["openjdk"].version.major.to_s) - # Fix zip error on macOS because libjnidispatch.dylib is not in file list - inreplace "build.sh", "libjnidispatch.so", "libjnidispatch.so libjnidispatch.dylib" if OS.mac? - # Fix relative path in build script, which is designed to be run out extracted zip archive - inreplace "build.sh", "cd native", "cd ../native" + inreplace "build.sh" do |s| + # Fix zip error on macOS because libjnidispatch.dylib is not in file list + s.gsub! "libjnidispatch.so", "libjnidispatch.so libjnidispatch.dylib" if OS.mac? + # Fix relative path in build script, which is designed to be run out extracted zip archive + s.gsub! "cd native", "cd ../native" + end system "sh", "build.sh" buildpath.install shared_library("libjnidispatch")