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