From ee6a89ba440aedbf7f1c89333f5046418e6e3459 Mon Sep 17 00:00:00 2001 From: ThiƩbaud Weksteen Date: Thu, 25 Feb 2021 16:30:57 +0100 Subject: Export OUT_DIR variable to rust-project.json This variable is required by rust-analyzer to correctly process crates that uses the include!(concat!(env!("OUT_DIR"), ...)) pattern. Adds an initialize method to baseCompiler to save the computed path for this directory. It is not possible to use the BeginMutator as the BaseModuleContext does not contain enough information to use PathForModuleOut. Bug: 175004835 Test: SOONG_GEN_RUST_PROJECT=1 m nothing; inspect rust-project.json Change-Id: If47b3832d3cca5712ae87773c174a61f5ee27bf8 --- rust/compiler.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'rust/compiler.go') diff --git a/rust/compiler.go b/rust/compiler.go index c26f208ee..98ad7ad1b 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -60,6 +60,7 @@ const ( InstallInData = iota incorrectSourcesError = "srcs can only contain one path for a rust file and source providers prefixed by \":\"" + genSubDir = "out/" ) type BaseCompilerProperties struct { @@ -154,6 +155,10 @@ type baseCompiler struct { distFile android.OptionalPath // Stripped output file. If Valid(), this file will be installed instead of outputFile. strippedOutputFile android.OptionalPath + + // If a crate has a source-generated dependency, a copy of the source file + // will be available in cargoOutDir (equivalent to Cargo OUT_DIR). + cargoOutDir android.ModuleOutPath } func (compiler *baseCompiler) Disabled() bool { @@ -243,6 +248,14 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD panic(fmt.Errorf("baseCrater doesn't know how to crate things!")) } +func (compiler *baseCompiler) initialize(ctx ModuleContext) { + compiler.cargoOutDir = android.PathForModuleOut(ctx, genSubDir) +} + +func (compiler *baseCompiler) CargoOutDir() android.OptionalPath { + return android.OptionalPathForPath(compiler.cargoOutDir) +} + func (compiler *baseCompiler) isDependencyRoot() bool { return false } -- cgit v1.2.3-59-g8ed1b