From dd2ad61a93ed8c9e6a7043fc80ef8a91860996a4 Mon Sep 17 00:00:00 2001 From: danielnachun Date: Sun, 26 Jun 2022 11:03:06 -0700 Subject: [PATCH] nu: fix build on Linux --- Formula/nu.rb | 54 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/Formula/nu.rb b/Formula/nu.rb index a5af909dec540..1b786ddd72ba2 100644 --- a/Formula/nu.rb +++ b/Formula/nu.rb @@ -15,9 +15,45 @@ class Nu < Formula depends_on "pcre" + uses_from_macos "llvm" => [:build, :test] + uses_from_macos "swift" => :build # For libdispatch on Linux. + uses_from_macos "libffi" + + on_linux do + depends_on "gnustep-make" => :build + depends_on "gnustep-base" + depends_on "libobjc2" + end + + # Clang must be used on Linux because GCC Objective-C support is insufficient. + fails_with :gcc + def install ENV.delete("SDKROOT") if MacOS.version < :sierra ENV["PREFIX"] = prefix + # Don't hard code path to clang. + inreplace "tools/nuke", "/usr/bin/clang", ENV.cc + + unless OS.mac? + ENV.append_path "PATH", Formula["gnustep-make"].libexec + + # Help linker find libdispatch from swift on Linux. + # This is only used for the mininush temporary compiler and is not needed for nush. + ldflags = %W[ + "-L#{Formula["swift"].libexec}/lib/swift/linux" + "-Wl,-rpath,#{Formula["swift"].libexec}/lib/swift/linux" + ] + ENV["LIBDIRS"] = ldflags.join(" ") + + # Remove unused prefix from ffi.h + inreplace ["objc/NuBridge.h", "objc/NuBridge.m", "objc/Nu.m"], "x86_64-linux-gnu/", "" + + # Remove CFLAGS that force using GNU runtime on Linux. + # Remove this workaround when upstream drops these flags or provides a way to disable them. + # Reported upstream here: https://github.com/programming-nu/nu/issues/99. + inreplace "Nukefile", "-DGNU_RUNTIME=1", "" + inreplace "Nukefile", "-fgnu-runtime", "" + end inreplace "Nukefile" do |s| s.gsub!('(SH "sudo ', '(SH "') # don't use sudo to install @@ -36,14 +72,16 @@ def install end def caveats - <<~EOS - Nu.framework was installed to: - #{frameworks}/Nu.framework - - You may want to symlink this Framework to a standard macOS location, - such as: - ln -s "#{frameworks}/Nu.framework" /Library/Frameworks - EOS + on_macos do + <<~EOS + Nu.framework was installed to: + #{frameworks}/Nu.framework + + You may want to symlink this Framework to a standard macOS location, + such as: + ln -s "#{frameworks}/Nu.framework" /Library/Frameworks + EOS + end end test do