blob: 6e4fb85c151632320e79c7148f5e4456c74ebb3a [file] [log] [blame]
Jakub Kotur1d640d02021-01-06 12:40:43 +01001// Copyright 2020 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
15package rust
16
17import (
18 "android/soong/android"
19)
20
21type BenchmarkProperties struct {
22}
23
24type benchmarkDecorator struct {
25 *binaryDecorator
26 Properties BenchmarkProperties
27 testConfig android.Path
28}
29
30func NewRustBenchmark(hod android.HostOrDeviceSupported) (*Module, *benchmarkDecorator) {
31 // Build both 32 and 64 targets for device benchmarks.
32 // Cannot build both for host benchmarks yet if the benchmark depends on
33 // something like proc-macro2 that cannot be built for both.
34 multilib := android.MultilibBoth
35 if hod != android.DeviceSupported && hod != android.HostAndDeviceSupported {
36 multilib = android.MultilibFirst
37 }
38 module := newModule(hod, multilib)
39
40 benchmark := &benchmarkDecorator{
41 binaryDecorator: &binaryDecorator{
42 baseCompiler: NewBaseCompiler("nativebench", "nativebench64", InstallInData),
43 },
44 }
45
46 module.compiler = benchmark
47 module.AddProperties(&benchmark.Properties)
48 return module, benchmark
49}
50
51func init() {
52 android.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
53 android.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
54}
55
56func RustBenchmarkFactory() android.Module {
57 module, _ := NewRustBenchmark(android.HostAndDeviceSupported)
58 return module.Init()
59}
60
61func RustBenchmarkHostFactory() android.Module {
62 module, _ := NewRustBenchmark(android.HostSupported)
63 return module.Init()
64}
65
66func (benchmark *benchmarkDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
67 return rlibAutoDep
68}
69
70func (benchmark *benchmarkDecorator) stdLinkage(ctx *depsContext) RustLinkage {
71 return RlibLinkage
72}
73
74func (benchmark *benchmarkDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
75 flags = benchmark.binaryDecorator.compilerFlags(ctx, flags)
76 return flags
77}
78
79func (benchmark *benchmarkDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
80 deps = benchmark.binaryDecorator.compilerDeps(ctx, deps)
81
82 deps.Rustlibs = append(deps.Rustlibs, "libcriterion")
83
84 return deps
85}
86
87func (benchmark *benchmarkDecorator) compilerProps() []interface{} {
88 return append(benchmark.binaryDecorator.compilerProps(), &benchmark.Properties)
89}