xref: /aosp_15_r20/build/bazel/rules/linker_config.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1*7594170eSAndroid Build Coastguard Worker# Copyright (C) 2022 The Android Open Source Project
2*7594170eSAndroid Build Coastguard Worker#
3*7594170eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*7594170eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*7594170eSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*7594170eSAndroid Build Coastguard Worker#
7*7594170eSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*7594170eSAndroid Build Coastguard Worker#
9*7594170eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*7594170eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*7594170eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*7594170eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*7594170eSAndroid Build Coastguard Worker# limitations under the License.
14*7594170eSAndroid Build Coastguard Worker
15*7594170eSAndroid Build Coastguard Workerload("@bazel_skylib//lib:paths.bzl", "paths")
16*7594170eSAndroid Build Coastguard Workerload("//build/bazel/rules:prebuilt_file.bzl", "PrebuiltFileInfo")
17*7594170eSAndroid Build Coastguard Worker
18*7594170eSAndroid Build Coastguard Workerdef _linker_config_impl(ctx):
19*7594170eSAndroid Build Coastguard Worker    output_file = ctx.actions.declare_file(paths.replace_extension(ctx.file.src.basename, ".pb"))
20*7594170eSAndroid Build Coastguard Worker
21*7594170eSAndroid Build Coastguard Worker    args = ctx.actions.args()
22*7594170eSAndroid Build Coastguard Worker    args.add("proto")
23*7594170eSAndroid Build Coastguard Worker    args.add("-s", ctx.file.src.path)
24*7594170eSAndroid Build Coastguard Worker    args.add("-o", output_file.path)
25*7594170eSAndroid Build Coastguard Worker
26*7594170eSAndroid Build Coastguard Worker    ctx.actions.run(
27*7594170eSAndroid Build Coastguard Worker        outputs = [output_file],
28*7594170eSAndroid Build Coastguard Worker        inputs = [ctx.file.src],
29*7594170eSAndroid Build Coastguard Worker        executable = ctx.executable._conv_linker_config,
30*7594170eSAndroid Build Coastguard Worker        arguments = [args],
31*7594170eSAndroid Build Coastguard Worker    )
32*7594170eSAndroid Build Coastguard Worker
33*7594170eSAndroid Build Coastguard Worker    return [
34*7594170eSAndroid Build Coastguard Worker        DefaultInfo(
35*7594170eSAndroid Build Coastguard Worker            files = depset([output_file]),
36*7594170eSAndroid Build Coastguard Worker        ),
37*7594170eSAndroid Build Coastguard Worker        PrebuiltFileInfo(
38*7594170eSAndroid Build Coastguard Worker            src = output_file,
39*7594170eSAndroid Build Coastguard Worker            dir = "etc",
40*7594170eSAndroid Build Coastguard Worker            filename = "linker.config.pb",
41*7594170eSAndroid Build Coastguard Worker        ),
42*7594170eSAndroid Build Coastguard Worker    ]
43*7594170eSAndroid Build Coastguard Worker
44*7594170eSAndroid Build Coastguard Workerlinker_config = rule(
45*7594170eSAndroid Build Coastguard Worker    doc = """
46*7594170eSAndroid Build Coastguard Worker    linker_config generates protobuf file from json file. This protobuf file will
47*7594170eSAndroid Build Coastguard Worker    be used from linkerconfig while generating ld.config.txt. Format of this file
48*7594170eSAndroid Build Coastguard Worker    can be found from
49*7594170eSAndroid Build Coastguard Worker    https://android.googlesource.com/platform/system/linkerconfig/+/master/README.md
50*7594170eSAndroid Build Coastguard Worker    """,
51*7594170eSAndroid Build Coastguard Worker    implementation = _linker_config_impl,
52*7594170eSAndroid Build Coastguard Worker    attrs = {
53*7594170eSAndroid Build Coastguard Worker        "src": attr.label(allow_single_file = [".json"], mandatory = True, doc = "source linker configuration property file"),
54*7594170eSAndroid Build Coastguard Worker        "_conv_linker_config": attr.label(default = "//build/soong/scripts:conv_linker_config", cfg = "exec", executable = True),
55*7594170eSAndroid Build Coastguard Worker    },
56*7594170eSAndroid Build Coastguard Worker)
57