split_static_library.gni 3.0 KB

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