2019-08-27 21:03:00 +02:00
|
|
|
// Copyright 2019 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 (
|
2020-11-11 16:59:52 +01:00
|
|
|
"path/filepath"
|
2019-08-27 21:03:00 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-11-03 15:17:51 +01:00
|
|
|
"android/soong/rust/config"
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ = pctx.SourcePathVariable("rustcCmd", "${config.RustBin}/rustc")
|
|
|
|
rustc = pctx.AndroidStaticRule("rustc",
|
|
|
|
blueprint.RuleParams{
|
2020-07-10 03:03:28 +02:00
|
|
|
Command: "$envVars $rustcCmd " +
|
2019-08-27 21:03:00 +02:00
|
|
|
"-C linker=${config.RustLinker} " +
|
2019-09-20 20:00:37 +02:00
|
|
|
"-C link-args=\"${crtBegin} ${config.RustLinkerArgs} ${linkFlags} ${crtEnd}\" " +
|
2020-08-14 00:46:21 +02:00
|
|
|
"--emit link -o $out --emit dep-info=$out.d.raw $in ${libFlags} $rustcFlags" +
|
|
|
|
" && grep \"^$out:\" $out.d.raw > $out.d",
|
2019-08-27 21:03:00 +02:00
|
|
|
CommandDeps: []string{"$rustcCmd"},
|
2019-11-05 21:16:46 +01:00
|
|
|
// Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
|
2020-08-14 00:46:21 +02:00
|
|
|
// Rustc emits unneeded dependency lines for the .d and input .rs files.
|
|
|
|
// Those extra lines cause ninja warning:
|
|
|
|
// "warning: depfile has multiple output paths"
|
|
|
|
// For ninja, we keep/grep only the dependency rule for the rust $out file.
|
2019-11-05 21:16:46 +01:00
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Depfile: "$out.d",
|
2019-08-27 21:03:00 +02:00
|
|
|
},
|
2020-07-10 03:03:28 +02:00
|
|
|
"rustcFlags", "linkFlags", "libFlags", "crtBegin", "crtEnd", "envVars")
|
2020-04-09 15:56:02 +02:00
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
_ = pctx.SourcePathVariable("rustdocCmd", "${config.RustBin}/rustdoc")
|
|
|
|
rustdoc = pctx.AndroidStaticRule("rustdoc",
|
|
|
|
blueprint.RuleParams{
|
2021-04-28 02:12:02 +02:00
|
|
|
Command: "$envVars $rustdocCmd $rustdocFlags $in -o $outDir && " +
|
2021-03-19 23:06:02 +01:00
|
|
|
"touch $out",
|
|
|
|
CommandDeps: []string{"$rustdocCmd"},
|
|
|
|
},
|
|
|
|
"rustdocFlags", "outDir", "envVars")
|
|
|
|
|
2020-06-22 13:28:02 +02:00
|
|
|
_ = pctx.SourcePathVariable("clippyCmd", "${config.RustBin}/clippy-driver")
|
|
|
|
clippyDriver = pctx.AndroidStaticRule("clippy",
|
|
|
|
blueprint.RuleParams{
|
2020-07-21 19:28:27 +02:00
|
|
|
Command: "$envVars $clippyCmd " +
|
2020-06-22 13:28:02 +02:00
|
|
|
// Because clippy-driver uses rustc as backend, we need to have some output even during the linting.
|
|
|
|
// Use the metadata output as it has the smallest footprint.
|
2021-04-07 16:00:19 +02:00
|
|
|
"--emit metadata -o $out --emit dep-info=$out.d.raw $in ${libFlags} " +
|
|
|
|
"$rustcFlags $clippyFlags" +
|
|
|
|
" && grep \"^$out:\" $out.d.raw > $out.d",
|
2020-06-22 13:28:02 +02:00
|
|
|
CommandDeps: []string{"$clippyCmd"},
|
2021-04-07 16:00:19 +02:00
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Depfile: "$out.d",
|
2020-06-22 13:28:02 +02:00
|
|
|
},
|
2020-07-21 19:28:27 +02:00
|
|
|
"rustcFlags", "libFlags", "clippyFlags", "envVars")
|
2020-06-22 13:28:02 +02:00
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
zip = pctx.AndroidStaticRule("zip",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "cat $out.rsp | tr ' ' '\\n' | tr -d \\' | sort -u > ${out}.tmp && ${SoongZipCmd} -o ${out} -C $$OUT_DIR -l ${out}.tmp",
|
|
|
|
CommandDeps: []string{"${SoongZipCmd}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
})
|
2020-07-10 03:03:28 +02:00
|
|
|
|
|
|
|
cp = pctx.AndroidStaticRule("cp",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "cp `cat $outDir.rsp` $outDir",
|
|
|
|
Rspfile: "${outDir}.rsp",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
},
|
|
|
|
"outDir")
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
type buildOutput struct {
|
2021-01-15 01:03:18 +01:00
|
|
|
outputFile android.Path
|
2020-04-09 15:56:02 +02:00
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
2021-03-19 23:06:02 +01:00
|
|
|
outputFile android.WritablePath) buildOutput {
|
2021-10-26 00:37:43 +02:00
|
|
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
2019-11-20 19:14:33 +01:00
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
2021-03-19 23:06:02 +01:00
|
|
|
outputFile android.WritablePath) buildOutput {
|
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
2021-03-19 23:06:02 +01:00
|
|
|
outputFile android.WritablePath) buildOutput {
|
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
2021-03-19 23:06:02 +01:00
|
|
|
outputFile android.WritablePath) buildOutput {
|
2021-10-26 00:37:43 +02:00
|
|
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
2021-03-19 23:06:02 +01:00
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
2021-03-19 23:06:02 +01:00
|
|
|
outputFile android.WritablePath) buildOutput {
|
2021-10-26 00:37:43 +02:00
|
|
|
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
2021-03-19 23:06:02 +01:00
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
2021-03-19 23:06:02 +01:00
|
|
|
flags Flags, outputFile android.WritablePath) buildOutput {
|
|
|
|
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro")
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
|
|
|
var paths android.Paths
|
|
|
|
for _, lib := range libs {
|
|
|
|
paths = append(paths, lib.Path)
|
|
|
|
}
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
func makeLibFlags(deps PathDeps) []string {
|
|
|
|
var libFlags []string
|
|
|
|
|
|
|
|
// Collect library/crate flags
|
|
|
|
for _, lib := range deps.RLibs {
|
|
|
|
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
|
|
|
|
}
|
|
|
|
for _, lib := range deps.DyLibs {
|
|
|
|
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
|
|
|
|
}
|
|
|
|
for _, proc_macro := range deps.ProcMacros {
|
|
|
|
libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, path := range deps.linkDirs {
|
|
|
|
libFlags = append(libFlags, "-L "+path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return libFlags
|
|
|
|
}
|
|
|
|
|
|
|
|
func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
|
|
|
|
var envVars []string
|
|
|
|
|
|
|
|
// libstd requires a specific environment variable to be set. This is
|
|
|
|
// not officially documented and may be removed in the future. See
|
|
|
|
// https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs#L866.
|
|
|
|
if ctx.RustModule().CrateName() == "std" {
|
|
|
|
envVars = append(envVars, "STD_ENV_ARCH="+config.StdEnvArch[ctx.RustModule().Arch().ArchType])
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(deps.SrcDeps) > 0 {
|
|
|
|
moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
|
|
|
|
// We must calculate an absolute path for OUT_DIR since Rust's include! macro (which normally consumes this)
|
|
|
|
// assumes that paths are relative to the source file.
|
|
|
|
var outDirPrefix string
|
|
|
|
if !filepath.IsAbs(moduleGenDir.String()) {
|
|
|
|
// If OUT_DIR is not absolute, we use $$PWD to generate an absolute path (os.Getwd() returns '/')
|
|
|
|
outDirPrefix = "$$PWD/"
|
|
|
|
} else {
|
|
|
|
// If OUT_DIR is absolute, then moduleGenDir will be an absolute path, so we don't need to set this to anything.
|
|
|
|
outDirPrefix = ""
|
|
|
|
}
|
|
|
|
envVars = append(envVars, "OUT_DIR="+filepath.Join(outDirPrefix, moduleGenDir.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return envVars
|
|
|
|
}
|
|
|
|
|
2020-06-24 11:32:48 +02:00
|
|
|
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
2021-11-03 20:30:18 +01:00
|
|
|
outputFile android.WritablePath, crateType string) buildOutput {
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
var inputs android.Paths
|
2019-11-05 21:16:46 +01:00
|
|
|
var implicits android.Paths
|
2020-04-09 15:56:02 +02:00
|
|
|
var output buildOutput
|
2021-03-19 23:06:02 +01:00
|
|
|
var rustcFlags, linkFlags []string
|
2020-04-09 15:56:02 +02:00
|
|
|
var implicitOutputs android.WritablePaths
|
|
|
|
|
|
|
|
output.outputFile = outputFile
|
2020-12-21 18:11:10 +01:00
|
|
|
crateName := ctx.RustModule().CrateName()
|
2020-06-24 11:32:48 +02:00
|
|
|
targetTriple := ctx.toolchain().RustTriple()
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
envVars := rustEnvVars(ctx, deps)
|
2020-11-03 15:17:51 +01:00
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
inputs = append(inputs, main)
|
|
|
|
|
|
|
|
// Collect rustc flags
|
2019-09-20 20:00:37 +02:00
|
|
|
rustcFlags = append(rustcFlags, flags.GlobalRustFlags...)
|
2019-08-27 21:03:00 +02:00
|
|
|
rustcFlags = append(rustcFlags, flags.RustFlags...)
|
2021-11-03 20:30:18 +01:00
|
|
|
rustcFlags = append(rustcFlags, "--crate-type="+crateType)
|
2020-12-21 18:11:10 +01:00
|
|
|
if crateName != "" {
|
|
|
|
rustcFlags = append(rustcFlags, "--crate-name="+crateName)
|
2019-11-01 03:38:29 +01:00
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
if targetTriple != "" {
|
|
|
|
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
2019-09-20 20:00:37 +02:00
|
|
|
linkFlags = append(linkFlags, "-target "+targetTriple)
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2020-06-25 18:34:12 +02:00
|
|
|
|
|
|
|
// Suppress an implicit sysroot
|
|
|
|
rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
|
|
|
|
|
2019-09-20 20:00:37 +02:00
|
|
|
// Collect linker flags
|
|
|
|
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
|
|
|
linkFlags = append(linkFlags, flags.LinkFlags...)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2021-07-22 16:52:06 +02:00
|
|
|
// Check if this module needs to use the bootstrap linker
|
|
|
|
if ctx.RustModule().Bootstrap() && !ctx.RustModule().InRecovery() && !ctx.RustModule().InRamdisk() && !ctx.RustModule().InVendorRamdisk() {
|
|
|
|
dynamicLinker := "-Wl,-dynamic-linker,/system/bin/bootstrap/linker"
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
dynamicLinker += "64"
|
|
|
|
}
|
|
|
|
linkFlags = append(linkFlags, dynamicLinker)
|
|
|
|
}
|
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
libFlags := makeLibFlags(deps)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// Collect dependencies
|
2019-11-05 21:16:46 +01:00
|
|
|
implicits = append(implicits, rustLibsToPaths(deps.RLibs)...)
|
|
|
|
implicits = append(implicits, rustLibsToPaths(deps.DyLibs)...)
|
|
|
|
implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...)
|
|
|
|
implicits = append(implicits, deps.StaticLibs...)
|
2021-01-21 21:23:29 +01:00
|
|
|
implicits = append(implicits, deps.SharedLibDeps...)
|
2020-12-01 15:25:22 +01:00
|
|
|
implicits = append(implicits, deps.srcProviderFiles...)
|
2020-07-10 03:03:28 +02:00
|
|
|
|
2019-11-05 21:16:46 +01:00
|
|
|
if deps.CrtBegin.Valid() {
|
|
|
|
implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path())
|
2019-09-20 20:00:37 +02:00
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2020-07-10 03:03:28 +02:00
|
|
|
if len(deps.SrcDeps) > 0 {
|
2021-02-25 16:30:57 +01:00
|
|
|
moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
|
2020-07-10 03:03:28 +02:00
|
|
|
var outputs android.WritablePaths
|
|
|
|
|
|
|
|
for _, genSrc := range deps.SrcDeps {
|
2020-07-22 15:14:47 +02:00
|
|
|
if android.SuffixInList(outputs.Strings(), genSubDir+genSrc.Base()) {
|
2020-07-10 03:03:28 +02:00
|
|
|
ctx.PropertyErrorf("srcs",
|
|
|
|
"multiple source providers generate the same filename output: "+genSrc.Base())
|
|
|
|
}
|
2020-07-22 15:14:47 +02:00
|
|
|
outputs = append(outputs, android.PathForModuleOut(ctx, genSubDir+genSrc.Base()))
|
2020-07-10 03:03:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: cp,
|
2021-02-25 16:30:57 +01:00
|
|
|
Description: "cp " + moduleGenDir.Path().Rel(),
|
2020-07-10 03:03:28 +02:00
|
|
|
Outputs: outputs,
|
|
|
|
Inputs: deps.SrcDeps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"outDir": moduleGenDir.String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
implicits = append(implicits, outputs.Paths()...)
|
|
|
|
}
|
|
|
|
|
2021-02-22 10:52:22 +01:00
|
|
|
envVars = append(envVars, "ANDROID_RUST_VERSION="+config.RustDefaultVersion)
|
|
|
|
|
2021-08-11 21:13:43 +02:00
|
|
|
if ctx.RustModule().compiler.CargoEnvCompat() {
|
|
|
|
if _, ok := ctx.RustModule().compiler.(*binaryDecorator); ok {
|
|
|
|
envVars = append(envVars, "CARGO_BIN_NAME="+strings.TrimSuffix(outputFile.Base(), outputFile.Ext()))
|
|
|
|
}
|
|
|
|
envVars = append(envVars, "CARGO_CRATE_NAME="+ctx.RustModule().CrateName())
|
|
|
|
pkgVersion := ctx.RustModule().compiler.CargoPkgVersion()
|
|
|
|
if pkgVersion != "" {
|
|
|
|
envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 19:28:27 +02:00
|
|
|
if flags.Clippy {
|
|
|
|
clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: clippyDriver,
|
|
|
|
Description: "clippy " + main.Rel(),
|
|
|
|
Output: clippyFile,
|
|
|
|
ImplicitOutputs: nil,
|
|
|
|
Inputs: inputs,
|
|
|
|
Implicits: implicits,
|
|
|
|
Args: map[string]string{
|
|
|
|
"rustcFlags": strings.Join(rustcFlags, " "),
|
|
|
|
"libFlags": strings.Join(libFlags, " "),
|
|
|
|
"clippyFlags": strings.Join(flags.ClippyFlags, " "),
|
|
|
|
"envVars": strings.Join(envVars, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
// Declare the clippy build as an implicit dependency of the original crate.
|
|
|
|
implicits = append(implicits, clippyFile)
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-04-09 15:56:02 +02:00
|
|
|
Rule: rustc,
|
|
|
|
Description: "rustc " + main.Rel(),
|
|
|
|
Output: outputFile,
|
|
|
|
ImplicitOutputs: implicitOutputs,
|
|
|
|
Inputs: inputs,
|
|
|
|
Implicits: implicits,
|
2019-08-27 21:03:00 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"rustcFlags": strings.Join(rustcFlags, " "),
|
2019-09-20 20:00:37 +02:00
|
|
|
"linkFlags": strings.Join(linkFlags, " "),
|
2019-08-27 21:03:00 +02:00
|
|
|
"libFlags": strings.Join(libFlags, " "),
|
2019-11-05 21:16:46 +01:00
|
|
|
"crtBegin": deps.CrtBegin.String(),
|
|
|
|
"crtEnd": deps.CrtEnd.String(),
|
2020-07-10 03:03:28 +02:00
|
|
|
"envVars": strings.Join(envVars, " "),
|
2019-08-27 21:03:00 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
return output
|
|
|
|
}
|
2021-03-19 23:06:02 +01:00
|
|
|
|
|
|
|
func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps,
|
|
|
|
flags Flags) android.ModuleOutPath {
|
|
|
|
|
|
|
|
rustdocFlags := append([]string{}, flags.RustdocFlags...)
|
|
|
|
rustdocFlags = append(rustdocFlags, "--sysroot=/dev/null")
|
|
|
|
|
2021-04-28 02:12:02 +02:00
|
|
|
// Build an index for all our crates. -Z unstable options is required to use
|
|
|
|
// this flag.
|
|
|
|
rustdocFlags = append(rustdocFlags, "-Z", "unstable-options", "--enable-index-page")
|
|
|
|
|
2021-03-19 23:06:02 +01:00
|
|
|
targetTriple := ctx.toolchain().RustTriple()
|
|
|
|
|
|
|
|
// Collect rustc flags
|
|
|
|
if targetTriple != "" {
|
|
|
|
rustdocFlags = append(rustdocFlags, "--target="+targetTriple)
|
|
|
|
}
|
|
|
|
|
|
|
|
crateName := ctx.RustModule().CrateName()
|
2021-04-28 02:12:02 +02:00
|
|
|
rustdocFlags = append(rustdocFlags, "--crate-name "+crateName)
|
2021-03-19 23:06:02 +01:00
|
|
|
|
|
|
|
rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
|
|
|
|
docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
|
2021-04-28 02:12:02 +02:00
|
|
|
|
2021-07-30 22:25:42 +02:00
|
|
|
// Silence warnings about renamed lints for third-party crates
|
|
|
|
modulePath := android.PathForModuleSrc(ctx).String()
|
|
|
|
if android.IsThirdPartyPath(modulePath) {
|
|
|
|
rustdocFlags = append(rustdocFlags, " -A renamed_and_removed_lints")
|
|
|
|
}
|
2021-07-28 21:07:16 +02:00
|
|
|
|
2021-04-28 02:12:02 +02:00
|
|
|
// Yes, the same out directory is used simultaneously by all rustdoc builds.
|
|
|
|
// This is what cargo does. The docs for individual crates get generated to
|
|
|
|
// a subdirectory named for the crate, and rustdoc synchronizes writes to
|
|
|
|
// shared pieces like the index and search data itself.
|
|
|
|
// https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/render/write_shared.rs#L144-L146
|
|
|
|
docDir := android.PathForOutput(ctx, "rustdoc")
|
2021-03-19 23:06:02 +01:00
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: rustdoc,
|
|
|
|
Description: "rustdoc " + main.Rel(),
|
|
|
|
Output: docTimestampFile,
|
|
|
|
Input: main,
|
2021-11-05 21:36:47 +01:00
|
|
|
Implicit: ctx.RustModule().UnstrippedOutputFile(),
|
2021-03-19 23:06:02 +01:00
|
|
|
Args: map[string]string{
|
|
|
|
"rustdocFlags": strings.Join(rustdocFlags, " "),
|
|
|
|
"outDir": docDir.String(),
|
|
|
|
"envVars": strings.Join(rustEnvVars(ctx, deps), " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return docTimestampFile
|
|
|
|
}
|