Skip to content

Commit

Permalink
Uses thin ar static libraries.
Browse files Browse the repository at this point in the history
We are crossing the 100 MB hard limit on GitHub file sizes.

Two alternatives:

1) Make split archives, and change the LDFLAGS to include all of them.
2) Make split archives, and then make an empty parent archive that sets additional linker flags using "ar l".
   This would avoid having to update Go files, but wide compatibility is less certain.

We can't use GitHub Large Files Support, since go get wouldn't see the files.

For Windows, it's not clear what we'd have to do.
  • Loading branch information
tommie committed Dec 27, 2023
1 parent 6d625c4 commit 1b40dc8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/v8build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ jobs:
# The name matches the directory under deps/.
name: ${{ matrix.os }}_${{ matrix.arch }}
if-no-files-found: error
path: deps/${{ matrix.os }}_${{ matrix.arch }}/libv8.a
path: |
deps/${{ matrix.os }}_${{ matrix.arch }}/libv8.a
deps/${{ matrix.os }}_${{ matrix.arch }}/obj/
retention-days: 2

commit:
Expand Down
118 changes: 77 additions & 41 deletions deps/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
import platform
import argparse
import glob
import os
import subprocess
import platform
import shutil
import argparse
import subprocess

valid_archs = ['arm64', 'x86_64']
# "x86_64" is called "amd64" on Windows
Expand Down Expand Up @@ -93,6 +94,36 @@ def v8deps():
cwd=deps_path,
env=env)

def build_gn_args():
is_debug = args.debug
is_clang = args.clang if args.clang is not None else args.os != "linux"
arch = v8_arch()
# symbol_level = 1 includes line number information
# symbol_level = 2 can be used for additional debug information, but it can increase the
# compiled library by an order of magnitude and further slow down compilation
symbol_level = 1 if args.debug else 0
strip_debug_info = not args.debug

gnargs = gn_args % (
str(bool(is_debug)).lower(),
str(is_clang).lower(),
v8_os(),
arch,
arch,
symbol_level,
str(strip_debug_info).lower(),
)
if args.ccache:
gnargs += 'cc_wrapper="ccache"\n'
if not is_clang and arch == "arm64":
# https://chromium.googlesource.com/chromium/deps/icu/+/2958a507f15e475045906d73af39018d5038a93b
# introduced -mmark-bti-property, which isn't supported by GCC.
#
# V8 itself fixed this in https://chromium-review.googlesource.com/c/v8/v8/+/3930160.
gnargs += 'arm_control_flow_integrity="none"\n'

return gnargs

def cmd(args):
return ["cmd", "/c"] + args if is_windows else args

Expand Down Expand Up @@ -125,6 +156,42 @@ def update_last_change():
out_path = os.path.join(v8_path, "build", "util", "LASTCHANGE")
subprocess.check_call(["python", "build/util/lastchange.py", "-o", out_path], cwd=v8_path)

def convert_to_thin_ar(src_fn, dest_fn, dest_obj_dn):
"""Extracts all files from src_fn to dest_obj_dn/ and makes a thin archive at dest_fn.
GitHub's file size limit is 100 MiB, and the archive is hitting that.
"""
dest_path = os.path.dirname(dest_fn)

ar_path = "ar"
if args.os == "linux" and args.arch == "arm64":
ar_path = "aarch64-linux-gnu-ar"

if os.path.exists(dest_obj_dn):
shutil.rmtree(dest_obj_dn)
os.makedirs(dest_obj_dn)

subprocess.check_call(
[
ar_path,
"x",
"--output", dest_obj_dn,
src_fn,
],
cwd=v8_path)

if os.path.exists(dest_fn):
os.unlink(dest_fn)

subprocess.check_call(
[
ar_path,
"qsc",
"--thin",
dest_fn,
] + [os.path.relpath(fn, dest_path) for fn in glob.glob(os.path.join(dest_obj_dn, "*"))],
cwd=dest_path)

def main():
v8deps()
if is_windows:
Expand All @@ -136,48 +203,17 @@ def main():
assert(os.path.exists(ninja_path))

build_path = os.path.join(deps_path, ".build", os_arch())
env = os.environ.copy()

is_debug = args.debug
is_clang = args.clang if args.clang is not None else args.os != "linux"
arch = v8_arch()
# symbol_level = 1 includes line number information
# symbol_level = 2 can be used for additional debug information, but it can increase the
# compiled library by an order of magnitude and further slow down compilation
symbol_level = 1 if args.debug else 0
strip_debug_info = not args.debug

gnargs = gn_args % (
str(bool(is_debug)).lower(),
str(is_clang).lower(),
v8_os(),
arch,
arch,
symbol_level,
str(strip_debug_info).lower(),
)
if args.ccache:
gnargs += 'cc_wrapper="ccache"\n'
if not is_clang and arch == "arm64":
# https://chromium.googlesource.com/chromium/deps/icu/+/2958a507f15e475045906d73af39018d5038a93b
# introduced -mmark-bti-property, which isn't supported by GCC.
#
# V8 itself fixed this in https://chromium-review.googlesource.com/c/v8/v8/+/3930160.
gnargs += 'arm_control_flow_integrity="none"\n'
gnargs = build_gn_args()

subprocess.check_call(cmd([gn_path, "gen", build_path, "--args=" + gnargs.replace('\n', ' ')]),
cwd=v8_path,
env=env)
subprocess.check_call([ninja_path, "-v", "-C", build_path, "v8_monolith"],
cwd=v8_path,
env=env)
subprocess.check_call(cmd([gn_path, "gen", build_path, "--args=" + gnargs.replace('\n', ' ')]), cwd=v8_path)
subprocess.check_call([ninja_path, "-v", "-C", build_path, "v8_monolith"], cwd=v8_path)

lib_fn = os.path.join(build_path, "obj/libv8_monolith.a")
dest_path = os.path.join(deps_path, os_arch())
if not os.path.exists(dest_path):
os.makedirs(dest_path)
dest_fn = os.path.join(dest_path, 'libv8.a')
shutil.copy(lib_fn, dest_fn)
convert_to_thin_ar(
os.path.join(build_path, "obj/libv8_monolith.a"),
os.path.join(dest_path, "libv8.a"),
os.path.join(dest_path, "obj"))


if __name__ == "__main__":
Expand Down

0 comments on commit 1b40dc8

Please sign in to comment.