Skip to content

Commit

Permalink
nu: fix build on Apple Silicon
Browse files Browse the repository at this point in the history
Closes #112070.

Signed-off-by: Carlo Cabrera <[email protected]>
Signed-off-by: BrewTestBot <[email protected]>
  • Loading branch information
cho-m authored and BrewTestBot committed Oct 1, 2022
1 parent 6f3562b commit 6a5543a
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions Formula/nu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Nu < Formula
sha256 "1a6839c1f45aff10797dd4ce5498edaf2f04c415b3c28cd06a7e0697d6133342"
license "Apache-2.0"
revision 1
head "https://github.com/programming-nu/nu.git", branch: "master"

bottle do
sha256 cellar: :any, monterey: "a2a1bdb6473b6afd30cde5def27158415fb38f92851b8a252498631f7e2f350d"
Expand All @@ -15,24 +16,45 @@ class Nu < Formula

depends_on "pcre"

uses_from_macos "llvm" => [:build, :test]
uses_from_macos "llvm" => :build
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"
depends_on "readline"
end

on_arm do
# objc/NuBridge.m:1242:6: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99
# Since libffi.tbd only exports '_ffi_prep_closure' on x86_64, we need to use formula until fixed.
# Issue ref: https://github.com/programming-nu/nu/issues/97
depends_on "libffi"
end

# Clang must be used on Linux because GCC Objective-C support is insufficient.
fails_with :gcc

# Fix Snow Leopard or Lion check to avoid `-arch x86_64` being added to ARM build
# PR ref: https://github.com/programming-nu/nu/pull/101
# TODO: Remove if upstream PR is merged and in a release.
patch do
url "https://github.com/programming-nu/nu/commit/0a837a407f9e9b8f7861b0dd2736f54c04729642.patch?full_index=1"
sha256 "6c8567f0c2681f652dc087f6ef4b713bcc598e99729099a910984f9134f6a72c"
end

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
# Work around ARM build error where directives removed necessary code and broke mininush.
# Nu uncaught exception: NuIvarAddedTooLate: explicit instance variables ...
# Issue ref: https://github.com/programming-nu/nu/issues/102
inreplace "objc/NuOperators.m", "#if defined(__x86_64__) || TARGET_OS_IPHONE",
"#if defined(__x86_64__) || defined(__arm64__)"

unless OS.mac?
ENV.append_path "PATH", Formula["gnustep-make"].libexec
Expand All @@ -45,9 +67,6 @@ def install
]
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.
Expand All @@ -63,7 +82,15 @@ def install
(set @framework_install_path "#{frameworks}")
EOS
end
system "make"

# Remove bundled libffi
(buildpath/"libffi").rmtree

# Remove unused prefix from ffi.h to match directory structure of libffi formula
include_path = (OS.mac? && Hardware::CPU.arm?) ? "ffi" : "x86_64-linux-gnu"
inreplace ["objc/NuBridge.h", "objc/NuBridge.m", "objc/Nu.m"], "<#{include_path}/", "<"

system "make", "CC=#{ENV.cc}"
system "./mininush", "tools/nuke"
bin.mkdir
lib.mkdir
Expand Down

0 comments on commit 6a5543a

Please sign in to comment.