remove rust deps on clang prebuilts

Prebuilt modules for some clang tools were created in aosp/2746469, but they do not exist for darwin builds. Adding the same modules in prebuilts/clang/host/darwin-x86/Android.bp results in duplicate module names. Instead we can just get a path to these files directly in Soong.

Test: CI
Test: https://android-build.googleplex.com/builds/abtd/run/L90700000963131594
Change-Id: I620cfd7b1ab34bd0959feea562d599b963717198
This commit is contained in:
Sam Delmerico 2023-09-21 06:21:21 +00:00
parent fbec3a5f5c
commit 476e876119
3 changed files with 30 additions and 43 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/google/blueprint"
"android/soong/android"
cc_config "android/soong/cc/config"
"android/soong/rust/config"
)
@ -204,7 +205,9 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderComma
}
}
envVars = append(envVars, "AR="+cmd.PathForTool(deps.Llvm_ar))
envVars = append(envVars, "AR="+cmd.PathForInput(
cc_config.ClangPath(ctx, "bin/llvm-ar")),
)
if ctx.Darwin() {
envVars = append(envVars, "ANDROID_RUST_DARWIN=true")
@ -292,11 +295,6 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
}
if flags.Clippy {
// TODO(b/298461712) remove this hack to let slim manifest branches build
if deps.Clippy_driver == nil {
deps.Clippy_driver = config.RustPath(ctx, "bin/clippy-driver")
}
clippyRule := getRuleBuilder(ctx, pctx, false, "clippy")
clippyCmd := clippyRule.Command()
clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy")
@ -305,7 +303,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
clippyCmd.
Flags(rustEnvVars(ctx, deps, clippyCmd)).
Tool(deps.Clippy_driver).
Tool(config.RustPath(ctx, "bin/clippy-driver")).
Flag("--emit metadata").
FlagWithOutput("-o ", clippyFile).
FlagWithOutput("--emit dep-info=", clippyDepInfoFile).
@ -365,14 +363,18 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
}
}
// TODO(b/298461712) remove this hack to let slim manifest branches build
if deps.Rustc == nil {
deps.Rustc = config.RustPath(ctx, "bin/rustc")
clangTools := android.Paths{
cc_config.ClangPath(ctx, "bin/llvm-ar"),
}
if ctx.Config().BuildOS != android.Darwin {
clangTools = append(clangTools,
cc_config.ClangPath(ctx, "lib/libc++.so"),
)
}
rustcCmd.
Flags(rustEnvVars(ctx, deps, rustcCmd)).
Tool(deps.Rustc).
Tool(config.RustPath(ctx, "bin/rustc")).
FlagWithInput("-C linker=", android.PathForSource(ctx, "build", "soong", "scripts", "mkcratersp.py")).
Flag("--emit link").
Flag("-o").
@ -380,6 +382,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
FlagWithOutput("--emit dep-info=", depInfoFile).
Inputs(inputs).
Flags(libFlags).
Implicits(clangTools).
ImplicitTools(toolImplicits).
Implicits(implicits).
Flags(rustcFlags).
@ -406,9 +409,20 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
// those need to be renamed/symlinked to something in the rustLink sandbox
// if we want to separate the rules
linkerSboxOutputFile := android.PathForModuleOut(ctx, sboxDirectory, outputFile.Base())
clangTools := android.Paths{
cc_config.ClangPath(ctx, "bin/clang++"),
cc_config.ClangPath(ctx, "bin/lld"),
cc_config.ClangPath(ctx, "bin/ld.lld"),
}
if ctx.Config().BuildOS != android.Darwin {
clangTools = append(clangTools,
cc_config.ClangPath(ctx, "bin/clang++.real"),
cc_config.ClangPath(ctx, "lib/libc++.so"),
)
}
rustLinkCmd := rustcRule.Command()
rustLinkCmd.
Tool(deps.Clang).
Tool(cc_config.ClangPath(ctx, "bin/clang++")).
Flag("-o").
Output(linkerSboxOutputFile).
Inputs(deps.CrtBegin).
@ -416,6 +430,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
FlagWithInput("@", rustSboxOutputFile).
Flags(linkFlags).
Inputs(deps.CrtEnd).
ImplicitTools(clangTools).
ImplicitTools(toolImplicits).
Implicits(rustcImplicitOutputs.Paths()).
Implicits(implicits).
@ -441,7 +456,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
Flag("KYTHE_CANONICALIZE_VNAME_PATHS=prefer-relative").
Tool(ctx.Config().PrebuiltBuildTool(ctx, "rust_extractor")).
Flags(rustEnvVars(ctx, deps, kytheCmd)).
Tool(deps.Rustc).
Tool(config.RustPath(ctx, "bin/rustc")).
Flag("-C linker=true").
Inputs(inputs).
Flags(makeLibFlags(deps, kytheCmd)).
@ -455,11 +470,6 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
}
func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags) android.ModuleOutPath {
// TODO(b/298461712) remove this hack to let slim manifest branches build
if deps.Rustdoc == nil {
deps.Rustdoc = config.RustPath(ctx, "bin/rustdoc")
}
rustdocRule := getRuleBuilder(ctx, pctx, false, "rustdoc")
rustdocCmd := rustdocRule.Command()
@ -498,7 +508,7 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags) a
rustdocCmd.
Flags(rustEnvVars(ctx, deps, rustdocCmd)).
Tool(deps.Rustdoc).
Tool(config.RustPath(ctx, "bin/rustdoc")).
Flags(rustdocFlags).
Input(main).
Flag("-o "+docDir.String()).

View file

@ -147,6 +147,6 @@ func rustPath(ctx android.PathContext) android.SourcePath {
if override := ctx.Config().Getenv("RUST_DEFAULT_VERSION"); override != "" {
rustVersion = override
}
return android.PathForSource(ctx, rustBase, ctx.Config().PrebuiltOS(), rustVersion)
return android.PathForSource(ctx, rustBase, HostPrebuiltTag(ctx.Config()), rustVersion)
})
}

View file

@ -472,13 +472,6 @@ type PathDeps struct {
// Paths to generated source files
SrcDeps android.Paths
srcProviderFiles android.Paths
// Paths to specific build tools
Rustc android.Path
Clang android.Path
Llvm_ar android.Path
Clippy_driver android.Path
Rustdoc android.Path
}
type RustLibraries []RustLibrary
@ -1480,18 +1473,9 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.BuildToolDeps = append(depPaths.BuildToolDeps, buildTool.Deps...)
switch android.RemoveOptionalPrebuiltPrefix(dep.Name()) {
case "rustc":
depPaths.Rustc = buildTool.Src
// rustc expects the standard cc toolchain libraries (libdl, libm, libc, etc.)
// not to be under the __SBOX_SANDBOX_DIR__/ directory
depPaths.BuildToolSrcDeps = append(depPaths.BuildToolSrcDeps, buildTool.Deps...)
case "clang++":
depPaths.Clang = buildTool.Src
case "llvm-ar":
depPaths.Llvm_ar = buildTool.Src
case "clippy-driver":
depPaths.Clippy_driver = buildTool.Src
case "rustdoc":
depPaths.Rustdoc = buildTool.Src
}
case depTag == cc.CrtBeginDepTag:
depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
@ -1612,13 +1596,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "rustc")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "clippy-driver")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "rustdoc")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "clang++")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "clang++.real")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "lld")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "ld.lld")
ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "llvm-ar")
// rlibs
rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})