aboutsummaryrefslogtreecommitdiff
path: root/rust/project_json.go
diff options
context:
space:
mode:
authormosimchah <mosimchah@gmail.com>2025-12-02 09:27:38 -0500
committermosimchah <mosimchah@gmail.com>2025-12-02 09:27:38 -0500
commitc7bade461dc55726f62997d13a48582f7c4b4655 (patch)
treeea0588da76060a2038f54f67efd046ca77634b10 /rust/project_json.go
parent0f5414d19317805e8bbbe7c4db5f0fd78769bad5 (diff)
parent89d78cff8b00d3b20a90074635c3fe5a2ee49474 (diff)
Merge branch 'lineage-23.1' of https://github.com/LineageOS/android_build_soong into HEADw16.1
* 'lineage-23.1' of https://github.com/LineageOS/android_build_soong: (528 commits) Revert "install_symlink: Make symlink target configurable" Reapply "Clear as much of cc.Module as possible after GenerateBuildActions" Revert "rust: config: Fix missing CPU variant LD flags in Rust" Rename build-flag in outdir Revert^4 "cipd: Default CIPD proxy server to on, add opt-out" Convert check-vintf-all to phony with actions Create a partial implementation of check-vintf-all for soong-only Configure RBE rust pool based on build variant Revert^3 "Add sdk version check to arr" Add jdk.internal.invoke to the allowlist Make droid always depend on symbols zip Import Device and Odm skus Don't install gob_gen in Soong Remove bazel reference from run_integration_tests.sh Fix bootstrap_test.sh Don't panic in aconfig libraries when AllowMissingDependencies is set Avoid returning nil paths from PathForModuleSrc Revert "Flag controled clang version" Rework module target dependencies on required deps Revert^2 "Add sdk version check to arr" ... Change-Id: I6e9a63fa14fda917a42e426e5dcebbad7f67e1de
Diffstat (limited to 'rust/project_json.go')
-rw-r--r--rust/project_json.go91
1 files changed, 54 insertions, 37 deletions
diff --git a/rust/project_json.go b/rust/project_json.go
index 6e8cebeed..be1bb9c75 100644
--- a/rust/project_json.go
+++ b/rust/project_json.go
@@ -18,6 +18,8 @@ import (
"encoding/json"
"fmt"
+ "github.com/google/blueprint/proptools"
+
"android/soong/android"
"android/soong/rust/config"
)
@@ -33,6 +35,7 @@ import (
const (
// Environment variables used to control the behavior of this singleton.
envVariableCollectRustDeps = "SOONG_GEN_RUST_PROJECT"
+ envVariableUseKythe = "XREF_CORPUS"
rustProjectJsonFileName = "rust-project.json"
)
@@ -83,23 +86,23 @@ func init() {
// mergeDependencies visits all the dependencies for module and updates crate and deps
// with any new dependency.
func (singleton *projectGeneratorSingleton) mergeDependencies(ctx android.SingletonContext,
- module *Module, crate *rustProjectCrate, deps map[string]int) {
+ module android.ModuleProxy, crate *rustProjectCrate, deps map[string]int) {
- ctx.VisitDirectDeps(module, func(child android.Module) {
+ ctx.VisitDirectDepsProxies(module, func(child android.ModuleProxy) {
// Skip intra-module dependencies (i.e., generated-source library depending on the source variant).
if module.Name() == child.Name() {
return
}
// Skip unsupported modules.
- rChild, ok := isModuleSupported(ctx, child)
+ rustInfo, commonInfo, ok := isModuleSupported(ctx, child)
if !ok {
return
}
// For unknown dependency, add it first.
var childId int
- cInfo, known := singleton.knownCrates[rChild.Name()]
+ cInfo, known := singleton.knownCrates[child.Name()]
if !known {
- childId, ok = singleton.addCrate(ctx, rChild)
+ childId, ok = singleton.addCrate(ctx, child, rustInfo, commonInfo)
if !ok {
return
}
@@ -110,44 +113,43 @@ func (singleton *projectGeneratorSingleton) mergeDependencies(ctx android.Single
if _, ok = deps[child.Name()]; ok {
return
}
- crate.Deps = append(crate.Deps, rustProjectDep{Crate: childId, Name: rChild.CrateName()})
+ crate.Deps = append(crate.Deps, rustProjectDep{Crate: childId, Name: rustInfo.CompilerInfo.CrateName})
deps[child.Name()] = childId
})
}
// isModuleSupported returns the RustModule if the module
// should be considered for inclusion in rust-project.json.
-func isModuleSupported(ctx android.SingletonContext, module android.Module) (*Module, bool) {
- rModule, ok := module.(*Module)
+func isModuleSupported(ctx android.SingletonContext, module android.ModuleProxy) (*RustInfo, *android.CommonModuleInfo, bool) {
+ info, ok := android.OtherModuleProvider(ctx, module, RustInfoProvider)
if !ok {
- return nil, false
+ return nil, nil, false
}
- if !rModule.Enabled(ctx) {
- return nil, false
+ commonInfo := android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoProvider)
+ if !commonInfo.Enabled {
+ return nil, nil, false
}
- return rModule, true
+ return info, commonInfo, true
}
// addCrate adds a crate to singleton.project.Crates ensuring that required
// dependencies are also added. It returns the index of the new crate in
// singleton.project.Crates
-func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContext, rModule *Module) (int, bool) {
+func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContext, module android.ModuleProxy, rustInfo *RustInfo,
+ commonInfo *android.CommonModuleInfo) (int, bool) {
+
deps := make(map[string]int)
- rootModule, err := rModule.compiler.checkedCrateRootPath()
- if err != nil {
- return 0, false
- }
var procMacroDylib *string = nil
- if procDec, procMacro := rModule.compiler.(*procMacroDecorator); procMacro {
- procMacroDylib = new(string)
- *procMacroDylib = procDec.baseCompiler.unstrippedOutputFilePath().String()
+
+ if procMacro := rustInfo.ProcMacroInfo; procMacro != nil {
+ procMacroDylib = proptools.StringPtr(procMacro.Dylib.String())
}
crate := rustProjectCrate{
- DisplayName: rModule.Name(),
- RootModule: rootModule.String(),
- Edition: rModule.compiler.edition(),
+ DisplayName: module.Name(),
+ RootModule: rustInfo.CompilerInfo.CrateRootPath.String(),
+ Edition: rustInfo.CompilerInfo.Edition,
Deps: make([]rustProjectDep, 0),
Cfg: make([]string, 0),
Env: make(map[string]string),
@@ -155,60 +157,60 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
ProcMacroDylib: procMacroDylib,
}
- if rModule.compiler.cargoOutDir().Valid() {
- crate.Env["OUT_DIR"] = rModule.compiler.cargoOutDir().String()
+ if cargoOutDir := rustInfo.CompilerInfo.CargoOutDir; cargoOutDir.Valid() {
+ crate.Env["OUT_DIR"] = cargoOutDir.String()
}
- for _, feature := range rModule.compiler.features(ctx, rModule) {
+ for _, feature := range rustInfo.CompilerInfo.Features {
crate.Cfg = append(crate.Cfg, "feature=\""+feature+"\"")
}
- singleton.mergeDependencies(ctx, rModule, &crate, deps)
+ singleton.mergeDependencies(ctx, module, &crate, deps)
var idx int
- if cInfo, ok := singleton.knownCrates[rModule.Name()]; ok {
+ if cInfo, ok := singleton.knownCrates[module.Name()]; ok {
idx = cInfo.Idx
singleton.project.Crates[idx] = crate
} else {
idx = len(singleton.project.Crates)
singleton.project.Crates = append(singleton.project.Crates, crate)
}
- singleton.knownCrates[rModule.Name()] = crateInfo{Idx: idx, Deps: deps, Device: rModule.Device()}
+ singleton.knownCrates[module.Name()] = crateInfo{Idx: idx, Deps: deps, Device: commonInfo.Target.Os.Class == android.Device}
return idx, true
}
// appendCrateAndDependencies creates a rustProjectCrate for the module argument and appends it to singleton.project.
// It visits the dependencies of the module depth-first so the dependency ID can be added to the current module. If the
// current module is already in singleton.knownCrates, its dependencies are merged.
-func (singleton *projectGeneratorSingleton) appendCrateAndDependencies(ctx android.SingletonContext, module android.Module) {
- rModule, ok := isModuleSupported(ctx, module)
+func (singleton *projectGeneratorSingleton) appendCrateAndDependencies(ctx android.SingletonContext, module android.ModuleProxy) {
+ rustInfo, commonInfo, ok := isModuleSupported(ctx, module)
if !ok {
return
}
// If we have seen this crate already; merge any new dependencies.
if cInfo, ok := singleton.knownCrates[module.Name()]; ok {
// If we have a new device variant, override the old one
- if !cInfo.Device && rModule.Device() {
- singleton.addCrate(ctx, rModule)
+ if !cInfo.Device && commonInfo.Target.Os.Class == android.Device {
+ singleton.addCrate(ctx, module, rustInfo, commonInfo)
return
}
crate := singleton.project.Crates[cInfo.Idx]
- singleton.mergeDependencies(ctx, rModule, &crate, cInfo.Deps)
+ singleton.mergeDependencies(ctx, module, &crate, cInfo.Deps)
singleton.project.Crates[cInfo.Idx] = crate
return
}
- singleton.addCrate(ctx, rModule)
+ singleton.addCrate(ctx, module, rustInfo, commonInfo)
}
func (singleton *projectGeneratorSingleton) GenerateBuildActions(ctx android.SingletonContext) {
- if !ctx.Config().IsEnvTrue(envVariableCollectRustDeps) {
+ if !(ctx.Config().IsEnvTrue(envVariableCollectRustDeps) || ctx.Config().Getenv(envVariableUseKythe) != "") {
return
}
singleton.project.Sysroot = config.RustPath(ctx)
singleton.knownCrates = make(map[string]crateInfo)
- ctx.VisitAllModules(func(module android.Module) {
+ ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
singleton.appendCrateAndDependencies(ctx, module)
})
@@ -217,6 +219,21 @@ func (singleton *projectGeneratorSingleton) GenerateBuildActions(ctx android.Sin
if err != nil {
ctx.Errorf(err.Error())
}
+ if ctx.Config().XrefCorpusName() != "" {
+ rule := android.NewRuleBuilder(pctx, ctx)
+ jsonPath := android.PathForOutput(ctx, "rust-project.json")
+ kzipPath := android.PathForOutput(ctx, "rust-project.kzip")
+ vnames := android.PathForSource(ctx, "build/soong/vnames.json")
+ rule.Command().PrebuiltBuildTool(ctx, "rust_project_to_kzip").
+ FlagWithInput("-project_json ", jsonPath).
+ FlagWithOutput("-output ", kzipPath).
+ FlagWithArg("-corpus ", ctx.Config().XrefCorpusName()).
+ FlagWithArg("-root ", "$PWD").
+ FlagWithInput("-vnames_json_path ", vnames)
+ ruleName := "rust3-extraction"
+ rule.Build(ruleName, "Turning Rust project into kzips")
+ ctx.Phony("xref_rust", kzipPath)
+ }
}
func createJsonFile(project rustProjectJson, rustProjectPath android.WritablePath) error {