• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/target_types.gni")
18import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_unit_test/test.gni")
20
21config("linker_script") {
22  inputs = [ "build_id_linker_snippet.ld" ]
23
24  # Automatically add the gnu build ID linker sections when building for Linux.
25  # macOS and Windows executables are not supported, and embedded targets must
26  # manually add the snippet to their linker script in a read-only section.
27  if (current_os == "linux") {
28    # When building for Linux, the linker provides a default linker script.
29    # The add_build_id_to_default_script.ld wrapper includes the
30    # build_id_linker_snippet.ld script in a way that appends to the the
31    # default linker script instead of overriding it.
32    ldflags = [
33      "-T",
34      rebase_path("add_build_id_to_default_linker_script.ld", root_build_dir),
35    ]
36    lib_dirs = [ "." ]
37
38    inputs += [ "add_build_id_to_default_linker_script.ld" ]
39  }
40  visibility = [ ":*" ]
41}
42
43config("gnu_build_id") {
44  ldflags = [ "-Wl,--build-id=sha1" ]
45}
46
47config("public_include_path") {
48  include_dirs = [ "public" ]
49  visibility = [ ":*" ]
50}
51
52# GNU build IDs aren't supported by Windows and macOS.
53if (current_os != "mac" && current_os != "win") {
54  pw_source_set("build_id") {
55    all_dependent_configs = [
56      ":gnu_build_id",
57      ":linker_script",
58    ]
59    public_configs = [ ":public_include_path" ]
60    public = [ "public/pw_build_info/build_id.h" ]
61    sources = [ "build_id.cc" ]
62    deps = [
63      dir_pw_preprocessor,
64      dir_pw_span,
65    ]
66  }
67}
68
69pw_doc_group("docs") {
70  sources = [ "docs.rst" ]
71  inputs = [
72    "add_build_id_to_default_linker_script.ld",
73    "build_id_linker_snippet.ld",
74  ]
75}
76
77pw_test_group("tests") {
78  tests = [ ":build_id_test" ]
79}
80
81pw_test("build_id_test") {
82  enable_if = current_os == "linux"
83  deps = [
84    ":build_id",
85    "$dir_pw_span",
86  ]
87  sources = [ "build_id_test.cc" ]
88}
89