• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 the V8 project authors. All rights reserved.
2# Copyright 2016 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import("//build/config/compiler/compiler.gni")
7
8template("split_static_library") {
9  assert(defined(invoker.split_count),
10         "Must define split_count for split_static_library")
11
12  # In many conditions the number of inputs will be 1 (because the
13  # count will be conditional on platform or configuration) and for
14  # some build configurations it's unnecessary to split libraries
15  # since the tooling will never create files of a problematic size.
16  if (invoker.split_count == 1 || use_lld) {
17    static_library(target_name) {
18      forward_variables_from(invoker, "*")
19    }
20  } else {
21    group_name = target_name
22
23    generated_static_libraries = []
24    current_library_index = 0
25    foreach(current_sources, split_list(invoker.sources, invoker.split_count)) {
26      current_name = "${target_name}_$current_library_index"
27      assert(
28          current_sources != [],
29          "Your values for splitting a static library generate one that has no sources.")
30      generated_static_libraries += [ ":$current_name" ]
31
32      static_library(current_name) {
33        # Generated static library shard gets everything but sources (which
34        # we're redefining) and visibility (which is set to be the group
35        # below).
36        forward_variables_from(invoker,
37                               "*",
38                               [
39                                 "check_includes",
40                                 "sources",
41                                 "visibility",
42                               ])
43        sources = current_sources
44        visibility = [ ":$group_name" ]
45
46        # When splitting a target's sources up into a series of static
47        # libraries, those targets will naturally include headers from each
48        # other arbitrarily. We could theoretically generate a web of
49        # dependencies and allow_circular_includes_from between all pairs of
50        # targets, but that's very cumbersome. Typical usage in Chrome is that
51        # only official Windows builds use split static libraries due to the
52        # Visual Studio size limits, and this means we'll still get header
53        # checking coverage for the other configurations.
54        check_includes = false
55
56        # Uniquify the output name if one is specified.
57        if (defined(invoker.output_name)) {
58          output_name = "${invoker.output_name}_$current_library_index"
59        }
60      }
61
62      current_library_index = current_library_index + 1
63    }
64
65    group(group_name) {
66      public_deps = generated_static_libraries
67      forward_variables_from(invoker,
68                             [
69                               "testonly",
70                               "visibility",
71                             ])
72    }
73  }
74}
75
76set_defaults("split_static_library") {
77  configs = default_compiler_configs
78}
79