Skip to content

Instantly share code, notes, and snippets.

@markopy
Last active June 14, 2023 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markopy/2d5d928ac594a936f30af1a9a5cdb331 to your computer and use it in GitHub Desktop.
Save markopy/2d5d928ac594a936f30af1a9a5cdb331 to your computer and use it in GitHub Desktop.
Patched homebrew formula to install/build nodejs v16 on macos 10.13.6
class NodeAT16 < Formula
desc "Platform built on V8 to build network applications"
homepage "https://nodejs.org/"
url "https://nodejs.org/dist/v16.20.0/node-v16.20.0.tar.xz"
sha256 "e0990f992234e40a51fe11f92c3816c93a77e1b081145d3dd762cd1026345349"
license "MIT"
livecheck do
url "https://nodejs.org/dist/"
regex(%r{href=["']?v?(16(?:\.\d+)+)/?["' >]}i)
end
bottle do
sha256 cellar: :any, arm64_ventura: "9a935f6418abfa0087bdbbe0cce97f7e2b238918345cdd46b6d6bc77ef1ab5bd"
sha256 cellar: :any, arm64_monterey: "fd6acf86e43d8eb1b179921690400d3274d5790153002941210e4fbd60f74d51"
sha256 cellar: :any, arm64_big_sur: "d3d4474f90828c287fd830977d996ffb3b47480e1a051651cebf5bf16351f7c1"
sha256 cellar: :any, ventura: "4ed39f7d3d42dd323d975cd09ff90413318964360960bafc0914a50997347bf1"
sha256 cellar: :any, monterey: "d4e31dbedd8ab1d42e9b98fa95a570a75fc40118b6bfa40c8c98d442e2e24bd4"
sha256 cellar: :any, big_sur: "15cf55cecbfdfaf3f9070a9d7a829a5429e5c5b45eeab28bedf211f4543b92f6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "1b7ae0fd85fa0741ad7cc38a5c64463db526f78002973141814aad62da14f6bd"
end
keg_only :versioned_formula
# https://nodejs.org/en/about/releases/
# disable! date: "2023-09-11", because: :unsupported
depends_on "pkg-config" => :build
depends_on "python@3.11" => :build
depends_on "brotli"
depends_on "c-ares"
depends_on "icu4c"
depends_on "libnghttp2"
depends_on "libuv"
depends_on "openssl@1.1"
uses_from_macos "python", since: :catalina
uses_from_macos "zlib"
fails_with :clang do
build 1099
cause "Node requires Xcode CLT 11+"
end
fails_with gcc: "5"
def install
python3 = "python3.11"
# make sure subprocesses spawned by make are using our Python 3
ENV["PYTHON"] = which(python3)
args = %W[
--prefix=#{prefix}
--with-intl=system-icu
--shared-libuv
--shared-nghttp2
--shared-openssl
--shared-zlib
--shared-brotli
--shared-cares
--shared-libuv-includes=#{Formula["libuv"].include}
--shared-libuv-libpath=#{Formula["libuv"].lib}
--shared-nghttp2-includes=#{Formula["libnghttp2"].include}
--shared-nghttp2-libpath=#{Formula["libnghttp2"].lib}
--shared-openssl-includes=#{Formula["openssl@1.1"].include}
--shared-openssl-libpath=#{Formula["openssl@1.1"].lib}
--shared-brotli-includes=#{Formula["brotli"].include}
--shared-brotli-libpath=#{Formula["brotli"].lib}
--shared-cares-includes=#{Formula["c-ares"].include}
--shared-cares-libpath=#{Formula["c-ares"].lib}
--openssl-use-def-ca-store
]
system python3, "configure.py", *args
system "make", "install"
end
def post_install
(lib/"node_modules/npm/npmrc").atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
end
test do
path = testpath/"test.js"
path.write "console.log('hello');"
output = shell_output("#{bin}/node #{path}").strip
assert_equal "hello", output
output = shell_output("#{bin}/node -e 'console.log(new Intl.NumberFormat(\"en-EN\").format(1234.56))'").strip
assert_equal "1,234.56", output
output = shell_output("#{bin}/node -e 'console.log(new Intl.NumberFormat(\"de-DE\").format(1234.56))'").strip
assert_equal "1.234,56", output
# make sure npm can find node
ENV.prepend_path "PATH", opt_bin
ENV.delete "NVM_NODEJS_ORG_MIRROR"
assert_equal which("node"), opt_bin/"node"
assert_predicate bin/"npm", :exist?, "npm must exist"
assert_predicate bin/"npm", :executable?, "npm must be executable"
npm_args = ["-ddd", "--cache=#{HOMEBREW_CACHE}/npm_cache", "--build-from-source"]
system "#{bin}/npm", *npm_args, "install", "npm@latest"
system "#{bin}/npm", *npm_args, "install", "ref-napi"
assert_predicate bin/"npx", :exist?, "npx must exist"
assert_predicate bin/"npx", :executable?, "npx must be executable"
assert_match "< hello >", shell_output("#{bin}/npx --yes cowsay hello")
end
end
patch :DATA
__END__
Disable v8 system instrumentation on Darwin
On Darwin, the v8 system instrumentation requires the header "os/signpost.h"
which is available since apple_sdk 11+. See: https://github.com/nodejs/node/issues/39584
--- old/tools/v8_gypfiles/features.gypi
+++ new/tools/v8_gypfiles/features.gypi
@@ -62,7 +62,7 @@
}, {
'is_component_build': 0,
}],
- ['OS == "win" or OS == "mac"', {
+ ['OS == "win"', {
# Sets -DSYSTEM_INSTRUMENTATION. Enables OS-dependent event tracing
'v8_enable_system_instrumentation': 1,
}, {
@markopy
Copy link
Author

markopy commented Jun 14, 2023

This gist is the node@16 formula from https://github.com/Homebrew/homebrew-core/blob/212c5526b18165ac6922c2b7016b995b82b5bdc8/Formula/node@16.rb with the patch from https://github.com/NixOS/nixpkgs/pull/133232/files#diff-2fb78802847284b4179c668046bc3f7445c28f5266cfde23a7cf77b793489c3f appended.

Download the gist as node@16.rb and install with

brew install ./node\@16.rb

It fixes the following error when trying to build nodejs v16 on macos High Sierra:

In file included from ../deps/v8/src/libplatform/tracing/trace-writer.cc:14:
../deps/v8/src/libplatform/tracing/recorder.h:17:10: fatal error: 'os/signpost.h' file not found
#include <os/signpost.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[1]: *** [/private/tmp/nodeA16-20230614-83798-ijl6xa/node-v16.20.0/out/Release/obj.target/v8_libplatform/deps/v8/src/libplatform/tracing/trace-writer.o] Error 1
make[1]: *** Waiting for unfinished jobs....
In file included from ../deps/v8/src/libplatform/tracing/recorder-mac.cc:7:
../deps/v8/src/libplatform/tracing/recorder.h:17:10: fatal error: 'os/signpost.h' file not found
#include <os/signpost.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[1]: *** [/private/tmp/nodeA16-20230614-83798-ijl6xa/node-v16.20.0/out/Release/obj.target/v8_libplatform/deps/v8/src/libplatform/tracing/recorder-mac.o] Error 1
rm ac3948245c6d956075cb57d344a5fbfe0efdae9c.intermediate
make: *** [node] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment