blob: 2d43b2d617a85471d3c5b4f80ea27e55a56c5b59 [file] [log] [blame]
# Copyright 2017 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.
# Declare a driver module target.
#
# This target allows you to create an object file that can be used as a driver
# that is loaded at runtime.
#
# Parameters
#
# test (optional)
# [boolean] Whether this driver is a test driver. Defaults to false.
# Note: this only makes sense for drivers migrated from the Zircon build.
# Safe to ignore in other cases.
#
# Flags: cflags, cflags_c, cflags_cc, asmflags, defines, include_dirs,
# ldflags, lib_dirs, libs,
# Deps: data_deps, deps, public_deps
# Dependent configs: all_dependent_configs, public_configs
# General: check_includes, configs, data, inputs, output_name,
# output_extension, public, sources, testonly, visibility
template("driver_module") {
loadable_module(target_name) {
variant_selector_target_type = "driver_module"
# Save the target name as forward_variables_from below might override it.
_target_name = target_name
assert_no_deps = []
# Explicitly forward visibility, implicitly forward everything else.
# See comment in //build/config/BUILDCONFIG.gn for details on this pattern.
forward_variables_from(invoker, [ "visibility" ])
forward_variables_from(invoker,
"*",
[
"test",
"visibility",
])
# Restore the target name.
target_name = _target_name
if (!defined(output_dir)) {
output_dir = root_out_dir
}
if (!defined(output_name)) {
output_name = target_name
}
if (!defined(output_extension)) {
output_extension = "so"
}
_output_file_name = output_name
if (output_extension != "") {
_output_file_name += ".$output_extension"
}
_output_file = "$output_dir/$_output_file_name"
_rebased_output_file = rebase_path(_output_file, root_build_dir)
_dest_dir = "driver"
if (defined(invoker.test) && invoker.test) {
_dest_dir += "/test"
}
has_syslog_backend = false
if (defined(deps)) {
foreach(dep, deps) {
dep = get_label_info(dep, "label_no_toolchain")
has_syslog_backend =
has_syslog_backend || dep == "//sdk/lib/syslog/cpp:backend" ||
dep == "//sdk/lib/syslog/cpp:backend_legacy" ||
dep == "//sdk/lib/syslog/cpp:backend_fuchsia_compat"
}
}
# If no syslog backend is found, ensure we have not included the syslog frontend.
if (!has_syslog_backend) {
assert_no_deps += [ "//sdk/lib/syslog/cpp" ]
}
metadata = {
# Used by the distribution_manifest template.
distribution_entries = [
{
source = _rebased_output_file
destination = "$_dest_dir/$_output_file_name"
label = get_label_info(":$_target_name", "label_with_toolchain")
},
]
}
}
}
set_defaults("driver_module") {
# Sets the default configs for driver_module, which can be modified later
# by the invoker. This overrides the loadable_module default.
configs = default_shared_library_configs
# Drivers cannot dynamically link against the C++ standard library. This config
# tells the linker to link against it statically. This is safe for drivers which
# don't depend on the standard library as well as the linker will not have any
# symbols to resolve.
configs += [ "//build/config/fuchsia:static_cpp_standard_library" ]
}
# TODO(64400): Temporary to allow out of tree users to soft migrate.
template("driver_module_new") {
driver_module(target_name) {
forward_variables_from(invoker, "*")
}
}
set_defaults("driver_module_new") {
configs = default_shared_library_configs
configs += [ "//build/config/fuchsia:static_cpp_standard_library" ]
}