| # Copyright 2025 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/rust/config.gni") |
| |
| # Define a config() target including the necessary .so file in ldflags. |
| # |
| # Args: |
| # name [string]: Library name prefix (e.g. "libstd" or "libtest"). |
| # |
| template("rust_runtime_link_config") { |
| assert(defined(invoker.name), "name is required") |
| |
| _match = false |
| foreach(_entry, rustc_runtime) { |
| if (_entry.rustflags == [ "-Cprefer-dynamic" ] && |
| _entry.target + [ current_target_tuple ] - [ current_target_tuple ] != |
| _entry.target) { |
| foreach(_runtime, _entry.runtime) { |
| if (_runtime.name == invoker.name) { |
| assert( |
| _match == false, |
| "Multiple .so matches found for ${invoker.name} and ${current_target_tuple} in rust runtime.json. File is ill-formed!") |
| _match = _runtime |
| } |
| } |
| } |
| } |
| |
| config(target_name) { |
| ldflags = [ rebase_path("${rustc_lib_dir}/${_match.dist}", root_build_dir) ] |
| } |
| } |