What's the correct way to build V8 as a static library on macOS?

1,990 views
Skip to first unread message

tbl...@icloud.com

unread,
Nov 20, 2016, 8:08:01 PM11/20/16
to v8-users
I tried building with GN, but I was not able to get it to generate any lib*.a files. So that didn't work for me.

I'm currently building with Gyp, but my build doesn't seem to have snapshot support enabled. There is a libv8_nosnapshot.a file, but no libv8.a file.

What's the officially correct way?

~Theodore

John Gardner

unread,
Nov 25, 2016, 11:18:06 PM11/25/16
to v8-users
I'd like to know this as well. Specifically, for updating Homebrew's version of V8, which requires an entirely new formula.

tbl...@icloud.com

unread,
Nov 25, 2016, 11:52:01 PM11/25/16
to v8-users
I'm pretty sure that the correct way right now, if you want a static or dynamic library, is to use Gyp. GN only generates object files, which is only useful if you're including V8 in a project that is also built with GN, such as Chromium. I found this from a link to a Chromium bug in the Homebrew formula.

~Theodore

tbl...@icloud.com

unread,
Nov 25, 2016, 11:53:28 PM11/25/16
to v8-users

tbl...@icloud.com

unread,
Nov 26, 2016, 1:34:00 AM11/26/16
to v8-users
Actually, that's the wrong link. I've completely forgotten where I found out that information.

John Gardner

unread,
Nov 26, 2016, 3:05:54 AM11/26/16
to v8-users
A tracking issue at Electron's repository confirms that it's not possible to build static libraries using GN:

Under gn, there is no way to have v8 build as a standalone static library. This is because v8 and other intermediate targets used to build chrome.exe are source_set targets in chrome's gn files. These are like virtual targets, and only object (.o) files are ever generated for them.

A trick described here involves modifying v8/gni/v8.gni to force static library generation:

template("v8_source_set") {
 static_library(target_name) {

Which results in these files being included in out.gn/x64.release/obj/ after building with Ninja:
  • libfuzzer_support.a
  • libjson_fuzzer.a
  • libparser_fuzzer.a
  • libregexp_fuzzer.a
  • libsimple_fuzzer.a
  • libv8_base.a
  • libv8_external_snapshot.a
  • libv8_libbase.a
  • libv8_libplatform.a
  • libv8_libsampler.a
  • libv8_nosnapshot.a
  • libv8_snapshot.a
  • libwasm_asmjs_fuzzer.a
  • libwasm_fuzzer.a

Jochen Eisinger

unread,
Nov 28, 2016, 4:51:45 AM11/28/16
to v8-users
with https://codereview.chromium.org/2373783002/ it should be possible to set v8_static_library to true to get static libraries

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Gardner

unread,
Nov 28, 2016, 5:05:00 AM11/28/16
to v8-users
Ah awesome, thanks!

Similar question: is it possible to set the rpath at linking-time when compiling a component build? It doesn't seem like ldflags can be modified from a configuration-level. Perhaps I'm using the wrong approach...

I need each dylib to be compiled with an absolute rpath (specifically, /usr/local/opt). Currently, it's attempting to load shared libraries from the executable's path, which doesn't work for the intended directory arrangement:

lib
lib/libv8.dylib
lib/libicuuc.dylib
lib/libicui18n.dylib
bin
bin/v8

Jochen Eisinger

unread,
Dec 5, 2016, 10:51:30 AM12/5/16
to v8-users
sorry for the long delay in answering.

I don't know how to control the rpath, maybe asking on gn-...@chromium.org is an option?
Reply all
Reply to author
Forward
0 new messages