1/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package {
18    default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
21cc_defaults {
22    name: "linkerconfig_defaults",
23    cflags: [
24        "-Wall",
25        "-Werror",
26        "-Wextra",
27    ],
28    defaults: ["libapexutil-deps"],
29    static_libs: [
30        "libapexutil",
31        "libbase",
32        "liblog",
33        "libprotobuf-cpp-lite",
34        "libxml2",
35        "lib_linker_config_proto_lite",
36    ],
37    target: {
38        host: {
39            static_libs: [
40                "libicui18n",
41                "libicuuc",
42            ],
43        },
44        not_windows: {
45            static_libs: ["libicuuc_stubdata"],
46        },
47    },
48    host_supported: true,
49}
50
51cc_defaults {
52    name: "linkerconfig_test_defaults",
53    defaults: ["linkerconfig_defaults"],
54    cflags: [
55        "-g",
56        "-Wunused",
57    ],
58    test_suites: ["general-tests"],
59}
60
61cc_library_static {
62    name: "linkerconfig_modules",
63    defaults: [ "linkerconfig_defaults" ],
64    export_include_dirs: [ "modules/include" ],
65    srcs: [
66        "modules/*.cc",
67    ],
68    generated_sources: ["apex-info-list"],
69    apex_available: [
70        "//apex_available:platform",
71        "com.android.runtime",
72    ],
73}
74
75cc_library_static {
76    name: "linkerconfig_contents",
77    defaults: [ "linkerconfig_defaults" ],
78    export_include_dirs: [ "contents/include" ],
79    static_libs: [
80        "linkerconfig_modules",
81    ],
82    srcs: [
83        "contents/namespace/*.cc",
84        "contents/section/*.cc",
85        "contents/configuration/*.cc",
86        "contents/context/*.cc",
87        "contents/common/*.cc",
88    ],
89    apex_available: [
90        "//apex_available:platform",
91        "com.android.runtime",
92    ],
93}
94
95cc_library_static {
96    name: "linkerconfig_generator",
97    defaults : [ "linkerconfig_defaults" ],
98    export_include_dirs: [ "generator/include" ],
99    static_libs: [
100        "linkerconfig_modules",
101        "linkerconfig_contents",
102    ],
103    srcs: [
104        "generator/*.cc",
105    ],
106    apex_available: [
107        "//apex_available:platform",
108        "com.android.runtime",
109    ],
110}
111
112cc_binary {
113    name: "linkerconfig",
114    defaults: [ "linkerconfig_defaults" ],
115    static_libs: [
116        "linkerconfig_modules",
117        "linkerconfig_contents",
118        "linkerconfig_generator",
119    ],
120    srcs: [
121        "main.cc",
122    ],
123    required: [
124        // files from /system/etc
125        "sanitizer.libraries.txt",
126        "vndkcorevariant.libraries.txt",
127        // Note that even thought linkerconfig requires at least one version of VNDK APEXes,
128        // we can't list it here because the exact version is unknown at build-time. It is decided
129        // at runtime according to ro.vndk.version (or ro.product.vndk.version)
130    ],
131    target: {
132        android: {
133            // This binary needs to be static on device, but it's also packaged
134            // as a host prebuilt in runtime-module-host-exports. On host it
135            // should link all libraries statically except libc and other system
136            // libraries, so enable this only on device.
137            static_executable: true,
138        },
139        host: {
140            stl: "c++_static",  // Link libc++ statically.
141        },
142    },
143
144    // Device does not boot when global ThinLTO is enabled for linkerconfig.
145    // http://b/170573443
146    lto: {
147        never: true,
148    },
149
150    apex_available: [
151        "//apex_available:platform",
152        "com.android.runtime",
153    ],
154}
155
156cc_test {
157    name: "linkerconfig_modules_unittest",
158    defaults: [ "linkerconfig_test_defaults" ],
159    srcs: [
160        "modules/tests/*_test.cc",
161    ],
162    static_libs: [
163        "libgmock",
164        "linkerconfig_modules",
165        "libc++fs",
166    ],
167    data: [
168        "modules/tests/data/linker.config.*",
169    ],
170}
171
172cc_test {
173    name: "linkerconfig_backward_compatibility_test",
174    defaults: [ "linkerconfig_test_defaults" ],
175    srcs: [
176        "contents/tests/backward_compatibility/*_test.cc",
177    ],
178    static_libs: [
179        "linkerconfig_modules",
180        "linkerconfig_contents",
181    ],
182}
183
184cc_test {
185    name: "linkerconfig_generator_unittest",
186    defaults: [ "linkerconfig_test_defaults" ],
187    srcs: [
188        "generator/tests/*_test.cc",
189    ],
190    static_libs: [
191        "linkerconfig_modules",
192        "linkerconfig_contents",
193        "linkerconfig_generator",
194    ],
195    data: [
196        "generator/tests/data/*.txt",
197    ],
198}
199
200cc_test {
201    name: "linkerconfig_contents_fulltest",
202    defaults: [ "linkerconfig_test_defaults" ],
203    local_include_dirs: [
204        "contents/tests/configuration/include",
205    ],
206    srcs: [
207        "contents/tests/configuration/*_test.cc",
208    ],
209    static_libs: [
210        "linkerconfig_modules",
211        "linkerconfig_contents",
212    ],
213}
214
215prebuilt_etc {
216    name: "ld.config.recovery.txt",
217    recovery: true,
218    filename: "ld.config.txt",
219    src: ":generate_recovery_linker_config",
220}
221
222genrule {
223    name: "generate_recovery_linker_config",
224    recovery: true,
225    out: ["ld.config.txt"],
226    tools: ["linkerconfig"],
227    cmd: "$(location linkerconfig) --recovery --target $(genDir)",
228}
229
230genrule {
231    name: "linkerconfig_diff_test_host_tools",
232    out: ["linkerconfig_diff_test_host_tools.zip"],
233    tools: ["conv_apex_manifest", "conv_linker_config", "linkerconfig", "soong_zip"],
234    cmd: "HOST_OUT_BIN=$$(dirname $(location conv_apex_manifest)) && " +
235         "HOST_SOONG_OUT=$$(dirname $$HOST_OUT_BIN) && " +
236         "LIBCPLUSPLUS=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libc++.*\") && " +
237         "mkdir -p $(genDir)/tools/bin && " +
238         "mkdir -p $(genDir)/tools/lib64 && " +
239         "cp $(location conv_apex_manifest) $(genDir)/tools/bin && " +
240         "cp $(location conv_linker_config) $(genDir)/tools/bin && " +
241         "cp $(location linkerconfig) $(genDir)/tools/bin && " +
242         "cp $$LIBCPLUSPLUS $(genDir)/tools/lib64 && " +
243         "$(location soong_zip) -C $(genDir)/tools -D $(genDir)/tools -o $(out)",
244}
245
246sh_test_host {
247    name: "linkerconfig_diff_test",
248    src: "rundiff.sh",
249    filename: "linkerconfig_diff_test.sh",
250    test_suites: ["general-tests"],
251    test_config: "linkerconfig_diff_test.xml",
252    data: [
253        "testdata/**/*",
254        "testdata/**/.*", // copy .keep files
255        // workaround to use host tools(conv_apex_manifest, linkerconfig) on build server
256        // ":conv_apex_manifest",
257        // ":linkerconfig",
258        ":linkerconfig_diff_test_host_tools",
259    ],
260}
261