2019-08-27 21:03:00 +02:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// http://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.
|
|
|
|
|
|
|
|
package rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
2021-04-14 11:18:47 +02:00
|
|
|
"android/soong/bloaty"
|
2019-09-24 22:23:50 +02:00
|
|
|
"android/soong/cc"
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
2021-03-11 12:48:35 +01:00
|
|
|
// Preparer that will define all cc module types and a limited set of mutators and singletons that
|
|
|
|
// make those module types usable.
|
|
|
|
var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
|
2021-03-30 23:45:21 +02:00
|
|
|
android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
|
2021-03-11 12:48:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// The directory in which rust test default modules will be defined.
|
|
|
|
//
|
|
|
|
// Placing them here ensures that their location does not conflict with default test modules
|
|
|
|
// defined by other packages.
|
|
|
|
const rustDefaultsDir = "defaults/rust/"
|
|
|
|
|
|
|
|
// Preparer that will define default rust modules, e.g. standard prebuilt modules.
|
|
|
|
var PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers(
|
|
|
|
cc.PrepareForTestWithCcDefaultModules,
|
2021-04-14 11:18:47 +02:00
|
|
|
bloaty.PrepareForTestWithBloatyDefaultModules,
|
2021-03-11 12:48:35 +01:00
|
|
|
PrepareForTestWithRustBuildComponents,
|
|
|
|
android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Preparer that will allow use of all rust modules fully.
|
|
|
|
var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithRustDefaultModules,
|
|
|
|
)
|
|
|
|
|
2021-05-20 19:39:16 +02:00
|
|
|
var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers(
|
|
|
|
PrepareForIntegrationTestWithRust,
|
|
|
|
cc.PrepareForTestWithCcIncludeVndk,
|
|
|
|
)
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
func GatherRequiredDepsForTest() string {
|
|
|
|
bp := `
|
2020-06-25 09:47:46 +02:00
|
|
|
rust_prebuilt_library {
|
2021-11-11 15:29:07 +01:00
|
|
|
name: "libstd",
|
|
|
|
crate_name: "std",
|
|
|
|
rlib: {
|
|
|
|
srcs: ["libstd.rlib"],
|
|
|
|
},
|
|
|
|
dylib: {
|
|
|
|
srcs: ["libstd.so"],
|
|
|
|
},
|
2020-08-05 09:29:23 +02:00
|
|
|
host_supported: true,
|
2020-09-08 18:46:52 +02:00
|
|
|
sysroot: true,
|
2020-08-05 09:29:23 +02:00
|
|
|
}
|
2019-09-24 22:23:50 +02:00
|
|
|
//////////////////////////////
|
|
|
|
// Device module requirements
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "liblog",
|
|
|
|
no_libcrt: true,
|
|
|
|
nocrt: true,
|
|
|
|
system_shared_libs: [],
|
2020-11-17 14:21:02 +01:00
|
|
|
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
2020-12-04 21:05:43 +01:00
|
|
|
min_sdk_version: "29",
|
2021-04-02 18:41:32 +02:00
|
|
|
vendor_available: true,
|
2021-11-09 22:23:40 +01:00
|
|
|
recovery_available: true,
|
2021-06-01 21:09:53 +02:00
|
|
|
llndk: {
|
|
|
|
symbol_file: "liblog.map.txt",
|
|
|
|
},
|
2019-09-24 22:23:50 +02:00
|
|
|
}
|
2020-11-06 20:56:27 +01:00
|
|
|
cc_library {
|
|
|
|
name: "libprotobuf-cpp-full",
|
|
|
|
no_libcrt: true,
|
|
|
|
nocrt: true,
|
|
|
|
system_shared_libs: [],
|
|
|
|
export_include_dirs: ["libprotobuf-cpp-full-includes"],
|
|
|
|
}
|
2020-02-11 14:24:25 +01:00
|
|
|
cc_library {
|
2022-02-10 20:41:18 +01:00
|
|
|
name: "libclang_rt.asan",
|
2020-02-11 14:24:25 +01:00
|
|
|
no_libcrt: true,
|
|
|
|
nocrt: true,
|
|
|
|
system_shared_libs: [],
|
2021-11-01 15:13:25 +01:00
|
|
|
}
|
|
|
|
cc_library {
|
2022-02-10 20:41:18 +01:00
|
|
|
name: "libclang_rt.hwasan_static",
|
2021-11-01 15:13:25 +01:00
|
|
|
no_libcrt: true,
|
|
|
|
nocrt: true,
|
|
|
|
system_shared_libs: [],
|
2020-02-11 14:24:25 +01:00
|
|
|
}
|
2020-06-25 09:47:46 +02:00
|
|
|
rust_library {
|
2020-04-09 15:32:15 +02:00
|
|
|
name: "libstd",
|
|
|
|
crate_name: "std",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
no_stdlibs: true,
|
2023-01-25 01:36:02 +01:00
|
|
|
product_available: true,
|
2020-04-28 16:10:23 +02:00
|
|
|
host_supported: true,
|
2020-12-02 15:15:16 +01:00
|
|
|
vendor_available: true,
|
2021-02-05 16:57:43 +01:00
|
|
|
vendor_ramdisk_available: true,
|
2021-11-09 22:23:40 +01:00
|
|
|
recovery_available: true,
|
2021-03-22 19:29:47 +01:00
|
|
|
native_coverage: false,
|
2020-09-08 18:46:52 +02:00
|
|
|
sysroot: true,
|
2020-11-17 14:21:02 +01:00
|
|
|
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
2020-12-04 21:05:43 +01:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 15:32:15 +02:00
|
|
|
}
|
2020-06-25 09:47:46 +02:00
|
|
|
rust_library {
|
2020-04-09 15:32:15 +02:00
|
|
|
name: "libtest",
|
|
|
|
crate_name: "test",
|
|
|
|
srcs: ["foo.rs"],
|
2020-04-28 16:10:23 +02:00
|
|
|
host_supported: true,
|
2020-12-02 15:15:16 +01:00
|
|
|
vendor_available: true,
|
2021-02-05 16:57:43 +01:00
|
|
|
vendor_ramdisk_available: true,
|
2021-11-09 22:23:40 +01:00
|
|
|
recovery_available: true,
|
2021-03-22 19:29:47 +01:00
|
|
|
native_coverage: false,
|
2020-11-17 14:21:02 +01:00
|
|
|
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
2020-12-04 21:05:43 +01:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 15:32:15 +02:00
|
|
|
}
|
2020-08-21 12:01:58 +02:00
|
|
|
rust_library {
|
2023-04-24 11:28:25 +02:00
|
|
|
name: "libprotobuf",
|
|
|
|
crate_name: "protobuf",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
rust_library {
|
2023-03-22 15:09:00 +01:00
|
|
|
name: "libprotobuf_deprecated",
|
2020-08-21 12:01:58 +02:00
|
|
|
crate_name: "protobuf",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
2020-11-06 20:56:27 +01:00
|
|
|
rust_library {
|
|
|
|
name: "libgrpcio",
|
|
|
|
crate_name: "grpcio",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
rust_library {
|
|
|
|
name: "libfutures",
|
|
|
|
crate_name: "futures",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
2020-02-11 14:24:25 +01:00
|
|
|
rust_library {
|
|
|
|
name: "liblibfuzzer_sys",
|
|
|
|
crate_name: "libfuzzer_sys",
|
|
|
|
srcs:["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
2021-01-06 12:40:43 +01:00
|
|
|
rust_library {
|
|
|
|
name: "libcriterion",
|
|
|
|
crate_name: "criterion",
|
|
|
|
srcs:["foo.rs"],
|
|
|
|
host_supported: true,
|
|
|
|
}
|
2020-11-17 14:21:02 +01:00
|
|
|
`
|
2019-08-27 21:03:00 +02:00
|
|
|
return bp
|
|
|
|
}
|
|
|
|
|
2021-03-30 23:45:21 +02:00
|
|
|
func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
2021-01-06 12:40:43 +01:00
|
|
|
ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
|
|
|
|
ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
|
|
|
|
ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
|
2020-07-08 14:39:44 +02:00
|
|
|
ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
|
2020-09-29 09:53:21 +02:00
|
|
|
ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("rust_test", RustTestFactory)
|
|
|
|
ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
|
|
|
|
ctx.RegisterModuleType("rust_library", RustLibraryFactory)
|
2020-06-23 23:28:53 +02:00
|
|
|
ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
|
|
|
|
ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
|
|
|
|
ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
|
2020-06-23 23:28:53 +02:00
|
|
|
ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
|
2020-02-11 14:24:25 +01:00
|
|
|
ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
|
2020-06-23 23:28:53 +02:00
|
|
|
ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
|
|
|
|
ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
|
|
|
|
ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
|
|
|
|
ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
|
|
|
|
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
|
|
|
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
2020-08-21 12:01:58 +02:00
|
|
|
ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
|
|
|
|
ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
|
2020-06-25 09:47:46 +02:00
|
|
|
ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
2019-11-23 00:25:03 +01:00
|
|
|
ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
2020-06-25 09:47:46 +02:00
|
|
|
ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
2019-08-27 21:03:00 +02:00
|
|
|
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
2019-10-18 23:49:46 +02:00
|
|
|
// rust mutators
|
|
|
|
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
|
2020-09-08 18:46:52 +02:00
|
|
|
ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
|
2020-04-09 15:56:02 +02:00
|
|
|
ctx.BottomUp("rust_begin", BeginMutator).Parallel()
|
2019-10-18 23:49:46 +02:00
|
|
|
})
|
2020-06-05 11:09:27 +02:00
|
|
|
ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
|
2022-04-19 05:12:56 +02:00
|
|
|
ctx.RegisterSingletonType("kythe_rust_extract", kytheExtractRustFactory)
|
2021-11-01 15:13:25 +01:00
|
|
|
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
|
|
|
|
})
|
2021-06-01 21:09:53 +02:00
|
|
|
registerRustSnapshotModules(ctx)
|
2020-11-17 14:21:02 +01:00
|
|
|
}
|