blob: 0e63c3ebc2c5f7f8b11392ca92212121108a80a8 [file] [log] [blame]
# Copyright 2020 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/cpp/sdk_shared_library.gni")
import("//build/cpp/sdk_source_set.gni")
template("zx_library") {
template_params = [
"static",
"shared",
"host",
"kernel",
"sdk",
"sdk_headers",
"sdk_publishable",
]
# The following parameters are just ignored, as in the GN build the shape of
# a library is driven by the value of the "sdk" parameter.
not_needed(invoker,
[
"static",
"shared",
"host",
])
assert(!defined(invoker.kernel) || !invoker.kernel,
"Kernel libraries not supported")
assert(defined(invoker.sdk),
"Can only migrate libraries exposed to the GN build")
shape = invoker.sdk
sdkable = defined(invoker.sdk_publishable) && invoker.sdk_publishable
assert(!sdkable || shape == "source" || shape == "shared",
"Static libraries available in SDKs are currently not supported.")
extra_target_args = {}
if (shape == "source") {
if (sdkable) {
target_type = "sdk_source_set"
extra_target_args = {
category = "partner"
api = "//sdk/lib/$target_name/$target_name.api"
sdk_name = target_name
build_as_static = true
}
} else {
target_type = "static_library"
}
} else if (shape == "static") {
target_type = "static_library"
} else if (shape == "shared") {
if (sdkable) {
target_type = "sdk_shared_library"
extra_target_args = {
category = "partner"
api = "//sdk/lib/$target_name/$target_name.api"
symbols_api = "//sdk/lib/$target_name/$target_name.symbols.api"
sdk_name = target_name
libcxx_linkage = "static"
}
} else {
target_type = "shared_library"
}
} else {
assert(false, "Unknown library type: $shape")
}
main_target_name = target_name
config_target_name = "$target_name.config"
config(config_target_name) {
include_dirs = [ "include" ]
}
target(target_type, main_target_name) {
forward_variables_from(invoker, "*", template_params)
forward_variables_from(extra_target_args, "*")
configs += [ "//build/unification/config:zircon-library" ]
# Binaries depending on migrated libraries cannot be marked as testonly, and
# therefore neither can the libraries themselves.
# See fxb/44278 for more info.
testonly = false
if (defined(invoker.sdk_headers)) {
public = []
foreach(header, invoker.sdk_headers) {
public += [ "include/$header" ]
}
}
public_configs = [ ":$config_target_name" ]
}
}
set_defaults("zx_library") {
configs = default_common_binary_configs
}