Building v8 formula with llvm

Hi!

I am trying to build v8.rb on MacOS 10.11. I know this version of MacOS is no longer supported, but we need to target this for R.

V8 requires C++17 to build, and the formula has:

depends_on :xcode => ["10.0", :build] # required by v8

However, at the same time the formula has a fallback methods to use homebrew llvm on older systems.

depends_on "llvm" => :build if DevelopmentTools.clang_build_version < 1100

# use clang from homebrew llvm formula on <= Mojave, because the system clang is to old for V8
if DevelopmentTools.clang_build_version < 1100
  ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib # but link against system libc++
  gn_args[:clang_base_path] = "\"#{Formula["llvm"].prefix}\""
end

I was hoping this would make it possible to build on older versions of MacOS. However, when I try to build the formula it fails as follows:

ninja: Entering directory `out/'
[1/182] CXX base/command_line.o
FAILED: base/command_line.o 
clang++ -MMD -MF base/command_line.o.d  -I.. -I. -DNDEBUG -O3 -fdata-sections -ffunction-sections -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -pthread -pipe -fno-exceptions -fno-rtti -fdiagnostics-color -mmacosx-version-min=10.9 -std=c++17 -c ../base/command_line.cc -o base/command_line.o
error: invalid value 'c++17' in '-std=c++17'

So I guess this means it is still using the system clang? Would there be a way to work around this and build V8 on MacOS 10.11 using homebrew toolchains?

Hi,

it looks like your build is already failing during trying to build gn.

Maybe you have to set an ENV["CXX"] explicitly pointing to clang++ from the LLVM formula before calling system "python", "build/gen.py" on line 75.

If that doesn’t work maybe try to downgrade the gn version to an older version, which is still compatible with macOS 10.11 (something ~1.5 years old should work here, because similar to Apple the latest 3 macOS versions are supported).

Also note that v8 inherits the build configuration from Chromium and officially only supports the latest 3 macOS SDKs. You will also have to set ENV["FORCE_MAC_SDK_MIN"] = "10.11" to support macOS 10.11 in the actual v8 build, following after the gn build. (Note: I’m not sure if this will work, but it’s likely that the SDK requirement is just inherited from Chromium and hopefully not really required for v8. At least it has worked for us a few months as a workaround for continuing to support macOS 10.12 for deno.)