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 default 31 # 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 # noop version of the package that allows build_id users to still be built 55 # for unsupported platforms and avoids amplifying downstream complexity. It 56 # provides a noop version of pw::build_info::BuildId() which just returns an 57 # empty span. 58 pw_source_set("build_id_or_noop") { 59 public_configs = [ ":public_include_path" ] 60 public = [ 61 "public/pw_build_info/build_id.h", 62 "public/pw_build_info/util.h", 63 ] 64 sources = [ 65 "build_id_noop.cc", 66 "util.cc", 67 ] 68 deps = [ 69 dir_pw_log, 70 dir_pw_span, 71 dir_pw_string, 72 ] 73 } 74} else { 75 pw_source_set("build_id") { 76 all_dependent_configs = [ 77 ":gnu_build_id", 78 ":linker_script", 79 ] 80 public_configs = [ ":public_include_path" ] 81 public = [ 82 "public/pw_build_info/build_id.h", 83 "public/pw_build_info/util.h", 84 ] 85 sources = [ 86 "build_id.cc", 87 "util.cc", 88 ] 89 deps = [ 90 dir_pw_log, 91 dir_pw_preprocessor, 92 dir_pw_span, 93 dir_pw_string, 94 ] 95 } 96 97 pw_source_set("build_id_or_noop") { 98 public_deps = [ ":build_id" ] 99 } 100} 101 102pw_doc_group("docs") { 103 sources = [ "docs.rst" ] 104 inputs = [ 105 "add_build_id_to_default_linker_script.ld", 106 "build_id_linker_snippet.ld", 107 ] 108} 109 110pw_test_group("tests") { 111 tests = [ ":build_id_test" ] 112} 113 114pw_test("build_id_test") { 115 enable_if = current_os == "linux" 116 deps = [ 117 ":build_id", 118 "$dir_pw_span", 119 ] 120 sources = [ "build_id_test.cc" ] 121} 122 123# git_build_info embedding isn't supported in GN build 124# Reference to satisfy presubmit. 125copy("git_build_info_files") { 126 sources = [ 127 "git_build_info_test.cc", 128 "substitute_workspace_status_tool.py", 129 ] 130 outputs = [ "$target_gen_dir/{{source_file_part}}" ] 131} 132