xref: /aosp_15_r20/build/bazel/rules/rust/rust_ffi_static.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16rust_ffi_static macro wraps the include paths to cc headers with the generated
17rust staticlib
18"""
19
20load("@rules_rust//rust:defs.bzl", "rust_static_library")
21load("//build/bazel/rules/cc:cc_prebuilt_library_static.bzl", "cc_prebuilt_library_static")
22
23def rust_ffi_static(
24        name,
25        srcs,
26        crate_name,
27        deps,
28        edition,
29        export_includes,
30        compile_data = None,
31        crate_features = [],
32        # TODO: b/305997810 - Support crate_root attribute
33        proc_macro_deps = [],
34        rustc_flags = [],
35        target_compatible_with = []):
36    rust_static_library(
37        name = name + "_rust_staticlib",
38        srcs = srcs,
39        compile_data = compile_data,
40        crate_features = crate_features,
41        crate_name = crate_name,
42        deps = deps,
43        edition = edition,
44        proc_macro_deps = proc_macro_deps,
45        rustc_flags = rustc_flags,
46        target_compatible_with = target_compatible_with,
47    )
48
49    # TODO: b/305274034 - remove cc_prebuilt_library_static if we can
50    # add includes to rust_ffi_static
51    cc_prebuilt_library_static(
52        name = name,
53        export_includes = export_includes,
54        static_library = name + "_rust_staticlib",
55        target_compatible_with = target_compatible_with,
56    )
57