• 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("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
18load("//pw_build:pw_linker_script.bzl", "pw_linker_script")
19load("//pw_build:python.bzl", "pw_py_binary")
20load(
21    "//pw_build_info:substitute_workspace_status.bzl",
22    "pw_substitute_workspace_status",
23)
24load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
25
26package(
27    default_visibility = ["//visibility:public"],
28)
29
30licenses(["notice"])
31
32cc_library(
33    name = "build_id_header",
34    hdrs = [
35        "public/pw_build_info/build_id.h",
36        "public/pw_build_info/util.h",
37    ],
38    strip_include_prefix = "public",
39    deps = [
40        "//pw_span",
41    ],
42)
43
44# When building for Linux, the linker provides a default linker script.
45# The add_build_id_to_default_script.ld wrapper includes the
46# build_id_linker_snippet.ld script in a way that appends to the
47# default linker script instead of overriding it.
48pw_linker_script(
49    name = "build_id_linker_script",
50    linker_script = "add_build_id_to_default_linker_script.ld",
51    target_compatible_with = ["@platforms//os:linux"],
52)
53
54cc_library(
55    name = "build_id",
56    srcs = [
57        "build_id.cc",
58        "util.cc",
59    ],
60    linkopts = [
61        "-Lexternal/" + repo_name() + "/" + package_name(),
62        "-L" + package_name(),
63        "-Wl,--build-id=sha1",
64    ],
65    # Automatically add the gnu build ID linker sections when building for
66    # Linux. macOS and Windows executables are not supported, and embedded
67    # targets must manually add the snippet to their linker script in a
68    # read-only section.
69    deps = select({
70        "@platforms//os:linux": [
71            ":build_id_linker_script",
72            ":build_id_linker_snippet.ld",
73        ],
74        "//conditions:default": [],
75    }) + [
76        ":build_id_header",
77        "//pw_log",
78        "//pw_preprocessor",
79        "//pw_span",
80        "//pw_string:builder",
81    ],
82)
83
84cc_library(
85    name = "build_id_noop",
86    srcs = [
87        "build_id_noop.cc",
88        "util.cc",
89    ],
90    deps = [
91        ":build_id_header",
92        "//pw_log",
93        "//pw_span",
94        "//pw_string:builder",
95    ],
96)
97
98cc_library(
99    name = "build_id_or_noop",
100    deps = select({
101        "@platforms//os:ios": [":build_id_noop"],
102        "@platforms//os:macos": [":build_id_noop"],
103        "@platforms//os:windows": [":build_id_noop"],
104        "//conditions:default": [":build_id"],
105    }),
106)
107
108pw_cc_test(
109    name = "build_id_test",
110    srcs = ["build_id_test.cc"],
111    # This test is only compatible with linux. macOS and Windows are not
112    # supported, and embedded targets must manually add the snippet to  their
113    # linker scripts
114    target_compatible_with = ["@platforms//os:linux"],
115    deps = [
116        ":build_id",
117        ":build_id_header",
118        "//pw_span",
119    ],
120)
121
122pw_py_binary(
123    name = "substitute_workspace_status_tool",
124    srcs = ["substitute_workspace_status_tool.py"],
125)
126
127pw_substitute_workspace_status(
128    name = "git_build_info",
129    src = "git_build_info.h.in",
130    out = "git_build_info.h",
131)
132
133pw_cc_test(
134    name = "git_build_info_test",
135    srcs = [
136        "git_build_info_test.cc",
137        ":git_build_info",
138    ],
139    tags = ["noclangtidy"],
140    deps = ["//pw_log"],
141)
142
143sphinx_docs_library(
144    name = "docs",
145    srcs = [
146        "add_build_id_to_default_linker_script.ld",
147        "build_id_linker_snippet.ld",
148        "docs.rst",
149    ],
150    prefix = "pw_build_info/",
151    target_compatible_with = incompatible_with_mcu(),
152)
153