2022-01-20 15:55:00 +01:00
|
|
|
// Copyright 2022 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 (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-10 04:07:19 +01:00
|
|
|
"android/soong/android"
|
2022-01-20 15:55:00 +01:00
|
|
|
"android/soong/cc"
|
2023-03-10 04:07:19 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2022-01-20 15:55:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const afdoFlagFormat = "-Zprofile-sample-use=%s"
|
|
|
|
|
|
|
|
type afdo struct {
|
|
|
|
Properties cc.AfdoProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func (afdo *afdo) props() []interface{} {
|
|
|
|
return []interface{}{&afdo.Properties}
|
|
|
|
}
|
|
|
|
|
2023-03-10 04:07:19 +01:00
|
|
|
func (afdo *afdo) addDep(ctx BaseModuleContext, actx android.BottomUpMutatorContext) {
|
|
|
|
// afdo is not supported outside of Android
|
|
|
|
if ctx.Host() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-04-12 02:43:00 +02:00
|
|
|
if mod, ok := ctx.Module().(*Module); ok && mod.Enabled(ctx) {
|
2023-03-10 04:07:19 +01:00
|
|
|
fdoProfileName, err := actx.DeviceConfig().AfdoProfile(actx.ModuleName())
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err.Error())
|
|
|
|
}
|
2024-01-24 01:38:06 +01:00
|
|
|
if fdoProfileName != "" {
|
2023-03-10 04:07:19 +01:00
|
|
|
actx.AddFarVariationDependencies(
|
|
|
|
[]blueprint.Variation{
|
|
|
|
{Mutator: "arch", Variation: actx.Target().ArchVariation()},
|
|
|
|
{Mutator: "os", Variation: "android"},
|
|
|
|
},
|
|
|
|
cc.FdoProfileTag,
|
2024-01-24 01:38:06 +01:00
|
|
|
[]string{fdoProfileName}...,
|
2023-03-10 04:07:19 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (afdo *afdo) flags(ctx android.ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
|
2022-01-20 15:55:00 +01:00
|
|
|
if ctx.Host() {
|
|
|
|
return flags, deps
|
|
|
|
}
|
|
|
|
|
2023-03-10 04:07:19 +01:00
|
|
|
if !afdo.Properties.Afdo {
|
|
|
|
return flags, deps
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.VisitDirectDepsWithTag(cc.FdoProfileTag, func(m android.Module) {
|
2023-12-13 22:47:44 +01:00
|
|
|
if info, ok := android.OtherModuleProvider(ctx, m, cc.FdoProfileProvider); ok {
|
2023-03-10 04:07:19 +01:00
|
|
|
path := info.Path
|
|
|
|
profileUseFlag := fmt.Sprintf(afdoFlagFormat, path.String())
|
2022-01-20 15:55:00 +01:00
|
|
|
flags.RustFlags = append(flags.RustFlags, profileUseFlag)
|
|
|
|
|
2023-03-10 04:07:19 +01:00
|
|
|
deps.AfdoProfiles = append(deps.AfdoProfiles, path)
|
2022-01-20 15:55:00 +01:00
|
|
|
}
|
2023-03-10 04:07:19 +01:00
|
|
|
})
|
|
|
|
|
2022-01-20 15:55:00 +01:00
|
|
|
return flags, deps
|
|
|
|
}
|