summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/builder.go6
-rw-r--r--rust/compiler.go4
-rw-r--r--rust/compiler_test.go35
-rw-r--r--rust/config/allowed_list.go1
-rw-r--r--rust/fuzz.go10
-rw-r--r--rust/rust.go40
6 files changed, 83 insertions, 13 deletions
diff --git a/rust/builder.go b/rust/builder.go
index 426a569bf..f79cf9b12 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -95,7 +95,7 @@ func init() {
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
}
@@ -112,13 +112,13 @@ func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
}
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
outputFile android.WritablePath) buildOutput {
- flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto")
+ flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
}
diff --git a/rust/compiler.go b/rust/compiler.go
index 1ce71f60b..cada9854a 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -449,6 +449,10 @@ func (compiler *baseCompiler) relativeInstallPath() string {
// Returns the Path for the main source file along with Paths for generated source files from modules listed in srcs.
func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
+ if len(srcs) == 0 {
+ ctx.PropertyErrorf("srcs", "srcs must not be empty")
+ }
+
// The srcs can contain strings with prefix ":".
// They are dependent modules of this module, with android.SourceDepTag.
// They are not the main source file compiled by rustc.
diff --git a/rust/compiler_test.go b/rust/compiler_test.go
index f589b691d..ec6829a1b 100644
--- a/rust/compiler_test.go
+++ b/rust/compiler_test.go
@@ -98,6 +98,41 @@ func TestEnforceSingleSourceFile(t *testing.T) {
}`)
}
+// Test that we reject _no_ source files.
+func TestEnforceMissingSourceFiles(t *testing.T) {
+
+ singleSrcError := "srcs must not be empty"
+
+ // Test libraries
+ testRustError(t, singleSrcError, `
+ rust_library_host {
+ name: "foo-bar-library",
+ crate_name: "foo",
+ }`)
+
+ // Test binaries
+ testRustError(t, singleSrcError, `
+ rust_binary_host {
+ name: "foo-bar-binary",
+ crate_name: "foo",
+ }`)
+
+ // Test proc_macros
+ testRustError(t, singleSrcError, `
+ rust_proc_macro {
+ name: "foo-bar-proc-macro",
+ crate_name: "foo",
+ }`)
+
+ // Test prebuilts
+ testRustError(t, singleSrcError, `
+ rust_prebuilt_dylib {
+ name: "foo-bar-prebuilt",
+ crate_name: "foo",
+ host_supported: true,
+ }`)
+}
+
// Test environment vars for Cargo compat are set.
func TestCargoCompat(t *testing.T) {
ctx := testRust(t, `
diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go
index 47ca3a7ec..b11357383 100644
--- a/rust/config/allowed_list.go
+++ b/rust/config/allowed_list.go
@@ -32,6 +32,7 @@ var (
"system/security",
"system/tools/aidl",
"tools/security/fuzzing/example_rust_fuzzer",
+ "tools/security/fuzzing/orphans",
"vendor/",
}
diff --git a/rust/fuzz.go b/rust/fuzz.go
index 5fb56ff40..a628b6158 100644
--- a/rust/fuzz.go
+++ b/rust/fuzz.go
@@ -111,6 +111,10 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
// List of individual fuzz targets.
s.FuzzTargets = make(map[string]bool)
+ // Map tracking whether each shared library has an install rule to avoid duplicate install rules from
+ // multiple fuzzers that depend on the same shared library.
+ sharedLibraryInstalled := make(map[string]bool)
+
ctx.VisitAllModules(func(module android.Module) {
// Discard non-fuzz targets.
rustModule, ok := module.(*Module)
@@ -145,6 +149,12 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
// The executable.
files = append(files, fuzz.FileToZip{rustModule.unstrippedOutputFile.Path(), ""})
+ // Grab the list of required shared libraries.
+ sharedLibraries := fuzz.CollectAllSharedDependencies(ctx, module, cc.UnstrippedOutputFile, cc.IsValidSharedDependency)
+
+ // Package shared libraries
+ files = append(files, cc.GetSharedLibsToZip(sharedLibraries, rustModule, &s.FuzzPackager, archString, &sharedLibraryInstalled)...)
+
archDirs[archOs], ok = s.BuildZipFile(ctx, module, fuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
if !ok {
return
diff --git a/rust/rust.go b/rust/rust.go
index b9afc7f82..13169f17e 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -130,9 +130,10 @@ type BaseProperties struct {
// Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
Min_sdk_version *string
- PreventInstall bool
- HideFromMake bool
- Installable *bool
+ HideFromMake bool `blueprint:"mutated"`
+ PreventInstall bool `blueprint:"mutated"`
+
+ Installable *bool
}
type Module struct {
@@ -177,8 +178,8 @@ func (mod *Module) SetHideFromMake() {
mod.Properties.HideFromMake = true
}
-func (c *Module) HiddenFromMake() bool {
- return c.Properties.HideFromMake
+func (mod *Module) HiddenFromMake() bool {
+ return mod.Properties.HideFromMake
}
func (mod *Module) SanitizePropDefined() bool {
@@ -526,10 +527,6 @@ func (mod *Module) PreventInstall() bool {
return mod.Properties.PreventInstall
}
-func (mod *Module) HideFromMake() {
- mod.Properties.HideFromMake = true
-}
-
func (mod *Module) MarkAsCoverageVariant(coverage bool) {
mod.coverage.Properties.IsCoverageVariant = coverage
}
@@ -597,6 +594,13 @@ func (mod *Module) CcLibraryInterface() bool {
return false
}
+func (mod *Module) UnstrippedOutputFile() android.Path {
+ if mod.unstrippedOutputFile.Valid() {
+ return mod.unstrippedOutputFile.Path()
+ }
+ return nil
+}
+
func (mod *Module) IncludeDirs() android.Paths {
if mod.compiler != nil {
if library, ok := mod.compiler.(*libraryDecorator); ok {
@@ -898,8 +902,24 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
}
apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
- if mod.installable(apexInfo) {
+ if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
+ // If the module has been specifically configure to not be installed then
+ // hide from make as otherwise it will break when running inside make as the
+ // output path to install will not be specified. Not all uninstallable
+ // modules can be hidden from make as some are needed for resolving make
+ // side dependencies.
+ mod.HideFromMake()
+ } else if !mod.installable(apexInfo) {
+ mod.SkipInstall()
+ }
+
+ // Still call install though, the installs will be stored as PackageSpecs to allow
+ // using the outputs in a genrule.
+ if mod.OutputFile().Valid() {
mod.compiler.install(ctx)
+ if ctx.Failed() {
+ return
+ }
}
ctx.Phony("rust", ctx.RustModule().OutputFile().Path())