Revert "remove rust deps on clang prebuilts"

Revert submission 2758566

Reason for revert: b/301463284

Reverted changes: /q/submissionid:2758566

Change-Id: I54f0ecbbd922deb23009ca89ff79689e128f4f31
This commit is contained in:
Colin Cross 2023-09-22 22:02:28 +00:00 committed by Gerrit Code Review
parent 476e876119
commit 05cbcb3539
3 changed files with 43 additions and 30 deletions

View file

@ -22,7 +22,6 @@ import (
"github.com/google/blueprint"
"android/soong/android"
cc_config "android/soong/cc/config"
"android/soong/rust/config"
)
@ -205,9 +204,7 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderComma
}
}
envVars = append(envVars, "AR="+cmd.PathForInput(
cc_config.ClangPath(ctx, "bin/llvm-ar")),
)
envVars = append(envVars, "AR="+cmd.PathForTool(deps.Llvm_ar))
if ctx.Darwin() {
envVars = append(envVars, "ANDROID_RUST_DARWIN=true")
@ -295,6 +292,11 @@ 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")
@ -303,7 +305,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
clippyCmd.
Flags(rustEnvVars(ctx, deps, clippyCmd)).
Tool(config.RustPath(ctx, "bin/clippy-driver")).
Tool(deps.Clippy_driver).
Flag("--emit metadata").
FlagWithOutput("-o ", clippyFile).
FlagWithOutput("--emit dep-info=", clippyDepInfoFile).
@ -363,18 +365,14 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
}
}
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"),
)
// TODO(b/298461712) remove this hack to let slim manifest branches build
if deps.Rustc == nil {
deps.Rustc = config.RustPath(ctx, "bin/rustc")
}
rustcCmd.
Flags(rustEnvVars(ctx, deps, rustcCmd)).
Tool(config.RustPath(ctx, "bin/rustc")).
Tool(deps.Rustc).
FlagWithInput("-C linker=", android.PathForSource(ctx, "build", "soong", "scripts", "mkcratersp.py")).
Flag("--emit link").
Flag("-o").
@ -382,7 +380,6 @@ 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).
@ -409,20 +406,9 @@ 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(cc_config.ClangPath(ctx, "bin/clang++")).
Tool(deps.Clang).
Flag("-o").
Output(linkerSboxOutputFile).
Inputs(deps.CrtBegin).
@ -430,7 +416,6 @@ 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).
@ -456,7 +441,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(config.RustPath(ctx, "bin/rustc")).
Tool(deps.Rustc).
Flag("-C linker=true").
Inputs(inputs).
Flags(makeLibFlags(deps, kytheCmd)).
@ -470,6 +455,11 @@ 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()
@ -508,7 +498,7 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags) a
rustdocCmd.
Flags(rustEnvVars(ctx, deps, rustdocCmd)).
Tool(config.RustPath(ctx, "bin/rustdoc")).
Tool(deps.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, HostPrebuiltTag(ctx.Config()), rustVersion)
return android.PathForSource(ctx, rustBase, ctx.Config().PrebuiltOS(), rustVersion)
})
}

View file

@ -472,6 +472,13 @@ 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
@ -1473,9 +1480,18 @@ 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, ""))
@ -1596,6 +1612,13 @@ 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})