• 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
15load(
16    "//pw_build:pigweed.bzl",
17    "pw_cc_test",
18)
19
20package(default_visibility = ["//visibility:public"])
21
22licenses(["notice"])
23
24cc_library(
25    name = "build_id_header",
26    hdrs = [
27        "public/pw_build_info/build_id.h",
28        "public/pw_build_info/util.h",
29    ],
30    includes = ["public"],
31    deps = [
32        "//pw_span",
33    ],
34)
35
36cc_library(
37    name = "build_id",
38    srcs = [
39        "build_id.cc",
40        "util.cc",
41    ],
42    # Automatically add the gnu build ID linker sections when building for
43    # Linux. macOS and Windows executables are not supported, and embedded
44    # targets must manually add the snippet to their linker script in a
45    # read-only section.
46    linkopts = select({
47        # When building for Linux, the linker provides a default linker script.
48        # The add_build_id_to_default_script.ld wrapper includes the
49        # build_id_linker_snippet.ld script in a way that appends to the
50        # default linker script instead of overriding it.
51        "@platforms//os:linux": [
52            "-T$(location add_build_id_to_default_linker_script.ld)",
53        ],
54        "//conditions:default": [],
55    }) + [
56        "-Lpw_build_info",
57        "-Wl,--build-id=sha1",
58    ],
59    deps = select({
60        "@platforms//os:linux": [
61            ":add_build_id_to_default_linker_script.ld",
62            ":build_id_linker_snippet.ld",
63        ],
64        "//conditions:default": [],
65    }) + [
66        ":build_id_header",
67        "//pw_log",
68        "//pw_preprocessor",
69        "//pw_span",
70        "//pw_string",
71    ],
72)
73
74cc_library(
75    name = "build_id_noop",
76    srcs = [
77        "build_id_noop.cc",
78        "util.cc",
79    ],
80    deps = [
81        ":build_id_header",
82        "//pw_log",
83        "//pw_span",
84        "//pw_string",
85    ],
86)
87
88cc_library(
89    name = "build_id_or_noop",
90    deps = select({
91        "@platforms//os:ios": [":build_id_noop"],
92        "@platforms//os:macos": [":build_id_noop"],
93        "@platforms//os:windows": [":build_id_noop"],
94        "//conditions:default": [":build_id"],
95    }),
96)
97
98pw_cc_test(
99    name = "build_id_test",
100    srcs = ["build_id_test.cc"],
101    # This test is only compatible with linux. macOS and Windows are not
102    # supported, and embedded targets must manually add the snippet to  their
103    # linker scripts
104    target_compatible_with = ["@platforms//os:linux"],
105    deps = [
106        ":build_id",
107        "//pw_span",
108        "//pw_unit_test",
109    ],
110)
111