summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/androidmk.go16
-rw-r--r--rust/benchmark.go1
-rw-r--r--rust/config/global.go1
-rw-r--r--rust/fuzz.go171
-rw-r--r--rust/library.go6
-rw-r--r--rust/library_test.go16
-rw-r--r--rust/rust.go4
-rw-r--r--rust/test.go8
-rw-r--r--rust/testing.go2
-rw-r--r--rust/vendor_snapshot_test.go23
10 files changed, 68 insertions, 180 deletions
diff --git a/rust/androidmk.go b/rust/androidmk.go
index ea45ebd01..630805a85 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -205,24 +205,24 @@ func (fuzz *fuzzDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *andro
ctx.SubAndroidMk(entries, fuzz.binaryDecorator)
var fuzzFiles []string
- for _, d := range fuzz.corpus {
+ for _, d := range fuzz.fuzzPackagedModule.Corpus {
fuzzFiles = append(fuzzFiles,
- filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base())
+ filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
}
- for _, d := range fuzz.data {
+ for _, d := range fuzz.fuzzPackagedModule.Data {
fuzzFiles = append(fuzzFiles,
- filepath.Dir(fuzz.dataIntermediateDir.String())+":data/"+d.Rel())
+ filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
}
- if fuzz.dictionary != nil {
+ if fuzz.fuzzPackagedModule.Dictionary != nil {
fuzzFiles = append(fuzzFiles,
- filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
+ filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
}
- if fuzz.config != nil {
+ if fuzz.fuzzPackagedModule.Config != nil {
fuzzFiles = append(fuzzFiles,
- filepath.Dir(fuzz.config.String())+":config.json")
+ filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
}
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext,
diff --git a/rust/benchmark.go b/rust/benchmark.go
index b89f5cd9b..0e842435d 100644
--- a/rust/benchmark.go
+++ b/rust/benchmark.go
@@ -101,6 +101,7 @@ func (benchmark *benchmarkDecorator) compilerFlags(ctx ModuleContext, flags Flag
func (benchmark *benchmarkDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps = benchmark.binaryDecorator.compilerDeps(ctx, deps)
+ deps.Rustlibs = append(deps.Rustlibs, "libtest")
deps.Rustlibs = append(deps.Rustlibs, "libcriterion")
return deps
diff --git a/rust/config/global.go b/rust/config/global.go
index 43b49d18b..1b56237b3 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -29,7 +29,6 @@ var (
DefaultEdition = "2018"
Stdlibs = []string{
"libstd",
- "libtest",
}
// Mapping between Soong internal arch types and std::env constants.
diff --git a/rust/fuzz.go b/rust/fuzz.go
index 7e1c55a50..18b25130f 100644
--- a/rust/fuzz.go
+++ b/rust/fuzz.go
@@ -32,13 +32,7 @@ func init() {
type fuzzDecorator struct {
*binaryDecorator
- Properties cc.FuzzProperties
- dictionary android.Path
- corpus android.Paths
- corpusIntermediateDir android.Path
- config android.Path
- data android.Paths
- dataIntermediateDir android.Path
+ fuzzPackagedModule cc.FuzzPackagedModule
}
var _ compiler = (*binaryDecorator)(nil)
@@ -88,7 +82,7 @@ func (fuzzer *fuzzDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
func (fuzzer *fuzzDecorator) compilerProps() []interface{} {
return append(fuzzer.binaryDecorator.compilerProps(),
- &fuzzer.Properties)
+ &fuzzer.fuzzPackagedModule.FuzzProperties)
}
func (fuzzer *fuzzDecorator) stdLinkage(ctx *depsContext) RustLinkage {
@@ -102,32 +96,19 @@ func (fuzzer *fuzzDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep
// Responsible for generating GNU Make rules that package fuzz targets into
// their architecture & target/host specific zip file.
type rustFuzzPackager struct {
- packages android.Paths
- fuzzTargets map[string]bool
+ cc.FuzzPackager
}
func rustFuzzPackagingFactory() android.Singleton {
return &rustFuzzPackager{}
}
-type fileToZip struct {
- SourceFilePath android.Path
- DestinationPathPrefix string
-}
-
-type archOs struct {
- hostOrTarget string
- arch string
- dir string
-}
-
func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
-
// Map between each architecture + host/device combination.
- archDirs := make(map[archOs][]fileToZip)
+ archDirs := make(map[cc.ArchOs][]cc.FileToZip)
// List of individual fuzz targets.
- s.fuzzTargets = make(map[string]bool)
+ s.FuzzTargets = make(map[string]bool)
ctx.VisitAllModules(func(module android.Module) {
// Discard non-fuzz targets.
@@ -136,20 +117,12 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
return
}
- fuzzModule, ok := rustModule.compiler.(*fuzzDecorator)
- if !ok {
+ if ok := cc.IsValid(rustModule.FuzzModule); !ok || rustModule.Properties.PreventInstall {
return
}
- // Discard ramdisk + vendor_ramdisk + recovery modules, they're duplicates of
- // fuzz targets we're going to package anyway.
- if !rustModule.Enabled() || rustModule.Properties.PreventInstall ||
- rustModule.InRamdisk() || rustModule.InVendorRamdisk() || rustModule.InRecovery() {
- return
- }
-
- // Discard modules that are in an unavailable namespace.
- if !rustModule.ExportedToMake() {
+ fuzzModule, ok := rustModule.compiler.(*fuzzDecorator)
+ if !ok {
return
}
@@ -160,126 +133,34 @@ func (s *rustFuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
archString := rustModule.Arch().ArchType.String()
archDir := android.PathForIntermediates(ctx, "fuzz", hostOrTargetString, archString)
- archOs := archOs{hostOrTarget: hostOrTargetString, arch: archString, dir: archDir.String()}
+ archOs := cc.ArchOs{HostOrTarget: hostOrTargetString, Arch: archString, Dir: archDir.String()}
- var files []fileToZip
+ var files []cc.FileToZip
builder := android.NewRuleBuilder(pctx, ctx)
- // Package the corpora into a zipfile.
- if fuzzModule.corpus != nil {
- corpusZip := archDir.Join(ctx, module.Name()+"_seed_corpus.zip")
- command := builder.Command().BuiltTool("soong_zip").
- Flag("-j").
- FlagWithOutput("-o ", corpusZip)
- rspFile := corpusZip.ReplaceExtension(ctx, "rsp")
- command.FlagWithRspFileInputList("-r ", rspFile, fuzzModule.corpus)
- files = append(files, fileToZip{corpusZip, ""})
- }
-
- // Package the data into a zipfile.
- if fuzzModule.data != nil {
- dataZip := archDir.Join(ctx, module.Name()+"_data.zip")
- command := builder.Command().BuiltTool("soong_zip").
- FlagWithOutput("-o ", dataZip)
- for _, f := range fuzzModule.data {
- intermediateDir := strings.TrimSuffix(f.String(), f.Rel())
- command.FlagWithArg("-C ", intermediateDir)
- command.FlagWithInput("-f ", f)
- }
- files = append(files, fileToZip{dataZip, ""})
- }
+ // Package the artifacts (data, corpus, config and dictionary into a zipfile.
+ files = s.PackageArtifacts(ctx, module, fuzzModule.fuzzPackagedModule, archDir, builder)
// The executable.
- files = append(files, fileToZip{rustModule.unstrippedOutputFile.Path(), ""})
-
- // The dictionary.
- if fuzzModule.dictionary != nil {
- files = append(files, fileToZip{fuzzModule.dictionary, ""})
- }
+ files = append(files, cc.FileToZip{rustModule.unstrippedOutputFile.Path(), ""})
- // Additional fuzz config.
- if fuzzModule.config != nil {
- files = append(files, fileToZip{fuzzModule.config, ""})
- }
-
- fuzzZip := archDir.Join(ctx, module.Name()+".zip")
-
- command := builder.Command().BuiltTool("soong_zip").
- Flag("-j").
- FlagWithOutput("-o ", fuzzZip)
-
- for _, file := range files {
- if file.DestinationPathPrefix != "" {
- command.FlagWithArg("-P ", file.DestinationPathPrefix)
- } else {
- command.Flag("-P ''")
- }
- command.FlagWithInput("-f ", file.SourceFilePath)
- }
-
- builder.Build("create-"+fuzzZip.String(),
- "Package "+module.Name()+" for "+archString+"-"+hostOrTargetString)
-
- // Don't add modules to 'make haiku-rust' that are set to not be
- // exported to the fuzzing infrastructure.
- if config := fuzzModule.Properties.Fuzz_config; config != nil {
- if rustModule.Host() && !BoolDefault(config.Fuzz_on_haiku_host, true) {
- return
- } else if !BoolDefault(config.Fuzz_on_haiku_device, true) {
- return
- }
+ archDirs[archOs], ok = s.BuildZipFile(ctx, module, fuzzModule.fuzzPackagedModule, files, builder, archDir, archString, hostOrTargetString, archOs, archDirs)
+ if !ok {
+ return
}
- s.fuzzTargets[module.Name()] = true
- archDirs[archOs] = append(archDirs[archOs], fileToZip{fuzzZip, ""})
})
-
- var archOsList []archOs
- for archOs := range archDirs {
- archOsList = append(archOsList, archOs)
- }
- sort.Slice(archOsList, func(i, j int) bool { return archOsList[i].dir < archOsList[j].dir })
-
- for _, archOs := range archOsList {
- filesToZip := archDirs[archOs]
- arch := archOs.arch
- hostOrTarget := archOs.hostOrTarget
- builder := android.NewRuleBuilder(pctx, ctx)
- outputFile := android.PathForOutput(ctx, "fuzz-rust-"+hostOrTarget+"-"+arch+".zip")
- s.packages = append(s.packages, outputFile)
-
- command := builder.Command().BuiltTool("soong_zip").
- Flag("-j").
- FlagWithOutput("-o ", outputFile).
- Flag("-L 0") // No need to try and re-compress the zipfiles.
-
- for _, fileToZip := range filesToZip {
- if fileToZip.DestinationPathPrefix != "" {
- command.FlagWithArg("-P ", fileToZip.DestinationPathPrefix)
- } else {
- command.Flag("-P ''")
- }
- command.FlagWithInput("-f ", fileToZip.SourceFilePath)
- }
- builder.Build("create-fuzz-package-"+arch+"-"+hostOrTarget,
- "Create fuzz target packages for "+arch+"-"+hostOrTarget)
- }
-
+ s.CreateFuzzPackage(ctx, archDirs, cc.Rust)
}
func (s *rustFuzzPackager) MakeVars(ctx android.MakeVarsContext) {
- packages := s.packages.Strings()
+ packages := s.Packages.Strings()
sort.Strings(packages)
ctx.Strict("SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES", strings.Join(packages, " "))
- // Preallocate the slice of fuzz targets to minimise memory allocations.
- fuzzTargets := make([]string, 0, len(s.fuzzTargets))
- for target, _ := range s.fuzzTargets {
- fuzzTargets = append(fuzzTargets, target)
- }
- sort.Strings(fuzzTargets)
- ctx.Strict("ALL_RUST_FUZZ_TARGETS", strings.Join(fuzzTargets, " "))
+ // Preallocate the slice of fuzz targets to minimize memory allocations.
+ s.PreallocateSlice(ctx, "ALL_RUST_FUZZ_TARGETS")
}
func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
@@ -289,13 +170,13 @@ func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzz.binaryDecorator.baseCompiler.install(ctx)
- if fuzz.Properties.Corpus != nil {
- fuzz.corpus = android.PathsForModuleSrc(ctx, fuzz.Properties.Corpus)
+ if fuzz.fuzzPackagedModule.FuzzProperties.Corpus != nil {
+ fuzz.fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzz.fuzzPackagedModule.FuzzProperties.Corpus)
}
- if fuzz.Properties.Data != nil {
- fuzz.data = android.PathsForModuleSrc(ctx, fuzz.Properties.Data)
+ if fuzz.fuzzPackagedModule.FuzzProperties.Data != nil {
+ fuzz.fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzz.fuzzPackagedModule.FuzzProperties.Data)
}
- if fuzz.Properties.Dictionary != nil {
- fuzz.dictionary = android.PathForModuleSrc(ctx, *fuzz.Properties.Dictionary)
+ if fuzz.fuzzPackagedModule.FuzzProperties.Dictionary != nil {
+ fuzz.fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzz.fuzzPackagedModule.FuzzProperties.Dictionary)
}
}
diff --git a/rust/library.go b/rust/library.go
index 747a29d72..5a36bd13f 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -431,6 +431,12 @@ func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
+ if library.dylib() {
+ // We need to add a dependency on std in order to link crates as dylibs.
+ // The hack to add this dependency is guarded by the following cfg so
+ // that we don't force a dependency when it isn't needed.
+ library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
+ }
flags = library.baseCompiler.compilerFlags(ctx, flags)
if library.shared() || library.static() {
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
diff --git a/rust/library_test.go b/rust/library_test.go
index 54cd2a5b3..cb4ef7eec 100644
--- a/rust/library_test.go
+++ b/rust/library_test.go
@@ -85,6 +85,22 @@ func TestDylibPreferDynamic(t *testing.T) {
}
}
+// Check that we are passing the android_dylib config flag
+func TestAndroidDylib(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library_host_dylib {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ }`)
+
+ libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so")
+
+ if !strings.Contains(libfooDylib.Args["rustcFlags"], "--cfg 'android_dylib'") {
+ t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
+ }
+}
+
func TestValidateLibraryStem(t *testing.T) {
testRustError(t, "crate_name must be defined.", `
rust_library_host {
diff --git a/rust/rust.go b/rust/rust.go
index 38f1742d4..52b409435 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -119,9 +119,7 @@ type BaseProperties struct {
}
type Module struct {
- android.ModuleBase
- android.DefaultableModuleBase
- android.ApexModuleBase
+ cc.FuzzModule
VendorProperties cc.VendorProperties
diff --git a/rust/test.go b/rust/test.go
index 6caa7b168..e95b47cff 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -169,3 +169,11 @@ func RustTestHostFactory() android.Module {
func (test *testDecorator) stdLinkage(ctx *depsContext) RustLinkage {
return RlibLinkage
}
+
+func (test *testDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
+ deps = test.binaryDecorator.compilerDeps(ctx, deps)
+
+ deps.Rustlibs = append(deps.Rustlibs, "libtest")
+
+ return deps
+}
diff --git a/rust/testing.go b/rust/testing.go
index 72f87e136..94cdd9dcd 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -170,12 +170,10 @@ func GatherRequiredDepsForTest() string {
name: "libtest",
crate_name: "test",
srcs: ["foo.rs"],
- no_stdlibs: true,
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
- sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
min_sdk_version: "29",
}
diff --git a/rust/vendor_snapshot_test.go b/rust/vendor_snapshot_test.go
index 815f80ec7..60ddb653f 100644
--- a/rust/vendor_snapshot_test.go
+++ b/rust/vendor_snapshot_test.go
@@ -569,7 +569,6 @@ func TestVendorSnapshotUse(t *testing.T) {
],
rlibs: [
"libstd",
- "libtest",
"librust_vendor_available",
],
binaries: [
@@ -597,7 +596,6 @@ func TestVendorSnapshotUse(t *testing.T) {
],
rlibs: [
"libstd",
- "libtest",
"librust_vendor_available",
],
binaries: [
@@ -665,22 +663,6 @@ func TestVendorSnapshotUse(t *testing.T) {
}
vendor_snapshot_rlib {
- name: "libtest",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- sysroot: true,
- arch: {
- arm64: {
- src: "libtest.rlib",
- },
- arm: {
- src: "libtest.rlib",
- },
- },
- }
-
- vendor_snapshot_rlib {
name: "librust_vendor_available",
version: "30",
target_arch: "arm64",
@@ -917,7 +899,6 @@ func TestVendorSnapshotUse(t *testing.T) {
"vendor/lib64.so": nil,
"vendor/liblog.so": nil,
"vendor/libstd.rlib": nil,
- "vendor/libtest.rlib": nil,
"vendor/librust_vendor_available.rlib": nil,
"vendor/crtbegin_so.o": nil,
"vendor/crtend_so.o": nil,
@@ -962,7 +943,7 @@ func TestVendorSnapshotUse(t *testing.T) {
}
libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64", "libtest.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
+ if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
}
@@ -977,7 +958,7 @@ func TestVendorSnapshotUse(t *testing.T) {
}
libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64", "libtest.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
+ if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
}