blob: e63ec7ded15f5cd2eefab5de7c90391364c2c1be [file] [log] [blame]
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/toolchain/zircon/clang.gni")
_llvm_elfabi = "$clang_tool_dir/llvm-elfabi"
# Define a linkable shared library built from a text ABI (.tbe) specification.
#
# This uses a `.tbe` file kept in the source tree to create a linkable ELF
# shared library stub file. This can be used at link time to build executable
# and (non-stub) shared library binaries without reference to the actual
# runtime shared library. The real (non-stub) shared library to be used at
# runtime must be compiled separately and included at runtime as necessary.
# This target only takes care of satisfying any link-time dependencies.
# Its label is used in `deps` like a shared_library() target.
#
# This defines two targets. The main target acts like shared_library() for
# linking purposes, but is not a GN target with outputs. An additional target
# "$target_name.stub" is defined whose outputs include the linking stub ELF
# file itself, e.g. for use as input to a copy() target or the like.
#
# Parameters
#
# * abi
# - Required: Source path to a `.tbe` file defining the library's ELF ABI.
# - Type: file
#
# * output_name
# - Optional: The plain name of the linkable library file to write,
# without the `lib` prefix or the `.so` extension.
# - Type: string
# - Default: $target_name
#
# * public, public_configs, public_deps
# - Optional: As for shared_library().
#
template("elfabi_shared_library") {
main_target = target_name
stub_target = "$target_name.stub"
if (defined(invoker.output_name)) {
output_name = invoker.output_name
} else {
output_name = target_name
}
stub_file = "$root_out_dir/lib$output_name.so"
source_set(main_target) {
forward_variables_from(invoker,
[
"visibility",
"public",
"public_configs",
"public_deps",
"testonly",
])
libs = [ stub_file ]
deps = [ ":$stub_target" ]
}
action(stub_target) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
if (defined(visibility)) {
visibility += [ ":$main_target" ]
}
# Output timestamps are not freshened if contents do not change.
all_outputs_fresh = false
script = _llvm_elfabi
sources = [ invoker.abi ]
outputs = [ stub_file ]
args = [
"--tbe",
"--write-if-changed",
"--output-target=elf64-little",
rebase_path(invoker.abi, root_build_dir),
rebase_path(stub_file, root_build_dir),
]
}
}