66 lines
2.1 KiB
Plaintext
66 lines
2.1 KiB
Plaintext
# Copyright 2023 The Pigweed Authors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
# the License at
|
|
#
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations under
|
|
# the License.
|
|
|
|
import("//build_overrides/pigweed.gni")
|
|
|
|
import("$dir_pw_build/gn_internal/build_target.gni")
|
|
|
|
# Note: In general, prefer to import target_types.gni rather than this file.
|
|
#
|
|
# This template wraps a configurable target type specified by the current
|
|
# toolchain to be used for all pw_rust_library targets. A wrapper for GN's
|
|
# built-in rust_library target, it is analogous to pw_static_library with
|
|
# additions to support rust specific parameters such as rust edition and cargo
|
|
# config features.
|
|
#
|
|
# For more information on the features provided by this template, see the full
|
|
# docs at https://pigweed.dev/pw_build/?highlight=pw_rust_library
|
|
template("pw_rust_library") {
|
|
pw_internal_build_target(target_name) {
|
|
forward_variables_from(invoker, "*")
|
|
|
|
crate_name = target_name
|
|
if (defined(name)) {
|
|
crate_name = name
|
|
}
|
|
|
|
_edition = "2021"
|
|
if (defined(edition)) {
|
|
_edition = edition
|
|
}
|
|
assert(_edition == "2015" || _edition == "2018" || _edition == "2021",
|
|
"edition ${_edition} is not supported")
|
|
|
|
if (!defined(configs)) {
|
|
configs = []
|
|
}
|
|
configs += [ "$dir_pw_build:rust_edition_${_edition}" ]
|
|
|
|
if (!defined(rustflags)) {
|
|
rustflags = []
|
|
}
|
|
if (defined(features)) {
|
|
foreach(i, features) {
|
|
rustflags += [ "--cfg=feature=\"${i}\"" ]
|
|
}
|
|
}
|
|
|
|
underlying_target_type = "rust_library"
|
|
crate_name = string_replace(crate_name, "-", "_")
|
|
output_name = crate_name
|
|
output_dir = "${target_out_dir}/lib"
|
|
add_global_link_deps = true
|
|
}
|
|
}
|