Revert "support sandboxed rust rules"
Revert submission 2629131-sandbox-rust-inputs Reason for revert: Fail on android build. Reverted changes: /q/submissionid:2629131-sandbox-rust-inputs Change-Id: Ifd9aa46e80a12d8f4ffa0a2daa74b96727cbb7e6
This commit is contained in:
parent
df0ed707a5
commit
41326c1f41
28 changed files with 383 additions and 1402 deletions
|
@ -95,12 +95,6 @@ func NewDepSet[T depSettableType](order DepSetOrder, direct []T, transitive []*D
|
|||
}
|
||||
}
|
||||
|
||||
// AddDirectToDepSet returns a new DepSet with additional elements added to its direct set.
|
||||
// The transitive sets remain untouched.
|
||||
func AddDirectToDepSet[T depSettableType](d *DepSet[T], direct ...T) *DepSet[T] {
|
||||
return NewDepSet[T](d.order, Concat(d.direct, direct), d.transitive)
|
||||
}
|
||||
|
||||
// DepSetBuilder is used to create an immutable DepSet.
|
||||
type DepSetBuilder[T depSettableType] struct {
|
||||
order DepSetOrder
|
||||
|
@ -194,14 +188,3 @@ func (d *DepSet[T]) ToList() []T {
|
|||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// ToListDirect returns the direct elements of a DepSet flattened to a list.
|
||||
func (d *DepSet[T]) ToListDirect() []T {
|
||||
if d == nil {
|
||||
return nil
|
||||
}
|
||||
list := make([]T, len(d.direct))
|
||||
copy(list, d.direct)
|
||||
list = firstUniqueInPlace(list)
|
||||
return list
|
||||
}
|
||||
|
|
|
@ -171,9 +171,6 @@ type Path interface {
|
|||
// Base returns the last element of the path
|
||||
Base() string
|
||||
|
||||
// Dir returns a path pointing the directory containing the path
|
||||
Dir() Path
|
||||
|
||||
// Rel returns the portion of the path relative to the directory it was created from. For
|
||||
// example, Rel on a PathsForModuleSrc would return the path relative to the module source
|
||||
// directory, and OutputPath.Join("foo").Rel() would return "foo".
|
||||
|
@ -1015,12 +1012,6 @@ func (p basePath) Base() string {
|
|||
return filepath.Base(p.path)
|
||||
}
|
||||
|
||||
func (p basePath) Dir() Path {
|
||||
p.path = filepath.Dir(p.path)
|
||||
p.rel = filepath.Dir(p.rel)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p basePath) Rel() string {
|
||||
if p.rel != "" {
|
||||
return p.rel
|
||||
|
@ -1055,11 +1046,6 @@ func (p SourcePath) withRel(rel string) SourcePath {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p SourcePath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
return p
|
||||
}
|
||||
|
||||
// safePathForSource is for paths that we expect are safe -- only for use by go
|
||||
// code that is embedding ninja variables in paths
|
||||
func safePathForSource(ctx PathContext, pathComponents ...string) (SourcePath, error) {
|
||||
|
@ -1262,12 +1248,6 @@ func (p OutputPath) withRel(rel string) OutputPath {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p OutputPath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
p.fullPath = filepath.Dir(p.fullPath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p OutputPath) WithoutRel() OutputPath {
|
||||
p.basePath.rel = filepath.Base(p.basePath.path)
|
||||
return p
|
||||
|
@ -1300,11 +1280,6 @@ type toolDepPath struct {
|
|||
basePath
|
||||
}
|
||||
|
||||
func (p toolDepPath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (t toolDepPath) RelativeToTop() Path {
|
||||
ensureTestOnly()
|
||||
return t
|
||||
|
@ -1488,11 +1463,6 @@ type ModuleOutPath struct {
|
|||
OutputPath
|
||||
}
|
||||
|
||||
func (p ModuleOutPath) Dir() Path {
|
||||
p.OutputPath = p.OutputPath.Dir().(OutputPath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p ModuleOutPath) RelativeToTop() Path {
|
||||
p.OutputPath = p.outputPathRelativeToTop()
|
||||
return p
|
||||
|
@ -1537,11 +1507,6 @@ type ModuleGenPath struct {
|
|||
ModuleOutPath
|
||||
}
|
||||
|
||||
func (p ModuleGenPath) Dir() Path {
|
||||
p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p ModuleGenPath) RelativeToTop() Path {
|
||||
p.OutputPath = p.outputPathRelativeToTop()
|
||||
return p
|
||||
|
@ -1581,11 +1546,6 @@ type ModuleObjPath struct {
|
|||
ModuleOutPath
|
||||
}
|
||||
|
||||
func (p ModuleObjPath) Dir() Path {
|
||||
p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p ModuleObjPath) RelativeToTop() Path {
|
||||
p.OutputPath = p.outputPathRelativeToTop()
|
||||
return p
|
||||
|
@ -1610,11 +1570,6 @@ type ModuleResPath struct {
|
|||
ModuleOutPath
|
||||
}
|
||||
|
||||
func (p ModuleResPath) Dir() Path {
|
||||
p.ModuleOutPath = p.ModuleOutPath.Dir().(ModuleOutPath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p ModuleResPath) RelativeToTop() Path {
|
||||
p.OutputPath = p.outputPathRelativeToTop()
|
||||
return p
|
||||
|
@ -1651,11 +1606,6 @@ type InstallPath struct {
|
|||
makePath bool
|
||||
}
|
||||
|
||||
func (p InstallPath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
return p
|
||||
}
|
||||
|
||||
// Will panic if called from outside a test environment.
|
||||
func ensureTestOnly() {
|
||||
if PrefixInList(os.Args, "-test.") {
|
||||
|
@ -1972,11 +1922,6 @@ type PhonyPath struct {
|
|||
basePath
|
||||
}
|
||||
|
||||
func (p PhonyPath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p PhonyPath) writablePath() {}
|
||||
|
||||
func (p PhonyPath) getSoongOutDir() string {
|
||||
|
@ -2002,11 +1947,6 @@ type testPath struct {
|
|||
basePath
|
||||
}
|
||||
|
||||
func (p testPath) Dir() Path {
|
||||
p.basePath = p.basePath.Dir().(basePath)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p testPath) RelativeToTop() Path {
|
||||
ensureTestOnly()
|
||||
return p
|
||||
|
|
|
@ -14,11 +14,7 @@
|
|||
|
||||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
import "path/filepath"
|
||||
|
||||
func init() {
|
||||
RegisterModuleType("prebuilt_build_tool", NewPrebuiltBuildTool)
|
||||
|
@ -59,13 +55,6 @@ func (t *prebuiltBuildTool) DepsMutator(ctx BottomUpMutatorContext) {
|
|||
}
|
||||
}
|
||||
|
||||
type PrebuiltBuildToolInfo struct {
|
||||
Src Path
|
||||
Deps Paths
|
||||
}
|
||||
|
||||
var PrebuiltBuildToolInfoProvider = blueprint.NewProvider(PrebuiltBuildToolInfo{})
|
||||
|
||||
func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||
sourcePath := t.prebuilt.SingleSourcePath(ctx)
|
||||
installedPath := PathForModuleOut(ctx, t.BaseModuleName())
|
||||
|
@ -93,11 +82,6 @@ func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|||
}
|
||||
|
||||
t.toolPath = OptionalPathForPath(installedPath)
|
||||
|
||||
ctx.SetProvider(PrebuiltBuildToolInfoProvider, PrebuiltBuildToolInfo{
|
||||
Src: sourcePath,
|
||||
Deps: deps,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) {
|
||||
|
|
|
@ -33,17 +33,12 @@ func CopyOf[T any](s []T) []T {
|
|||
return append([]T{}, s...)
|
||||
}
|
||||
|
||||
// Concat returns a new slice concatenated from the input slices. It does not change the input
|
||||
// Concat returns a new slice concatenated from the two input slices. It does not change the input
|
||||
// slices.
|
||||
func Concat[T any](slices ...[]T) []T {
|
||||
newLength := 0
|
||||
for _, s := range slices {
|
||||
newLength += len(s)
|
||||
}
|
||||
res := make([]T, 0, newLength)
|
||||
for _, s := range slices {
|
||||
res = append(res, s...)
|
||||
}
|
||||
func Concat[T any](s1, s2 []T) []T {
|
||||
res := make([]T, 0, len(s1)+len(s2))
|
||||
res = append(res, s1...)
|
||||
res = append(res, s2...)
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
|
@ -948,7 +948,7 @@ func TestApexWithStubs(t *testing.T) {
|
|||
// Ensure that stub dependency from a rust module is not included
|
||||
ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so")
|
||||
// The rust module is linked to the stub cc library
|
||||
rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").RuleParams.Command
|
||||
rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustLink").Args["linkFlags"]
|
||||
ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so")
|
||||
ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so")
|
||||
|
||||
|
@ -1024,7 +1024,7 @@ func TestApexCanUsePrivateApis(t *testing.T) {
|
|||
mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"]
|
||||
ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so")
|
||||
ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
|
||||
rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").RuleParams.Command
|
||||
rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustLink").Args["linkFlags"]
|
||||
ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so")
|
||||
ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so")
|
||||
}
|
||||
|
|
|
@ -68,26 +68,6 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
|
|||
|
||||
func commonDefaultModules() string {
|
||||
return `
|
||||
prebuilt_build_tool {
|
||||
name: "clang++",
|
||||
src: "bin/clang++",
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "clang++.real",
|
||||
src: "bin/clang++.real",
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "lld",
|
||||
src: "bin/lld",
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "ld.lld",
|
||||
src: "bin/ld.lld",
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "llvm-ar",
|
||||
src: "bin/llvm-ar",
|
||||
}
|
||||
cc_defaults {
|
||||
name: "toolchain_libs_defaults",
|
||||
host_supported: true,
|
||||
|
@ -589,12 +569,6 @@ var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
|
|||
|
||||
// Additional files needed in tests that disallow non-existent source.
|
||||
android.MockFS{
|
||||
"defaults/cc/common/bin/clang++": nil,
|
||||
"defaults/cc/common/bin/clang++.real": nil,
|
||||
"defaults/cc/common/bin/lld": nil,
|
||||
"defaults/cc/common/bin/ld.lld": nil,
|
||||
"defaults/cc/common/bin/llvm-ar": nil,
|
||||
|
||||
"defaults/cc/common/libc.map.txt": nil,
|
||||
"defaults/cc/common/libdl.map.txt": nil,
|
||||
"defaults/cc/common/libm.map.txt": nil,
|
||||
|
|
|
@ -54,8 +54,8 @@ func TestAfdoEnabled(t *testing.T) {
|
|||
|
||||
expectedCFlag := fmt.Sprintf(afdoFlagFormat, "afdo_profiles_package/foo.afdo")
|
||||
|
||||
if !strings.Contains(foo.RuleParams.Command, expectedCFlag) {
|
||||
t.Errorf("Expected 'foo' to enable afdo, but did not find %q in command %q", expectedCFlag, foo.RuleParams.Command)
|
||||
if !strings.Contains(foo.Args["rustcFlags"], expectedCFlag) {
|
||||
t.Errorf("Expected 'foo' to enable afdo, but did not find %q in cflags %q", expectedCFlag, foo.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,17 +96,17 @@ func TestAfdoEnabledWithMultiArchs(t *testing.T) {
|
|||
rustMockedFiles.AddToFixture(),
|
||||
).RunTestWithBp(t, bp)
|
||||
|
||||
fooArm := result.ModuleForTests("foo", "android_arm_armv7-a-neon").Description("rustc")
|
||||
fooArm64 := result.ModuleForTests("foo", "android_arm64_armv8-a").Description("rustc")
|
||||
fooArm := result.ModuleForTests("foo", "android_arm_armv7-a-neon").Rule("rustc")
|
||||
fooArm64 := result.ModuleForTests("foo", "android_arm64_armv8-a").Rule("rustc")
|
||||
|
||||
expectedCFlagArm := fmt.Sprintf(afdoFlagFormat, "afdo_profiles_package/foo_arm.afdo")
|
||||
expectedCFlagArm64 := fmt.Sprintf(afdoFlagFormat, "afdo_profiles_package/foo_arm64.afdo")
|
||||
|
||||
if !strings.Contains(fooArm.RuleParams.Command, expectedCFlagArm) {
|
||||
t.Errorf("Expected 'fooArm' to enable afdo, but did not find %q in command %q", expectedCFlagArm, fooArm.RuleParams.Command)
|
||||
if !strings.Contains(fooArm.Args["rustcFlags"], expectedCFlagArm) {
|
||||
t.Errorf("Expected 'fooArm' to enable afdo, but did not find %q in cflags %q", expectedCFlagArm, fooArm.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
if !strings.Contains(fooArm64.RuleParams.Command, expectedCFlagArm64) {
|
||||
t.Errorf("Expected 'fooArm64' to enable afdo, but did not find %q in command %q", expectedCFlagArm64, fooArm.RuleParams.Command)
|
||||
if !strings.Contains(fooArm64.Args["rustcFlags"], expectedCFlagArm64) {
|
||||
t.Errorf("Expected 'fooArm64' to enable afdo, but did not find %q in cflags %q", expectedCFlagArm64, fooArm64.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,6 +149,7 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
|
|||
|
||||
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects.Strings()...)
|
||||
|
||||
if binary.stripper.NeedsStrip(ctx) {
|
||||
strippedOutputFile := outputFile
|
||||
|
@ -159,7 +160,7 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
|
|||
}
|
||||
binary.baseCompiler.unstrippedOutputFile = outputFile
|
||||
|
||||
ret.kytheFile = TransformSrcToBinary(ctx, binary, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
ret.kytheFile = TransformSrcToBinary(ctx, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ func TestBinaryFlags(t *testing.T) {
|
|||
|
||||
fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustc")
|
||||
|
||||
flags := fizzBuzz.RuleParams.Command
|
||||
flags := fizzBuzz.Args["rustcFlags"]
|
||||
if strings.Contains(flags, "--test") {
|
||||
t.Errorf("extra --test flag, rustcFlags: %#v", flags)
|
||||
}
|
||||
|
@ -150,11 +150,11 @@ func TestBootstrap(t *testing.T) {
|
|||
bootstrap: true,
|
||||
}`)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Rule("rustc")
|
||||
foo := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Rule("rustLink")
|
||||
|
||||
flag := "-Wl,-dynamic-linker,/system/bin/bootstrap/linker64"
|
||||
if !strings.Contains(foo.RuleParams.Command, flag) {
|
||||
t.Errorf("missing link flag to use bootstrap linker, expecting %#v, command: %#v", flag, foo.RuleParams.Command)
|
||||
if !strings.Contains(foo.Args["linkFlags"], flag) {
|
||||
t.Errorf("missing link flag to use bootstrap linker, expecting %#v, linkFlags: %#v", flag, foo.Args["linkFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,17 +167,19 @@ func TestStaticBinaryFlags(t *testing.T) {
|
|||
}`)
|
||||
|
||||
fizzOut := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Rule("rustc")
|
||||
fizzOutLink := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Rule("rustLink")
|
||||
fizzMod := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Module().(*Module)
|
||||
|
||||
flags := fizzOut.RuleParams.Command
|
||||
flags := fizzOut.Args["rustcFlags"]
|
||||
linkFlags := fizzOutLink.Args["linkFlags"]
|
||||
if !strings.Contains(flags, "-C relocation-model=static") {
|
||||
t.Errorf("static binary missing '-C relocation-model=static' in command, found: %#v", flags)
|
||||
t.Errorf("static binary missing '-C relocation-model=static' in rustcFlags, found: %#v", flags)
|
||||
}
|
||||
if !strings.Contains(flags, "-C panic=abort") {
|
||||
t.Errorf("static binary missing '-C panic=abort' in command, found: %#v", flags)
|
||||
t.Errorf("static binary missing '-C panic=abort' in rustcFlags, found: %#v", flags)
|
||||
}
|
||||
if !strings.Contains(flags, "-static") {
|
||||
t.Errorf("static binary missing '-static' in command, found: %#v", flags)
|
||||
if !strings.Contains(linkFlags, "-static") {
|
||||
t.Errorf("static binary missing '-static' in linkFlags, found: %#v", flags)
|
||||
}
|
||||
|
||||
if !android.InList("libc", fizzMod.Properties.AndroidMkStaticLibs) {
|
||||
|
@ -199,9 +201,10 @@ func TestLinkObjects(t *testing.T) {
|
|||
name: "libfoo",
|
||||
}`)
|
||||
|
||||
fizzBuzz := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Rule("rustc")
|
||||
if !strings.Contains(fizzBuzz.RuleParams.Command, "/libfoo.so") {
|
||||
t.Errorf("missing shared dependency 'libfoo.so' in command: %#v", fizzBuzz.RuleParams.Command)
|
||||
fizzBuzz := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Rule("rustLink")
|
||||
linkFlags := fizzBuzz.Args["linkFlags"]
|
||||
if !strings.Contains(linkFlags, "/libfoo.so") {
|
||||
t.Errorf("missing shared dependency 'libfoo.so' in linkFlags: %#v", linkFlags)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
423
rust/builder.go
423
rust/builder.go
|
@ -15,7 +15,6 @@
|
|||
package rust
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -26,6 +25,54 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
_ = pctx.SourcePathVariable("rustcCmd", "${config.RustBin}/rustc")
|
||||
_ = pctx.SourcePathVariable("mkcraterspCmd", "build/soong/scripts/mkcratersp.py")
|
||||
rustc = pctx.AndroidStaticRule("rustc",
|
||||
blueprint.RuleParams{
|
||||
Command: "$envVars $rustcCmd " +
|
||||
"-C linker=$mkcraterspCmd " +
|
||||
"--emit link -o $out --emit dep-info=$out.d.raw $in ${libFlags} $rustcFlags" +
|
||||
" && grep \"^$out:\" $out.d.raw > $out.d",
|
||||
CommandDeps: []string{"$rustcCmd", "$mkcraterspCmd"},
|
||||
// Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
|
||||
// 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.
|
||||
Deps: blueprint.DepsGCC,
|
||||
Depfile: "$out.d",
|
||||
},
|
||||
"rustcFlags", "libFlags", "envVars")
|
||||
rustLink = pctx.AndroidStaticRule("rustLink",
|
||||
blueprint.RuleParams{
|
||||
Command: "${config.RustLinker} -o $out ${crtBegin} ${earlyLinkFlags} @$in ${linkFlags} ${crtEnd}",
|
||||
},
|
||||
"earlyLinkFlags", "linkFlags", "crtBegin", "crtEnd")
|
||||
|
||||
_ = pctx.SourcePathVariable("rustdocCmd", "${config.RustBin}/rustdoc")
|
||||
rustdoc = pctx.AndroidStaticRule("rustdoc",
|
||||
blueprint.RuleParams{
|
||||
Command: "$envVars $rustdocCmd $rustdocFlags $in -o $outDir && " +
|
||||
"touch $out",
|
||||
CommandDeps: []string{"$rustdocCmd"},
|
||||
},
|
||||
"rustdocFlags", "outDir", "envVars")
|
||||
|
||||
_ = pctx.SourcePathVariable("clippyCmd", "${config.RustBin}/clippy-driver")
|
||||
clippyDriver = pctx.AndroidStaticRule("clippy",
|
||||
blueprint.RuleParams{
|
||||
Command: "$envVars $clippyCmd " +
|
||||
// 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.
|
||||
"--emit metadata -o $out --emit dep-info=$out.d.raw $in ${libFlags} " +
|
||||
"$rustcFlags $clippyFlags" +
|
||||
" && grep \"^$out:\" $out.d.raw > $out.d",
|
||||
CommandDeps: []string{"$clippyCmd"},
|
||||
Deps: blueprint.DepsGCC,
|
||||
Depfile: "$out.d",
|
||||
},
|
||||
"rustcFlags", "libFlags", "clippyFlags", "envVars")
|
||||
|
||||
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",
|
||||
|
@ -34,7 +81,7 @@ var (
|
|||
RspfileContent: "$in",
|
||||
})
|
||||
|
||||
cpDir = pctx.AndroidStaticRule("cpDir",
|
||||
cp = pctx.AndroidStaticRule("cp",
|
||||
blueprint.RuleParams{
|
||||
Command: "cp `cat $outDir.rsp` $outDir",
|
||||
Rspfile: "${outDir}.rsp",
|
||||
|
@ -42,12 +89,6 @@ var (
|
|||
},
|
||||
"outDir")
|
||||
|
||||
cp = pctx.AndroidStaticRule("cp",
|
||||
blueprint.RuleParams{
|
||||
Command: "rm -f $out && cp $in $out",
|
||||
Description: "cp $out",
|
||||
})
|
||||
|
||||
// Cross-referencing:
|
||||
_ = pctx.SourcePathVariable("rustExtractor",
|
||||
"prebuilts/build-tools/${config.HostPrebuiltTag}/bin/rust_extractor")
|
||||
|
@ -55,6 +96,23 @@ var (
|
|||
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
|
||||
_ = pctx.VariableFunc("kytheCuEncoding",
|
||||
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCuEncoding() })
|
||||
_ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json")
|
||||
kytheExtract = pctx.AndroidStaticRule("kythe",
|
||||
blueprint.RuleParams{
|
||||
Command: `KYTHE_CORPUS=${kytheCorpus} ` +
|
||||
`KYTHE_OUTPUT_FILE=$out ` +
|
||||
`KYTHE_VNAMES=$kytheVnames ` +
|
||||
`KYTHE_KZIP_ENCODING=${kytheCuEncoding} ` +
|
||||
`KYTHE_CANONICALIZE_VNAME_PATHS=prefer-relative ` +
|
||||
`$rustExtractor $envVars ` +
|
||||
`$rustcCmd ` +
|
||||
`-C linker=true ` +
|
||||
`$in ${libFlags} $rustcFlags`,
|
||||
CommandDeps: []string{"$rustExtractor", "$kytheVnames"},
|
||||
Rspfile: "${out}.rsp",
|
||||
RspfileContent: "$in",
|
||||
},
|
||||
"rustcFlags", "libFlags", "envVars")
|
||||
)
|
||||
|
||||
type buildOutput struct {
|
||||
|
@ -66,40 +124,40 @@ func init() {
|
|||
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
||||
}
|
||||
|
||||
func TransformSrcToBinary(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "bin")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin")
|
||||
}
|
||||
|
||||
func TransformSrctoRlib(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
func TransformSrctoRlib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "rlib")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "rlib")
|
||||
}
|
||||
|
||||
func TransformSrctoDylib(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "dylib")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "dylib")
|
||||
}
|
||||
|
||||
func TransformSrctoStatic(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "staticlib")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib")
|
||||
}
|
||||
|
||||
func TransformSrctoShared(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath) buildOutput {
|
||||
flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin")
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "cdylib")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib")
|
||||
}
|
||||
|
||||
func TransformSrctoProcMacro(ctx ModuleContext, c compiler, mainSrc android.Path, deps PathDeps,
|
||||
func TransformSrctoProcMacro(ctx ModuleContext, mainSrc android.Path, deps PathDeps,
|
||||
flags Flags, outputFile android.WritablePath) buildOutput {
|
||||
return transformSrctoCrate(ctx, c, mainSrc, deps, flags, outputFile, "proc-macro")
|
||||
return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "proc-macro")
|
||||
}
|
||||
|
||||
func rustLibsToPaths(libs RustLibraries) android.Paths {
|
||||
|
@ -110,46 +168,28 @@ func rustLibsToPaths(libs RustLibraries) android.Paths {
|
|||
return paths
|
||||
}
|
||||
|
||||
func makeLibFlags(deps PathDeps, ruleCmd *android.RuleBuilderCommand) []string {
|
||||
func makeLibFlags(deps PathDeps) []string {
|
||||
var libFlags []string
|
||||
|
||||
// Collect library/crate flags
|
||||
for _, lib := range deps.Rlibs.ToListDirect() {
|
||||
libPath := ruleCmd.PathForInput(lib.Path)
|
||||
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+libPath)
|
||||
for _, lib := range deps.RLibs {
|
||||
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
|
||||
}
|
||||
for _, lib := range deps.Dylibs.ToListDirect() {
|
||||
libPath := ruleCmd.PathForInput(lib.Path)
|
||||
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+libPath)
|
||||
for _, lib := range deps.DyLibs {
|
||||
libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
|
||||
}
|
||||
for _, procMacro := range deps.ProcMacros.ToListDirect() {
|
||||
procMacroPath := ruleCmd.PathForInput(procMacro.Path)
|
||||
libFlags = append(libFlags, "--extern "+procMacro.CrateName+"="+procMacroPath)
|
||||
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 "+ruleCmd.PathForInput(path))
|
||||
libFlags = append(libFlags, "-L "+path)
|
||||
}
|
||||
|
||||
return libFlags
|
||||
}
|
||||
|
||||
func collectImplicits(deps PathDeps) android.Paths {
|
||||
depPaths := android.Paths{}
|
||||
depPaths = append(depPaths, rustLibsToPaths(deps.Rlibs.ToList())...)
|
||||
depPaths = append(depPaths, rustLibsToPaths(deps.Dylibs.ToList())...)
|
||||
depPaths = append(depPaths, rustLibsToPaths(deps.ProcMacros.ToList())...)
|
||||
depPaths = append(depPaths, deps.AfdoProfiles...)
|
||||
depPaths = append(depPaths, deps.WholeStaticLibs...)
|
||||
depPaths = append(depPaths, deps.SrcDeps...)
|
||||
depPaths = append(depPaths, deps.srcProviderFiles...)
|
||||
depPaths = append(depPaths, deps.LibDeps...)
|
||||
depPaths = append(depPaths, deps.linkObjects...)
|
||||
depPaths = append(depPaths, deps.BuildToolSrcDeps...)
|
||||
return depPaths
|
||||
}
|
||||
|
||||
func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderCommand) []string {
|
||||
func rustEnvVars(ctx ModuleContext, deps PathDeps) []string {
|
||||
var envVars []string
|
||||
|
||||
// libstd requires a specific environment variable to be set. This is
|
||||
|
@ -163,17 +203,15 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderComma
|
|||
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 outDir string
|
||||
if filepath.IsAbs(moduleGenDir.String()) {
|
||||
// If OUT_DIR is absolute, then moduleGenDir will be an absolute path, so we don't need to set this to anything.
|
||||
outDir = moduleGenDir.String()
|
||||
} else if moduleGenDir.Valid() {
|
||||
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 '/')
|
||||
outDir = filepath.Join("$$PWD/", cmd.PathForInput(moduleGenDir.Path()))
|
||||
outDirPrefix = "$$PWD/"
|
||||
} else {
|
||||
outDir = "$$PWD/"
|
||||
// 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="+outDir)
|
||||
envVars = append(envVars, "OUT_DIR="+filepath.Join(outDirPrefix, moduleGenDir.String()))
|
||||
} else {
|
||||
// TODO(pcc): Change this to "OUT_DIR=" after fixing crates to not rely on this value.
|
||||
envVars = append(envVars, "OUT_DIR=out")
|
||||
|
@ -204,7 +242,7 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderComma
|
|||
}
|
||||
}
|
||||
|
||||
envVars = append(envVars, "AR="+cmd.PathForTool(deps.Llvm_ar))
|
||||
envVars = append(envVars, "AR=${cc_config.ClangBin}/llvm-ar")
|
||||
|
||||
if ctx.Darwin() {
|
||||
envVars = append(envVars, "ANDROID_RUST_DARWIN=true")
|
||||
|
@ -213,18 +251,21 @@ func rustEnvVars(ctx ModuleContext, deps PathDeps, cmd *android.RuleBuilderComma
|
|||
return envVars
|
||||
}
|
||||
|
||||
func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, deps PathDeps, flags Flags,
|
||||
func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags,
|
||||
outputFile android.WritablePath, crateType string) buildOutput {
|
||||
|
||||
var inputs android.Paths
|
||||
var implicits, linkImplicits, linkOrderOnly android.Paths
|
||||
var output buildOutput
|
||||
var rustcFlags, linkFlags []string
|
||||
var earlyLinkFlags []string
|
||||
var earlyLinkFlags string
|
||||
|
||||
output.outputFile = outputFile
|
||||
crateName := ctx.RustModule().CrateName()
|
||||
targetTriple := ctx.toolchain().RustTriple()
|
||||
|
||||
envVars := rustEnvVars(ctx, deps)
|
||||
|
||||
inputs = append(inputs, main)
|
||||
|
||||
// Collect rustc flags
|
||||
|
@ -245,6 +286,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
|
|||
// Enable incremental compilation if requested by user
|
||||
if ctx.Config().IsEnvTrue("SOONG_RUSTC_INCREMENTAL") {
|
||||
incrementalPath := android.PathForOutput(ctx, "rustc").String()
|
||||
|
||||
rustcFlags = append(rustcFlags, "-Cincremental="+incrementalPath)
|
||||
}
|
||||
|
||||
|
@ -256,16 +298,36 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
|
|||
|
||||
// Collect linker flags
|
||||
if !ctx.Darwin() {
|
||||
earlyLinkFlags = append(earlyLinkFlags, "-Wl,--as-needed")
|
||||
earlyLinkFlags = "-Wl,--as-needed"
|
||||
}
|
||||
|
||||
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
||||
linkFlags = append(linkFlags, flags.LinkFlags...)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
libFlags := makeLibFlags(deps)
|
||||
|
||||
// Collect dependencies
|
||||
var linkImplicits android.Paths
|
||||
implicits := collectImplicits(deps)
|
||||
toolImplicits := android.Concat(deps.BuildToolDeps)
|
||||
implicits = append(implicits, rustLibsToPaths(deps.RLibs)...)
|
||||
implicits = append(implicits, rustLibsToPaths(deps.DyLibs)...)
|
||||
implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...)
|
||||
implicits = append(implicits, deps.AfdoProfiles...)
|
||||
implicits = append(implicits, deps.srcProviderFiles...)
|
||||
implicits = append(implicits, deps.WholeStaticLibs...)
|
||||
|
||||
linkImplicits = append(linkImplicits, deps.LibDeps...)
|
||||
linkImplicits = append(linkImplicits, deps.CrtBegin...)
|
||||
linkImplicits = append(linkImplicits, deps.CrtEnd...)
|
||||
implicits = append(implicits, comp.compilationSourcesAndData(ctx)...)
|
||||
|
||||
linkOrderOnly = append(linkOrderOnly, deps.linkObjects...)
|
||||
|
||||
if len(deps.SrcDeps) > 0 {
|
||||
moduleGenDir := ctx.RustModule().compiler.CargoOutDir()
|
||||
|
@ -280,7 +342,7 @@ func transformSrctoCrate(ctx ModuleContext, comp compiler, main android.Path, de
|
|||
}
|
||||
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: cpDir,
|
||||
Rule: cp,
|
||||
Description: "cp " + moduleGenDir.Path().Rel(),
|
||||
Outputs: outputs,
|
||||
Inputs: deps.SrcDeps,
|
||||
|
@ -292,176 +354,81 @@ 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")
|
||||
clippyDepInfoFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy.d.raw")
|
||||
clippyDepFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy.d")
|
||||
|
||||
clippyCmd.
|
||||
Flags(rustEnvVars(ctx, deps, clippyCmd)).
|
||||
Tool(deps.Clippy_driver).
|
||||
Flag("--emit metadata").
|
||||
FlagWithOutput("-o ", clippyFile).
|
||||
FlagWithOutput("--emit dep-info=", clippyDepInfoFile).
|
||||
Inputs(inputs).
|
||||
Flags(makeLibFlags(deps, clippyCmd)).
|
||||
Flags(rustcFlags).
|
||||
Flags(flags.ClippyFlags).
|
||||
ImplicitTools(toolImplicits).
|
||||
Implicits(implicits)
|
||||
|
||||
depfileCreationCmd := clippyRule.Command()
|
||||
depfileCreationCmd.
|
||||
Flag(fmt.Sprintf(
|
||||
`grep "^%s:" %s >`,
|
||||
depfileCreationCmd.PathForOutput(clippyFile),
|
||||
depfileCreationCmd.PathForOutput(clippyDepInfoFile),
|
||||
)).
|
||||
DepFile(clippyDepFile)
|
||||
|
||||
clippyRule.BuildWithUnescapedNinjaVars("clippy", "clippy "+main.Rel())
|
||||
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: clippyDriver,
|
||||
Description: "clippy " + main.Rel(),
|
||||
Output: clippyFile,
|
||||
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)
|
||||
}
|
||||
|
||||
sboxDirectory := "rustc"
|
||||
rustSboxOutputFile := android.PathForModuleOut(ctx, sboxDirectory, outputFile.Base())
|
||||
depFile := android.PathForModuleOut(ctx, sboxDirectory, rustSboxOutputFile.Base()+".d")
|
||||
depInfoFile := android.PathForModuleOut(ctx, sboxDirectory, rustSboxOutputFile.Base()+".d.raw")
|
||||
var rustcImplicitOutputs android.WritablePaths
|
||||
|
||||
sandboxedCompilation := comp.crateRoot(ctx) != nil
|
||||
rustcRule := getRuleBuilder(ctx, pctx, sandboxedCompilation, sboxDirectory)
|
||||
rustcCmd := rustcRule.Command()
|
||||
|
||||
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
||||
linkFlags = append(linkFlags, flags.LinkFlags...)
|
||||
linkFlags = append(linkFlags, rustcCmd.PathsForInputs(deps.linkObjects)...)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
libFlags := makeLibFlags(deps, rustcCmd)
|
||||
|
||||
rustcOutputFile := outputFile
|
||||
usesLinker := crateType == "bin" || crateType == "dylib" || crateType == "cdylib" || crateType == "proc-macro"
|
||||
if usesLinker {
|
||||
rustSboxOutputFile = android.PathForModuleOut(ctx, sboxDirectory, rustSboxOutputFile.Base()+".rsp")
|
||||
rustcImplicitOutputs = android.WritablePaths{
|
||||
android.PathForModuleOut(ctx, sboxDirectory, rustSboxOutputFile.Base()+".whole.a"),
|
||||
android.PathForModuleOut(ctx, sboxDirectory, rustSboxOutputFile.Base()+".a"),
|
||||
}
|
||||
rustcOutputFile = android.PathForModuleOut(ctx, outputFile.Base()+".rsp")
|
||||
}
|
||||
|
||||
// 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(deps.Rustc).
|
||||
FlagWithInput("-C linker=", android.PathForSource(ctx, "build", "soong", "scripts", "mkcratersp.py")).
|
||||
Flag("--emit link").
|
||||
Flag("-o").
|
||||
Output(rustSboxOutputFile).
|
||||
FlagWithOutput("--emit dep-info=", depInfoFile).
|
||||
Inputs(inputs).
|
||||
Flags(libFlags).
|
||||
ImplicitTools(toolImplicits).
|
||||
Implicits(implicits).
|
||||
Flags(rustcFlags).
|
||||
ImplicitOutputs(rustcImplicitOutputs)
|
||||
|
||||
depfileCreationCmd := rustcRule.Command()
|
||||
depfileCreationCmd.
|
||||
Flag(fmt.Sprintf(
|
||||
`grep "^%s:" %s >`,
|
||||
depfileCreationCmd.PathForOutput(rustSboxOutputFile),
|
||||
depfileCreationCmd.PathForOutput(depInfoFile),
|
||||
)).
|
||||
DepFile(depFile)
|
||||
|
||||
if !usesLinker {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: cp,
|
||||
Input: rustSboxOutputFile,
|
||||
Output: outputFile,
|
||||
Rule: rustc,
|
||||
Description: "rustc " + main.Rel(),
|
||||
Output: rustcOutputFile,
|
||||
Inputs: inputs,
|
||||
Implicits: implicits,
|
||||
Args: map[string]string{
|
||||
"rustcFlags": strings.Join(rustcFlags, " "),
|
||||
"libFlags": strings.Join(libFlags, " "),
|
||||
"envVars": strings.Join(envVars, " "),
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// TODO: delmerico - separate rustLink into its own rule
|
||||
// mkcratersp.py hardcodes paths to files within the sandbox, so
|
||||
// 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())
|
||||
rustLinkCmd := rustcRule.Command()
|
||||
rustLinkCmd.
|
||||
Tool(deps.Clang).
|
||||
Flag("-o").
|
||||
Output(linkerSboxOutputFile).
|
||||
Inputs(deps.CrtBegin).
|
||||
Flags(earlyLinkFlags).
|
||||
FlagWithInput("@", rustSboxOutputFile).
|
||||
Flags(linkFlags).
|
||||
Inputs(deps.CrtEnd).
|
||||
ImplicitTools(toolImplicits).
|
||||
Implicits(rustcImplicitOutputs.Paths()).
|
||||
Implicits(implicits).
|
||||
Implicits(linkImplicits)
|
||||
|
||||
if usesLinker {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: cp,
|
||||
Input: linkerSboxOutputFile,
|
||||
Rule: rustLink,
|
||||
Description: "rustLink " + main.Rel(),
|
||||
Output: outputFile,
|
||||
Inputs: android.Paths{rustcOutputFile},
|
||||
Implicits: linkImplicits,
|
||||
OrderOnly: linkOrderOnly,
|
||||
Args: map[string]string{
|
||||
"earlyLinkFlags": earlyLinkFlags,
|
||||
"linkFlags": strings.Join(linkFlags, " "),
|
||||
"crtBegin": strings.Join(deps.CrtBegin.Strings(), " "),
|
||||
"crtEnd": strings.Join(deps.CrtEnd.Strings(), " "),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
rustcRule.BuildWithUnescapedNinjaVars("rustc", "rustc "+main.Rel())
|
||||
|
||||
if flags.EmitXrefs {
|
||||
kytheRule := getRuleBuilder(ctx, pctx, false, "kythe")
|
||||
kytheCmd := kytheRule.Command()
|
||||
kytheFile := android.PathForModuleOut(ctx, outputFile.Base()+".kzip")
|
||||
kytheCmd.
|
||||
Flag("KYTHE_CORPUS=${kytheCorpus}").
|
||||
FlagWithOutput("KYTHE_OUTPUT_FILE=", kytheFile).
|
||||
FlagWithInput("KYTHE_VNAMES=", android.PathForSource(ctx, "build", "soong", "vnames.json")).
|
||||
Flag("KYTHE_KZIP_ENCODING=${kytheCuEncoding}").
|
||||
Flag("KYTHE_CANONICALIZE_VNAME_PATHS=prefer-relative").
|
||||
Tool(ctx.Config().PrebuiltBuildTool(ctx, "rust_extractor")).
|
||||
Flags(rustEnvVars(ctx, deps, kytheCmd)).
|
||||
Tool(deps.Rustc).
|
||||
Flag("-C linker=true").
|
||||
Inputs(inputs).
|
||||
Flags(makeLibFlags(deps, kytheCmd)).
|
||||
Flags(rustcFlags).
|
||||
ImplicitTools(toolImplicits).
|
||||
Implicits(implicits)
|
||||
kytheRule.BuildWithUnescapedNinjaVars("kythe", "Xref Rust extractor "+main.Rel())
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: kytheExtract,
|
||||
Description: "Xref Rust extractor " + main.Rel(),
|
||||
Output: kytheFile,
|
||||
Inputs: inputs,
|
||||
Implicits: implicits,
|
||||
Args: map[string]string{
|
||||
"rustcFlags": strings.Join(rustcFlags, " "),
|
||||
"libFlags": strings.Join(libFlags, " "),
|
||||
"envVars": strings.Join(envVars, " "),
|
||||
},
|
||||
})
|
||||
output.kytheFile = kytheFile
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
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()
|
||||
func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps,
|
||||
flags Flags) android.ModuleOutPath {
|
||||
|
||||
rustdocFlags := append([]string{}, flags.RustdocFlags...)
|
||||
rustdocFlags = append(rustdocFlags, "--sysroot=/dev/null")
|
||||
|
@ -480,7 +447,7 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags) a
|
|||
crateName := ctx.RustModule().CrateName()
|
||||
rustdocFlags = append(rustdocFlags, "--crate-name "+crateName)
|
||||
|
||||
rustdocFlags = append(rustdocFlags, makeLibFlags(deps, rustdocCmd)...)
|
||||
rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
|
||||
docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
|
||||
|
||||
// Silence warnings about renamed lints for third-party crates
|
||||
|
@ -496,26 +463,18 @@ func Rustdoc(ctx ModuleContext, main android.Path, deps PathDeps, flags Flags) a
|
|||
// https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/render/write_shared.rs#L144-L146
|
||||
docDir := android.PathForOutput(ctx, "rustdoc")
|
||||
|
||||
rustdocCmd.
|
||||
Flags(rustEnvVars(ctx, deps, rustdocCmd)).
|
||||
Tool(deps.Rustdoc).
|
||||
Flags(rustdocFlags).
|
||||
Input(main).
|
||||
Flag("-o "+docDir.String()).
|
||||
FlagWithOutput("&& touch ", docTimestampFile).
|
||||
Implicit(ctx.RustModule().UnstrippedOutputFile())
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: rustdoc,
|
||||
Description: "rustdoc " + main.Rel(),
|
||||
Output: docTimestampFile,
|
||||
Input: main,
|
||||
Implicit: ctx.RustModule().UnstrippedOutputFile(),
|
||||
Args: map[string]string{
|
||||
"rustdocFlags": strings.Join(rustdocFlags, " "),
|
||||
"outDir": docDir.String(),
|
||||
"envVars": strings.Join(rustEnvVars(ctx, deps), " "),
|
||||
},
|
||||
})
|
||||
|
||||
rustdocRule.BuildWithUnescapedNinjaVars("rustdoc", "rustdoc "+main.Rel())
|
||||
return docTimestampFile
|
||||
}
|
||||
|
||||
func getRuleBuilder(ctx android.ModuleContext, pctx android.PackageContext, sbox bool, sboxDirectory string) *android.RuleBuilder {
|
||||
r := android.NewRuleBuilder(pctx, ctx)
|
||||
if sbox {
|
||||
r = r.Sbox(
|
||||
android.PathForModuleOut(ctx, sboxDirectory),
|
||||
android.PathForModuleOut(ctx, sboxDirectory+".sbox.textproto"),
|
||||
).SandboxInputs()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
|
|
@ -63,14 +63,14 @@ func TestClippy(t *testing.T) {
|
|||
).RunTest(t)
|
||||
|
||||
r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||
android.AssertStringDoesContain(t, "libfoo flags", r.RuleParams.Command, tc.fooFlags)
|
||||
android.AssertStringEquals(t, "libfoo flags", tc.fooFlags, r.Args["clippyFlags"])
|
||||
|
||||
r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||
android.AssertStringDoesContain(t, "libbar flags", r.RuleParams.Command, "${config.ClippyDefaultLints}")
|
||||
android.AssertStringEquals(t, "libbar flags", "${config.ClippyDefaultLints}", r.Args["clippyFlags"])
|
||||
|
||||
r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||
if r.Rule != nil {
|
||||
t.Errorf("libfoobar is setup to use clippy when explicitly disabled: command=%q", r.RuleParams.Command)
|
||||
t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -82,9 +82,6 @@ type BaseCompilerProperties struct {
|
|||
// not directly used as source files.
|
||||
Crate_root *string `android:"path,arch_variant"`
|
||||
|
||||
// Additional data files that are used during compilation only. These are not accessible at runtime.
|
||||
Compile_data []string `android:"path,arch_variant"`
|
||||
|
||||
// name of the lint set that should be used to validate this module.
|
||||
//
|
||||
// Possible values are "default" (for using a sensible set of lints
|
||||
|
@ -346,23 +343,6 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
|
|||
panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
|
||||
}
|
||||
|
||||
func (compile *baseCompiler) crateRoot(ctx ModuleContext) android.Path {
|
||||
if compile.Properties.Crate_root != nil {
|
||||
return android.PathForModuleSrc(ctx, *compile.Properties.Crate_root)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// compilationSourcesAndData returns a list of files necessary to complete the compilation.
|
||||
// This includes the rust source files as well as any other data files that
|
||||
// are referenced during the build.
|
||||
func (compile *baseCompiler) compilationSourcesAndData(ctx ModuleContext) android.Paths {
|
||||
return android.PathsForModuleSrc(ctx, android.Concat(
|
||||
compile.Properties.Srcs,
|
||||
compile.Properties.Compile_data,
|
||||
))
|
||||
}
|
||||
|
||||
func (compiler *baseCompiler) rustdoc(ctx ModuleContext, flags Flags,
|
||||
deps PathDeps) android.OptionalPath {
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ func TestFeaturesToFlags(t *testing.T) {
|
|||
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
||||
|
||||
if !strings.Contains(libfooDylib.RuleParams.Command, "cfg 'feature=\"fizz\"'") ||
|
||||
!strings.Contains(libfooDylib.RuleParams.Command, "cfg 'feature=\"buzz\"'") {
|
||||
t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, command: %#v", libfooDylib.RuleParams.Command)
|
||||
if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"fizz\"'") ||
|
||||
!strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"buzz\"'") {
|
||||
t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,9 @@ func TestCfgsToFlags(t *testing.T) {
|
|||
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
||||
|
||||
if !strings.Contains(libfooDylib.RuleParams.Command, "cfg 'std'") ||
|
||||
!strings.Contains(libfooDylib.RuleParams.Command, "cfg 'cfg1=\"one\"'") {
|
||||
t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.RuleParams.Command)
|
||||
if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'std'") ||
|
||||
!strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'cfg1=\"one\"'") {
|
||||
t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,14 +146,14 @@ func TestCargoCompat(t *testing.T) {
|
|||
|
||||
fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Rule("rustc")
|
||||
|
||||
if !strings.Contains(fizz.RuleParams.Command, "CARGO_BIN_NAME=fizz") {
|
||||
t.Fatalf("expected 'CARGO_BIN_NAME=fizz' in envVars, actual command: %#v", fizz.RuleParams.Command)
|
||||
if !strings.Contains(fizz.Args["envVars"], "CARGO_BIN_NAME=fizz") {
|
||||
t.Fatalf("expected 'CARGO_BIN_NAME=fizz' in envVars, actual envVars: %#v", fizz.Args["envVars"])
|
||||
}
|
||||
if !strings.Contains(fizz.RuleParams.Command, "CARGO_CRATE_NAME=foo") {
|
||||
t.Fatalf("expected 'CARGO_CRATE_NAME=foo' in envVars, actual command: %#v", fizz.RuleParams.Command)
|
||||
if !strings.Contains(fizz.Args["envVars"], "CARGO_CRATE_NAME=foo") {
|
||||
t.Fatalf("expected 'CARGO_CRATE_NAME=foo' in envVars, actual envVars: %#v", fizz.Args["envVars"])
|
||||
}
|
||||
if !strings.Contains(fizz.RuleParams.Command, "CARGO_PKG_VERSION=1.0.0") {
|
||||
t.Fatalf("expected 'CARGO_PKG_VERSION=1.0.0' in envVars, actual command: %#v", fizz.RuleParams.Command)
|
||||
if !strings.Contains(fizz.Args["envVars"], "CARGO_PKG_VERSION=1.0.0") {
|
||||
t.Fatalf("expected 'CARGO_PKG_VERSION=1.0.0' in envVars, actual envVars: %#v", fizz.Args["envVars"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,13 +230,13 @@ func TestLints(t *testing.T) {
|
|||
).RunTest(t)
|
||||
|
||||
r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||
android.AssertStringDoesContain(t, "libfoo flags", r.RuleParams.Command, tc.fooFlags)
|
||||
android.AssertStringDoesContain(t, "libfoo flags", r.Args["rustcFlags"], tc.fooFlags)
|
||||
|
||||
r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||
android.AssertStringDoesContain(t, "libbar flags", r.RuleParams.Command, "${config.RustDefaultLints}")
|
||||
android.AssertStringDoesContain(t, "libbar flags", r.Args["rustcFlags"], "${config.RustDefaultLints}")
|
||||
|
||||
r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||
android.AssertStringDoesContain(t, "libfoobar flags", r.RuleParams.Command, "${config.RustAllowAllLints}")
|
||||
android.AssertStringDoesContain(t, "libfoobar flags", r.Args["rustcFlags"], "${config.RustAllowAllLints}")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,27 +126,3 @@ func GetRustVersion(ctx android.PathContext) string {
|
|||
func BazelRustToolchainVars(config android.Config) string {
|
||||
return android.BazelToolchainVars(config, exportedVars)
|
||||
}
|
||||
|
||||
func RustPath(ctx android.PathContext, file string) android.SourcePath {
|
||||
type rustToolKey string
|
||||
key := android.NewCustomOnceKey(rustToolKey(file))
|
||||
return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
|
||||
return rustPath(ctx).Join(ctx, file)
|
||||
})
|
||||
}
|
||||
|
||||
var rustPathKey = android.NewOnceKey("clangPath")
|
||||
|
||||
func rustPath(ctx android.PathContext) android.SourcePath {
|
||||
return ctx.Config().OnceSourcePath(rustPathKey, func() android.SourcePath {
|
||||
rustBase := RustDefaultBase
|
||||
if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
|
||||
rustBase = override
|
||||
}
|
||||
rustVersion := RustDefaultVersion
|
||||
if override := ctx.Config().Getenv("RUST_DEFAULT_VERSION"); override != "" {
|
||||
rustVersion = override
|
||||
}
|
||||
return android.PathForSource(ctx, rustBase, ctx.Config().PrebuiltOS(), rustVersion)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package rust
|
|||
import (
|
||||
"github.com/google/blueprint"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
|
@ -71,10 +70,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
|
|||
// no_std modules are missing libprofiler_builtins which provides coverage, so we need to add it as a dependency.
|
||||
if rustModule, ok := ctx.Module().(*Module); ok && rustModule.compiler.noStdlibs() {
|
||||
profiler_builtins := ctx.GetDirectDepWithTag(ProfilerBuiltins, rlibDepTag).(*Module)
|
||||
deps.Rlibs = android.AddDirectToDepSet[RustLibrary](deps.Rlibs, RustLibrary{
|
||||
Path: profiler_builtins.OutputFile().Path(),
|
||||
CrateName: profiler_builtins.CrateName(),
|
||||
})
|
||||
deps.RLibs = append(deps.RLibs, RustLibrary{Path: profiler_builtins.OutputFile().Path(), CrateName: profiler_builtins.CrateName()})
|
||||
}
|
||||
|
||||
if cc.EnableContinuousCoverage(ctx) {
|
||||
|
|
|
@ -55,27 +55,27 @@ func TestCoverageFlags(t *testing.T) {
|
|||
libbarNoCov := ctx.ModuleForTests("libbar_nocov", "android_arm64_armv8-a_dylib").Rule("rustc")
|
||||
fizzCov := ctx.ModuleForTests("fizz_cov", "android_arm64_armv8-a_cov").Rule("rustc")
|
||||
buzzNoCov := ctx.ModuleForTests("buzzNoCov", "android_arm64_armv8-a").Rule("rustc")
|
||||
libfooCovLink := ctx.ModuleForTests("libfoo_cov", "android_arm64_armv8-a_dylib_cov").Rule("rustc")
|
||||
libbarNoCovLink := ctx.ModuleForTests("libbar_nocov", "android_arm64_armv8-a_dylib").Rule("rustc")
|
||||
fizzCovLink := ctx.ModuleForTests("fizz_cov", "android_arm64_armv8-a_cov").Rule("rustc")
|
||||
buzzNoCovLink := ctx.ModuleForTests("buzzNoCov", "android_arm64_armv8-a").Rule("rustc")
|
||||
libfooCovLink := ctx.ModuleForTests("libfoo_cov", "android_arm64_armv8-a_dylib_cov").Rule("rustLink")
|
||||
libbarNoCovLink := ctx.ModuleForTests("libbar_nocov", "android_arm64_armv8-a_dylib").Rule("rustLink")
|
||||
fizzCovLink := ctx.ModuleForTests("fizz_cov", "android_arm64_armv8-a_cov").Rule("rustLink")
|
||||
buzzNoCovLink := ctx.ModuleForTests("buzzNoCov", "android_arm64_armv8-a").Rule("rustLink")
|
||||
|
||||
rustcCoverageFlags := []string{"-C instrument-coverage", " -g "}
|
||||
for _, flag := range rustcCoverageFlags {
|
||||
missingErrorStr := "missing rustc flag '%s' for '%s' module with coverage enabled; rustcFlags: %#v"
|
||||
containsErrorStr := "contains rustc flag '%s' for '%s' module with coverage disabled; rustcFlags: %#v"
|
||||
|
||||
if !strings.Contains(fizzCov.RuleParams.Command, flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCov.RuleParams.Command)
|
||||
if !strings.Contains(fizzCov.Args["rustcFlags"], flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCov.Args["rustcFlags"])
|
||||
}
|
||||
if !strings.Contains(libfooCov.RuleParams.Command, flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCov.RuleParams.Command)
|
||||
if !strings.Contains(libfooCov.Args["rustcFlags"], flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCov.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(buzzNoCov.RuleParams.Command, flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCov.RuleParams.Command)
|
||||
if strings.Contains(buzzNoCov.Args["rustcFlags"], flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCov.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(libbarNoCov.RuleParams.Command, flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCov.RuleParams.Command)
|
||||
if strings.Contains(libbarNoCov.Args["rustcFlags"], flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCov.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,17 +84,17 @@ func TestCoverageFlags(t *testing.T) {
|
|||
missingErrorStr := "missing rust linker flag '%s' for '%s' module with coverage enabled; rustcFlags: %#v"
|
||||
containsErrorStr := "contains rust linker flag '%s' for '%s' module with coverage disabled; rustcFlags: %#v"
|
||||
|
||||
if !strings.Contains(fizzCovLink.RuleParams.Command, flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCovLink.RuleParams.Command)
|
||||
if !strings.Contains(fizzCovLink.Args["linkFlags"], flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "fizz_cov", fizzCovLink.Args["linkFlags"])
|
||||
}
|
||||
if !strings.Contains(libfooCovLink.RuleParams.Command, flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCovLink.RuleParams.Command)
|
||||
if !strings.Contains(libfooCovLink.Args["linkFlags"], flag) {
|
||||
t.Fatalf(missingErrorStr, flag, "libfoo_cov dylib", libfooCovLink.Args["linkFlags"])
|
||||
}
|
||||
if strings.Contains(buzzNoCovLink.RuleParams.Command, flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCovLink.RuleParams.Command)
|
||||
if strings.Contains(buzzNoCovLink.Args["linkFlags"], flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "buzzNoCov", buzzNoCovLink.Args["linkFlags"])
|
||||
}
|
||||
if strings.Contains(libbarNoCovLink.RuleParams.Command, flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCovLink.RuleParams.Command)
|
||||
if strings.Contains(libbarNoCovLink.Args["linkFlags"], flag) {
|
||||
t.Fatalf(containsErrorStr, flag, "libbar_cov", libbarNoCovLink.Args["linkFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,8 +107,8 @@ func TestCoverageDeps(t *testing.T) {
|
|||
srcs: ["foo.rs"],
|
||||
}`)
|
||||
|
||||
fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a_cov").Rule("rustc")
|
||||
if !strings.Contains(fizz.RuleParams.Command, "libprofile-clang-extras.a") {
|
||||
t.Fatalf("missing expected coverage 'libprofile-clang-extras' dependency in linkFlags: %#v", fizz.RuleParams.Command)
|
||||
fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a_cov").Rule("rustLink")
|
||||
if !strings.Contains(fizz.Args["linkFlags"], "libprofile-clang-extras.a") {
|
||||
t.Fatalf("missing expected coverage 'libprofile-clang-extras' dependency in linkFlags: %#v", fizz.Args["linkFlags"])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,23 +51,23 @@ func TestRustFuzz(t *testing.T) {
|
|||
|
||||
// Check that compiler flags are set appropriately .
|
||||
fuzz_libtest := ctx.ModuleForTests("fuzz_libtest", "android_arm64_armv8-a_fuzzer").Rule("rustc")
|
||||
if !strings.Contains(fuzz_libtest.RuleParams.Command, "-C passes='sancov-module'") ||
|
||||
!strings.Contains(fuzz_libtest.RuleParams.Command, "--cfg fuzzing") {
|
||||
if !strings.Contains(fuzz_libtest.Args["rustcFlags"], "-C passes='sancov-module'") ||
|
||||
!strings.Contains(fuzz_libtest.Args["rustcFlags"], "--cfg fuzzing") {
|
||||
t.Errorf("rust_fuzz module does not contain the expected flags (sancov-module, cfg fuzzing).")
|
||||
}
|
||||
|
||||
// Check that host modules support fuzzing.
|
||||
host_fuzzer := ctx.ModuleForTests("fuzz_libtest", "android_arm64_armv8-a_fuzzer").Rule("rustc")
|
||||
if !strings.Contains(host_fuzzer.RuleParams.Command, "-C passes='sancov-module'") ||
|
||||
!strings.Contains(host_fuzzer.RuleParams.Command, "--cfg fuzzing") {
|
||||
if !strings.Contains(host_fuzzer.Args["rustcFlags"], "-C passes='sancov-module'") ||
|
||||
!strings.Contains(host_fuzzer.Args["rustcFlags"], "--cfg fuzzing") {
|
||||
t.Errorf("rust_fuzz_host module does not contain the expected flags (sancov-module, cfg fuzzing).")
|
||||
}
|
||||
|
||||
// Check that dependencies have 'fuzzer' variants produced for them as well.
|
||||
libtest_fuzzer := ctx.ModuleForTests("libtest_fuzzing", "android_arm64_armv8-a_rlib_rlib-std_fuzzer").Rule("rustc")
|
||||
if !strings.Contains(libtest_fuzzer.RuleParams.Command, "-C passes='sancov-module'") ||
|
||||
!strings.Contains(libtest_fuzzer.RuleParams.Command, "--cfg fuzzing") {
|
||||
t.Errorf("rust_fuzz dependent library does not contain the expected flags (sancov-module, cfg fuzzing). command: %q", libtest_fuzzer.RuleParams.Command)
|
||||
libtest_fuzzer := ctx.ModuleForTests("libtest_fuzzing", "android_arm64_armv8-a_rlib_rlib-std_fuzzer").Output("libtest_fuzzing.rlib")
|
||||
if !strings.Contains(libtest_fuzzer.Args["rustcFlags"], "-C passes='sancov-module'") ||
|
||||
!strings.Contains(libtest_fuzzer.Args["rustcFlags"], "--cfg fuzzing") {
|
||||
t.Errorf("rust_fuzz dependent library does not contain the expected flags (sancov-module, cfg fuzzing).")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,36 +59,36 @@ func TestImageVndkCfgFlag(t *testing.T) {
|
|||
|
||||
vendor := ctx.ModuleForTests("libfoo", "android_vendor.29_arm64_armv8-a_static").Rule("rustc")
|
||||
|
||||
if !strings.Contains(vendor.RuleParams.Command, "--cfg 'android_vndk'") {
|
||||
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.RuleParams.Command)
|
||||
if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vndk'") {
|
||||
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
|
||||
}
|
||||
if !strings.Contains(vendor.RuleParams.Command, "--cfg 'android_vendor'") {
|
||||
t.Errorf("missing \"--cfg 'android_vendor'\" for libfoo vendor variant, rustcFlags: %#v", vendor.RuleParams.Command)
|
||||
if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vendor'") {
|
||||
t.Errorf("missing \"--cfg 'android_vendor'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(vendor.RuleParams.Command, "--cfg 'android_product'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo vendor variant, rustcFlags: %#v", vendor.RuleParams.Command)
|
||||
if strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_product'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
product := ctx.ModuleForTests("libfoo", "android_product.29_arm64_armv8-a_static").Rule("rustc")
|
||||
if !strings.Contains(product.RuleParams.Command, "--cfg 'android_vndk'") {
|
||||
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo product variant, rustcFlags: %#v", product.RuleParams.Command)
|
||||
if !strings.Contains(product.Args["rustcFlags"], "--cfg 'android_vndk'") {
|
||||
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(product.RuleParams.Command, "--cfg 'android_vendor'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vendor'\" for libfoo product variant, rustcFlags: %#v", product.RuleParams.Command)
|
||||
if strings.Contains(product.Args["rustcFlags"], "--cfg 'android_vendor'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vendor'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
|
||||
}
|
||||
if !strings.Contains(product.RuleParams.Command, "--cfg 'android_product'") {
|
||||
t.Errorf("missing \"--cfg 'android_product'\" for libfoo product variant, rustcFlags: %#v", product.RuleParams.Command)
|
||||
if !strings.Contains(product.Args["rustcFlags"], "--cfg 'android_product'") {
|
||||
t.Errorf("missing \"--cfg 'android_product'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
system := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Rule("rustc")
|
||||
if strings.Contains(system.RuleParams.Command, "--cfg 'android_vndk'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vndk'\" for libfoo system variant, rustcFlags: %#v", system.RuleParams.Command)
|
||||
if strings.Contains(system.Args["rustcFlags"], "--cfg 'android_vndk'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vndk'\" for libfoo system variant, rustcFlags: %#v", system.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(system.RuleParams.Command, "--cfg 'android_vendor'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vendor'\" for libfoo system variant, rustcFlags: %#v", system.RuleParams.Command)
|
||||
if strings.Contains(system.Args["rustcFlags"], "--cfg 'android_vendor'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_vendor'\" for libfoo system variant, rustcFlags: %#v", system.Args["rustcFlags"])
|
||||
}
|
||||
if strings.Contains(system.RuleParams.Command, "--cfg 'android_product'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo system variant, rustcFlags: %#v", product.RuleParams.Command)
|
||||
if strings.Contains(system.Args["rustcFlags"], "--cfg 'android_product'") {
|
||||
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo system variant, rustcFlags: %#v", product.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -485,23 +485,6 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F
|
|||
return flags
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) compilationSourcesAndData(ctx ModuleContext) android.Paths {
|
||||
var extraSrcs android.Paths
|
||||
if library.rlib() {
|
||||
extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Rlib.Srcs)
|
||||
} else if library.dylib() {
|
||||
extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Dylib.Srcs)
|
||||
} else if library.static() {
|
||||
extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
|
||||
} else if library.shared() {
|
||||
extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
|
||||
}
|
||||
return android.Concat(
|
||||
library.baseCompiler.compilationSourcesAndData(ctx),
|
||||
extraSrcs,
|
||||
)
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
||||
var outputFile android.ModuleOutPath
|
||||
var ret buildOutput
|
||||
|
@ -542,6 +525,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||
|
||||
flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
|
||||
flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects.Strings()...)
|
||||
|
||||
if library.dylib() {
|
||||
// We need prefer-dynamic for now to avoid linking in the static stdlib. See:
|
||||
|
@ -552,13 +536,13 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||
|
||||
// Call the appropriate builder for this library type
|
||||
if library.rlib() {
|
||||
ret.kytheFile = TransformSrctoRlib(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
} else if library.dylib() {
|
||||
ret.kytheFile = TransformSrctoDylib(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
} else if library.static() {
|
||||
ret.kytheFile = TransformSrctoStatic(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
} else if library.shared() {
|
||||
ret.kytheFile = TransformSrctoShared(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile
|
||||
}
|
||||
|
||||
if library.rlib() || library.dylib() {
|
||||
|
|
|
@ -48,23 +48,23 @@ func TestLibraryVariants(t *testing.T) {
|
|||
staticCrateType := "staticlib"
|
||||
|
||||
// Test crate type for rlib is correct.
|
||||
if !strings.Contains(libfooRlib.RuleParams.Command, "crate-type="+rlibCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooRlib.RuleParams.Command)
|
||||
if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooRlib.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
// Test crate type for dylib is correct.
|
||||
if !strings.Contains(libfooDylib.RuleParams.Command, "crate-type="+dylibCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.RuleParams.Command)
|
||||
if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type="+dylibCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
// Test crate type for C static libraries is correct.
|
||||
if !strings.Contains(libfooStatic.RuleParams.Command, "crate-type="+staticCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.RuleParams.Command)
|
||||
if !strings.Contains(libfooStatic.Args["rustcFlags"], "crate-type="+staticCrateType) {
|
||||
t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
// Test crate type for C shared libraries is correct.
|
||||
if !strings.Contains(libfooShared.RuleParams.Command, "crate-type="+sharedCrateType) {
|
||||
t.Errorf("missing crate-type for shared variant, expecting %#v, got rustcFlags: %#v", sharedCrateType, libfooShared.RuleParams.Command)
|
||||
if !strings.Contains(libfooShared.Args["rustcFlags"], "crate-type="+sharedCrateType) {
|
||||
t.Errorf("missing crate-type for shared variant, expecting %#v, got rustcFlags: %#v", sharedCrateType, libfooShared.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -78,10 +78,10 @@ func TestDylibPreferDynamic(t *testing.T) {
|
|||
crate_name: "foo",
|
||||
}`)
|
||||
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Description("rustc")
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
||||
|
||||
if !strings.Contains(libfooDylib.RuleParams.Command, "prefer-dynamic") {
|
||||
t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.RuleParams.Command)
|
||||
if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") {
|
||||
t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,10 +94,10 @@ func TestAndroidDylib(t *testing.T) {
|
|||
crate_name: "foo",
|
||||
}`)
|
||||
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Description("rustc")
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
|
||||
|
||||
if !strings.Contains(libfooDylib.RuleParams.Command, "--cfg 'android_dylib'") {
|
||||
t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.RuleParams.Command)
|
||||
if !strings.Contains(libfooDylib.Args["rustcFlags"], "--cfg 'android_dylib'") {
|
||||
t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,10 +148,10 @@ func TestSharedLibrary(t *testing.T) {
|
|||
|
||||
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared")
|
||||
|
||||
libfooOutput := libfoo.Rule("rustc")
|
||||
if !strings.Contains(libfooOutput.RuleParams.Command, "-Wl,-soname=libfoo.so") {
|
||||
libfooOutput := libfoo.Rule("rustLink")
|
||||
if !strings.Contains(libfooOutput.Args["linkFlags"], "-Wl,-soname=libfoo.so") {
|
||||
t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v",
|
||||
libfooOutput.RuleParams.Command)
|
||||
libfooOutput.Args["linkFlags"])
|
||||
}
|
||||
|
||||
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkDylibs) {
|
||||
|
@ -237,21 +237,19 @@ func TestNativeDependencyOfRlib(t *testing.T) {
|
|||
// The build system assumes the cc deps will be at the final linkage (either a shared library or binary)
|
||||
// Hence, these flags are no-op
|
||||
// TODO: We could consider removing these flags
|
||||
expectedSharedFlag := "-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared"
|
||||
expectedStaticFlag := "-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static"
|
||||
for _, module := range modules {
|
||||
if !strings.Contains(module.Rule("rustc").RuleParams.Command, expectedSharedFlag) {
|
||||
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
||||
"-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared/") {
|
||||
t.Errorf(
|
||||
"expected to find shared library linkdir flag %q, rustcFlags: %#v",
|
||||
expectedSharedFlag,
|
||||
rustRlibRlibStd.Rule("rustc").RuleParams.Command,
|
||||
"missing -L flag for shared_cc_dep, rustcFlags: %#v",
|
||||
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
||||
)
|
||||
}
|
||||
if !strings.Contains(module.Rule("rustc").RuleParams.Command, expectedStaticFlag) {
|
||||
if !strings.Contains(module.Rule("rustc").Args["libFlags"],
|
||||
"-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static/") {
|
||||
t.Errorf(
|
||||
"expected to find static library linkdir flag %q, rustcFlags: %#v",
|
||||
expectedStaticFlag,
|
||||
rustRlibRlibStd.Rule("rustc").RuleParams.Command,
|
||||
"missing -L flag for static_cc_dep, rustcFlags: %#v",
|
||||
rustRlibRlibStd.Rule("rustc").Args["libFlags"],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,10 +146,7 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
|||
}
|
||||
|
||||
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
||||
deps.linkDirs = append(deps.linkDirs, android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs)...)
|
||||
prebuilt.flagExporter.exportLinkDirs(deps.linkDirs...)
|
||||
prebuilt.flagExporter.exportLinkObjects(deps.linkObjects...)
|
||||
prebuilt.flagExporter.exportLibDeps(deps.LibDeps...)
|
||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||
prebuilt.flagExporter.setProvider(ctx)
|
||||
|
||||
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
||||
|
@ -206,7 +203,7 @@ func (prebuilt *prebuiltProcMacroDecorator) compilerProps() []interface{} {
|
|||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs)...)
|
||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||
prebuilt.flagExporter.setProvider(ctx)
|
||||
|
||||
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
||||
|
|
|
@ -80,7 +80,7 @@ func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, dep
|
|||
outputFile := android.PathForModuleOut(ctx, fileName)
|
||||
|
||||
srcPath, _ := srcPathFromModuleSrcs(ctx, procMacro.baseCompiler.Properties.Srcs)
|
||||
ret := TransformSrctoProcMacro(ctx, procMacro, srcPath, deps, flags, outputFile)
|
||||
ret := TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile)
|
||||
procMacro.baseCompiler.unstrippedOutputFile = outputFile
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestRustProcMacro(t *testing.T) {
|
|||
|
||||
libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc")
|
||||
|
||||
if !strings.Contains(libprocmacro.RuleParams.Command, "--extern proc_macro") {
|
||||
t.Errorf("--extern proc_macro flag not being passed to rustc for proc macro %#v", libprocmacro.RuleParams.Command)
|
||||
if !strings.Contains(libprocmacro.Args["rustcFlags"], "--extern proc_macro") {
|
||||
t.Errorf("--extern proc_macro flag not being passed to rustc for proc macro %#v", libprocmacro.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
|
140
rust/rust.go
140
rust/rust.go
|
@ -438,18 +438,12 @@ type Deps struct {
|
|||
}
|
||||
|
||||
type PathDeps struct {
|
||||
Dylibs *android.DepSet[RustLibrary]
|
||||
Rlibs *android.DepSet[RustLibrary]
|
||||
ProcMacros *android.DepSet[RustLibrary]
|
||||
DyLibs RustLibraries
|
||||
RLibs RustLibraries
|
||||
LibDeps android.Paths
|
||||
WholeStaticLibs android.Paths
|
||||
ProcMacros RustLibraries
|
||||
AfdoProfiles android.Paths
|
||||
// These paths are files needed to run the build tools and will be located under
|
||||
// __SBOX_SANDBOX_DIR__/tools/...
|
||||
BuildToolDeps android.Paths
|
||||
// These paths are files needed to run the build tools and will be located under
|
||||
// __SBOX_SANDBOX_DIR__/...
|
||||
BuildToolSrcDeps android.Paths
|
||||
|
||||
// depFlags and depLinkFlags are rustc and linker (clang) flags.
|
||||
depFlags []string
|
||||
|
@ -457,7 +451,7 @@ type PathDeps struct {
|
|||
|
||||
// linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
|
||||
// Both of these are exported and propagate to dependencies.
|
||||
linkDirs android.Paths
|
||||
linkDirs []string
|
||||
linkObjects android.Paths
|
||||
|
||||
// Used by bindgen modules which call clang
|
||||
|
@ -472,13 +466,6 @@ 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
|
||||
|
@ -498,8 +485,6 @@ type compiler interface {
|
|||
compilerDeps(ctx DepsContext, deps Deps) Deps
|
||||
crateName() string
|
||||
rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
|
||||
crateRoot(ctx ModuleContext) android.Path
|
||||
compilationSourcesAndData(ctx ModuleContext) android.Paths
|
||||
|
||||
// Output directory in which source-generated code from dependencies is
|
||||
// copied. This is equivalent to Cargo's OUT_DIR variable.
|
||||
|
@ -529,7 +514,7 @@ type compiler interface {
|
|||
}
|
||||
|
||||
type exportedFlagsProducer interface {
|
||||
exportLinkDirs(...android.Path)
|
||||
exportLinkDirs(...string)
|
||||
exportLinkObjects(...android.Path)
|
||||
}
|
||||
|
||||
|
@ -538,13 +523,13 @@ type xref interface {
|
|||
}
|
||||
|
||||
type flagExporter struct {
|
||||
linkDirs android.Paths
|
||||
linkDirs []string
|
||||
linkObjects android.Paths
|
||||
libDeps android.Paths
|
||||
}
|
||||
|
||||
func (flagExporter *flagExporter) exportLinkDirs(dirs ...android.Path) {
|
||||
flagExporter.linkDirs = android.FirstUniquePaths(append(flagExporter.linkDirs, dirs...))
|
||||
func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
|
||||
flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
|
||||
}
|
||||
|
||||
func (flagExporter *flagExporter) exportLinkObjects(flags ...android.Path) {
|
||||
|
@ -571,7 +556,7 @@ func NewFlagExporter() *flagExporter {
|
|||
|
||||
type FlagExporterInfo struct {
|
||||
Flags []string
|
||||
LinkDirs android.Paths
|
||||
LinkDirs []string // TODO: this should be android.Paths
|
||||
LinkObjects android.Paths
|
||||
LibDeps android.Paths
|
||||
}
|
||||
|
@ -941,14 +926,6 @@ func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchai
|
|||
func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
}
|
||||
|
||||
type RustInfo struct {
|
||||
TransitiveRlibs *android.DepSet[RustLibrary]
|
||||
TransitiveDylibs *android.DepSet[RustLibrary]
|
||||
TransitiveProcMacros *android.DepSet[RustLibrary]
|
||||
}
|
||||
|
||||
var RustInfoProvider = blueprint.NewProvider(RustInfo{})
|
||||
|
||||
func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
ctx := &moduleContext{
|
||||
ModuleContext: actx,
|
||||
|
@ -1058,12 +1035,6 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||
|
||||
ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
|
||||
}
|
||||
|
||||
ctx.SetProvider(RustInfoProvider, RustInfo{
|
||||
TransitiveRlibs: deps.Rlibs,
|
||||
TransitiveDylibs: deps.Dylibs,
|
||||
TransitiveProcMacros: deps.ProcMacros,
|
||||
})
|
||||
}
|
||||
|
||||
func (mod *Module) deps(ctx DepsContext) Deps {
|
||||
|
@ -1122,7 +1093,6 @@ func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
|
|||
var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
|
||||
|
||||
var (
|
||||
buildToolDepTag = dependencyTag{name: "buildToolTag"}
|
||||
customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
|
||||
rlibDepTag = dependencyTag{name: "rlibTag", library: true}
|
||||
dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
|
||||
|
@ -1256,9 +1226,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
|
||||
var transitiveAndroidMkSharedLibs []*android.DepSet[string]
|
||||
var directAndroidMkSharedLibs []string
|
||||
transitiveRlibs := android.NewDepSetBuilder[RustLibrary](android.PREORDER)
|
||||
transitiveDylibs := android.NewDepSetBuilder[RustLibrary](android.PREORDER)
|
||||
transitiveProcMacros := android.NewDepSetBuilder[RustLibrary](android.PREORDER)
|
||||
|
||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||
depName := ctx.OtherModuleName(dep)
|
||||
depTag := ctx.OtherModuleDependencyTag(dep)
|
||||
|
@ -1271,17 +1239,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
return
|
||||
}
|
||||
|
||||
rustInfo := ctx.OtherModuleProvider(dep, RustInfoProvider).(RustInfo)
|
||||
if rustInfo.TransitiveDylibs != nil {
|
||||
transitiveDylibs.Transitive(rustInfo.TransitiveDylibs)
|
||||
}
|
||||
if rustInfo.TransitiveRlibs != nil {
|
||||
transitiveRlibs.Transitive(rustInfo.TransitiveRlibs)
|
||||
}
|
||||
if rustInfo.TransitiveProcMacros != nil {
|
||||
transitiveProcMacros.Transitive(rustInfo.TransitiveProcMacros)
|
||||
}
|
||||
|
||||
if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
|
||||
//Handle Rust Modules
|
||||
makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
|
||||
|
@ -1296,12 +1253,9 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
directDylibDeps = append(directDylibDeps, rustDep)
|
||||
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
|
||||
mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
|
||||
transitiveDylibs.Direct(RustLibrary{
|
||||
Path: rustDep.UnstrippedOutputFile(),
|
||||
CrateName: rustDep.CrateName(),
|
||||
})
|
||||
|
||||
case rlibDepTag:
|
||||
|
||||
rlib, ok := rustDep.compiler.(libraryInterface)
|
||||
if !ok || !rlib.rlib() {
|
||||
ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
|
||||
|
@ -1310,18 +1264,10 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
directRlibDeps = append(directRlibDeps, rustDep)
|
||||
mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
|
||||
mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName))
|
||||
transitiveRlibs.Direct(RustLibrary{
|
||||
Path: rustDep.UnstrippedOutputFile(),
|
||||
CrateName: rustDep.CrateName(),
|
||||
})
|
||||
|
||||
case procMacroDepTag:
|
||||
directProcMacroDeps = append(directProcMacroDeps, rustDep)
|
||||
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
|
||||
transitiveProcMacros.Direct(RustLibrary{
|
||||
Path: rustDep.UnstrippedOutputFile(),
|
||||
CrateName: rustDep.CrateName(),
|
||||
})
|
||||
}
|
||||
|
||||
transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs)
|
||||
|
@ -1357,8 +1303,9 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
|
||||
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
|
||||
linkFile := rustDep.UnstrippedOutputFile()
|
||||
linkDir := linkPathFromFilePath(linkFile)
|
||||
if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
|
||||
lib.exportLinkDirs(linkFile.Dir())
|
||||
lib.exportLinkDirs(linkDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1385,7 +1332,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
return
|
||||
}
|
||||
|
||||
linkPath := linkObject.Path().Dir()
|
||||
linkPath := linkPathFromFilePath(linkObject.Path())
|
||||
|
||||
exportDep := false
|
||||
switch {
|
||||
|
@ -1439,7 +1386,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
}
|
||||
return
|
||||
}
|
||||
linkPath = linkObject.Path().Dir()
|
||||
linkPath = linkPathFromFilePath(linkObject.Path())
|
||||
|
||||
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
|
||||
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...)
|
||||
|
@ -1474,25 +1421,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
}
|
||||
} else {
|
||||
switch {
|
||||
case depTag == buildToolDepTag:
|
||||
buildTool := ctx.OtherModuleProvider(dep, android.PrebuiltBuildToolInfoProvider).(android.PrebuiltBuildToolInfo)
|
||||
depPaths.BuildToolDeps = append(depPaths.BuildToolDeps, buildTool.Src)
|
||||
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, ""))
|
||||
case depTag == cc.CrtEndDepTag:
|
||||
|
@ -1508,6 +1436,21 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
}
|
||||
})
|
||||
|
||||
mod.transitiveAndroidMkSharedLibs = android.NewDepSet[string](android.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs)
|
||||
|
||||
var rlibDepFiles RustLibraries
|
||||
for _, dep := range directRlibDeps {
|
||||
rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
|
||||
}
|
||||
var dylibDepFiles RustLibraries
|
||||
for _, dep := range directDylibDeps {
|
||||
dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
|
||||
}
|
||||
var procMacroDepFiles RustLibraries
|
||||
for _, dep := range directProcMacroDeps {
|
||||
procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
|
||||
}
|
||||
|
||||
var libDepFiles android.Paths
|
||||
for _, dep := range directStaticLibDeps {
|
||||
libDepFiles = append(libDepFiles, dep.OutputFile().Path())
|
||||
|
@ -1531,22 +1474,20 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||
srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
|
||||
}
|
||||
|
||||
depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
|
||||
depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
|
||||
depPaths.LibDeps = append(depPaths.LibDeps, libDepFiles...)
|
||||
depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
|
||||
depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
|
||||
|
||||
// Dedup exported flags from dependencies
|
||||
depPaths.linkDirs = android.FirstUniquePaths(depPaths.linkDirs)
|
||||
depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
|
||||
depPaths.linkObjects = android.FirstUniquePaths(depPaths.linkObjects)
|
||||
depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
|
||||
depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
|
||||
depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
|
||||
depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
|
||||
|
||||
depPaths.Rlibs = transitiveRlibs.Build()
|
||||
depPaths.Dylibs = transitiveDylibs.Build()
|
||||
depPaths.ProcMacros = transitiveProcMacros.Build()
|
||||
mod.transitiveAndroidMkSharedLibs = android.NewDepSet[string](android.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs)
|
||||
|
||||
return depPaths
|
||||
}
|
||||
|
||||
|
@ -1569,6 +1510,10 @@ func (mod *Module) InstallInRecovery() bool {
|
|||
return mod.InRecovery()
|
||||
}
|
||||
|
||||
func linkPathFromFilePath(filepath android.Path) string {
|
||||
return strings.Split(filepath.String(), filepath.Base())[0]
|
||||
}
|
||||
|
||||
// usePublicApi returns true if the rust variant should link against NDK (publicapi)
|
||||
func (r *Module) usePublicApi() bool {
|
||||
return r.Device() && r.UseSdk()
|
||||
|
@ -1611,15 +1556,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||
blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
|
||||
}
|
||||
|
||||
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})
|
||||
for _, lib := range deps.Rlibs {
|
||||
|
|
|
@ -15,17 +15,14 @@
|
|||
package rust
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cmd/sbox/sbox_proto"
|
||||
"android/soong/genrule"
|
||||
)
|
||||
|
||||
|
@ -67,14 +64,11 @@ var rustMockedFiles = android.MockFS{
|
|||
|
||||
// testRust returns a TestContext in which a basic environment has been setup.
|
||||
// This environment contains a few mocked files. See rustMockedFiles for the list of these files.
|
||||
func testRust(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext {
|
||||
func testRust(t *testing.T, bp string) *android.TestContext {
|
||||
skipTestIfOsNotSupported(t)
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForRustTest,
|
||||
rustMockedFiles.AddToFixture(),
|
||||
android.GroupFixturePreparers(
|
||||
preparers...,
|
||||
),
|
||||
).
|
||||
RunTestWithBp(t, bp)
|
||||
return result.TestContext
|
||||
|
@ -208,11 +202,11 @@ func skipTestIfOsNotSupported(t *testing.T) {
|
|||
// Test that we can extract the link path from a lib path.
|
||||
func TestLinkPathFromFilePath(t *testing.T) {
|
||||
barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so")
|
||||
libName := barPath.Dir()
|
||||
expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared"
|
||||
libName := linkPathFromFilePath(barPath)
|
||||
expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/"
|
||||
|
||||
if libName.String() != expectedResult {
|
||||
t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName.String())
|
||||
if libName != expectedResult {
|
||||
t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +256,7 @@ func TestDepsTracking(t *testing.T) {
|
|||
`)
|
||||
module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
|
||||
rustc := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
||||
rustLink := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustc")
|
||||
rustLink := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustLink")
|
||||
|
||||
// Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
|
||||
if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) {
|
||||
|
@ -281,16 +275,16 @@ func TestDepsTracking(t *testing.T) {
|
|||
t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)")
|
||||
}
|
||||
|
||||
if !strings.Contains(rustc.RuleParams.Command, "-lstatic=wholestatic") {
|
||||
t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.RuleParams.Command)
|
||||
if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=wholestatic") {
|
||||
t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.Args["rustcFlags"])
|
||||
}
|
||||
|
||||
if !strings.Contains(rustLink.RuleParams.Command, "cc_stubs_dep.so") {
|
||||
t.Errorf("shared cc_library not being passed to rustc linkFlags %#v", rustLink.RuleParams.Command)
|
||||
if !strings.Contains(rustLink.Args["linkFlags"], "cc_stubs_dep.so") {
|
||||
t.Errorf("shared cc_library not being passed to rustc linkFlags %#v", rustLink.Args["linkFlags"])
|
||||
}
|
||||
|
||||
if !android.SuffixInList(rustLink.Implicits.Strings(), "cc_stubs_dep.so") {
|
||||
t.Errorf("shared cc dep not being passed as implicit to rustc %#v", rustLink.OrderOnly.Strings())
|
||||
if !android.SuffixInList(rustLink.OrderOnly.Strings(), "cc_stubs_dep.so") {
|
||||
t.Errorf("shared cc dep not being passed as order-only to rustc %#v", rustLink.OrderOnly.Strings())
|
||||
}
|
||||
|
||||
if !android.SuffixInList(rustLink.Implicits.Strings(), "cc_stubs_dep.so.toc") {
|
||||
|
@ -433,7 +427,7 @@ func TestProcMacroDeviceDeps(t *testing.T) {
|
|||
`)
|
||||
rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc")
|
||||
|
||||
if !strings.Contains(rustc.RuleParams.Command, "libbar/linux_glibc_x86_64") {
|
||||
if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") {
|
||||
t.Errorf("Proc_macro is not using host variant of dependent modules.")
|
||||
}
|
||||
}
|
||||
|
@ -486,396 +480,3 @@ func assertString(t *testing.T, got, expected string) {
|
|||
t.Errorf("expected %q got %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
sboxCompilationFiles = []string{
|
||||
"out/soong/.intermediates/defaults/rust/libaddr2line/android_arm64_armv8-a_rlib/libaddr2line.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libadler/android_arm64_armv8-a_rlib/libadler.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/liballoc/android_arm64_armv8-a_rlib/liballoc.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libcfg_if/android_arm64_armv8-a_rlib/libcfg_if.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libcompiler_builtins/android_arm64_armv8-a_rlib/libcompiler_builtins.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libcore/android_arm64_armv8-a_rlib/libcore.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libgimli/android_arm64_armv8-a_rlib/libgimli.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libhashbrown/android_arm64_armv8-a_rlib/libhashbrown.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/liblibc/android_arm64_armv8-a_rlib/liblibc.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libmemchr/android_arm64_armv8-a_rlib/libmemchr.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libminiz_oxide/android_arm64_armv8-a_rlib/libminiz_oxide.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libobject/android_arm64_armv8-a_rlib/libobject.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libpanic_unwind/android_arm64_armv8-a_rlib/libpanic_unwind.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/librustc_demangle/android_arm64_armv8-a_rlib/librustc_demangle.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/librustc_std_workspace_alloc/android_arm64_armv8-a_rlib/librustc_std_workspace_alloc.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/librustc_std_workspace_core/android_arm64_armv8-a_rlib/librustc_std_workspace_core.rlib",
|
||||
"out/soong/.intermediates/defaults/rust/libstd_detect/android_arm64_armv8-a_rlib/libstd_detect.rlib",
|
||||
"build/soong/scripts/mkcratersp.py",
|
||||
"defaults/rust/linux-x86/1.69.0/bin/rustc",
|
||||
"defaults/rust/linux-x86/1.69.0/lib/libstd.so",
|
||||
"defaults/rust/linux-x86/1.69.0/lib64/libc++.so.1",
|
||||
}
|
||||
sboxCompilationFilesWithCc = []string{
|
||||
"defaults/cc/common",
|
||||
"out/soong/.intermediates/defaults/cc/common/libc/android_arm64_armv8-a_shared/libc.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libc/android_arm64_armv8-a_shared/libc.so.toc",
|
||||
"out/soong/.intermediates/defaults/cc/common/libdl/android_arm64_armv8-a_shared/libdl.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libdl/android_arm64_armv8-a_shared/libdl.so.toc",
|
||||
"out/soong/.intermediates/defaults/cc/common/libm/android_arm64_armv8-a_shared/libm.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libm/android_arm64_armv8-a_shared/libm.so.toc",
|
||||
"out/soong/.intermediates/defaults/rust/liblog/android_arm64_armv8-a_shared/liblog.so",
|
||||
"out/soong/.intermediates/defaults/rust/liblog/android_arm64_armv8-a_shared/liblog.so.toc",
|
||||
}
|
||||
)
|
||||
|
||||
func TestSandboxCompilation(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
filegroup {
|
||||
name: "libsrcs1",
|
||||
srcs: ["src_filegroup1.rs"],
|
||||
}
|
||||
filegroup {
|
||||
name: "libsrcs2",
|
||||
srcs: ["src_filegroup2.rs"],
|
||||
}
|
||||
rust_library {
|
||||
name: "libfizz_buzz",
|
||||
crate_name:"fizz_buzz",
|
||||
crate_root: "foo.rs",
|
||||
srcs: [
|
||||
"src_lib*.rs",
|
||||
":libsrcs1",
|
||||
":libsrcs2",
|
||||
],
|
||||
compile_data: [
|
||||
"compile_data1.txt",
|
||||
"compile_data2.txt",
|
||||
],
|
||||
dylib: {
|
||||
srcs: ["dylib_only.rs"],
|
||||
},
|
||||
rlib: {
|
||||
srcs: ["rlib_only.rs"],
|
||||
},
|
||||
}
|
||||
rust_binary {
|
||||
name: "fizz_buzz",
|
||||
crate_name:"fizz_buzz",
|
||||
crate_root: "foo.rs",
|
||||
srcs: [
|
||||
"src_lib*.rs",
|
||||
":libsrcs1",
|
||||
":libsrcs2",
|
||||
],
|
||||
}
|
||||
rust_ffi {
|
||||
name: "librust_ffi",
|
||||
crate_name: "rust_ffi",
|
||||
crate_root: "foo.rs",
|
||||
static: {
|
||||
srcs: ["static_only.rs"],
|
||||
},
|
||||
shared: {
|
||||
srcs: ["shared_only.rs"],
|
||||
},
|
||||
srcs: ["src1.rs"],
|
||||
}
|
||||
cc_library_static {
|
||||
name: "cc_dep_static",
|
||||
}
|
||||
cc_library_shared {
|
||||
name: "cc_dep_shared",
|
||||
}
|
||||
rust_library {
|
||||
name: "libfizz_buzz_cc_deps",
|
||||
crate_name:"fizz_buzz",
|
||||
crate_root: "foo.rs",
|
||||
srcs: ["src*.rs"],
|
||||
shared_libs: ["cc_dep_shared"],
|
||||
static_libs: ["cc_dep_static"],
|
||||
}
|
||||
rust_library {
|
||||
name: "libfizz_buzz_intermediate_cc_deps",
|
||||
crate_name:"fizz_buzz",
|
||||
crate_root: "foo.rs",
|
||||
srcs: ["src*.rs"],
|
||||
rustlibs: ["libfizz_buzz_cc_deps"],
|
||||
}
|
||||
rust_library {
|
||||
name: "libfizz_buzz_transitive_cc_deps",
|
||||
crate_name:"fizz_buzz",
|
||||
crate_root: "foo.rs",
|
||||
srcs: ["src*.rs"],
|
||||
rustlibs: ["libfizz_buzz_intermediate_cc_deps"],
|
||||
}
|
||||
`,
|
||||
android.FixtureMergeMockFs(android.MockFS{
|
||||
"src_lib1.rs": nil,
|
||||
"src_lib2.rs": nil,
|
||||
"src_lib3.rs": nil,
|
||||
"src_lib4.rs": nil,
|
||||
"src_filegroup1.rs": nil,
|
||||
"src_filegroup2.rs": nil,
|
||||
"static_only.rs": nil,
|
||||
"shared_only.rs": nil,
|
||||
}),
|
||||
)
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
moduleName string
|
||||
variant string
|
||||
rustcExpectedFilesToCopy []string
|
||||
expectedFlags []string
|
||||
}{
|
||||
{
|
||||
name: "rust_library (dylib)",
|
||||
moduleName: "libfizz_buzz",
|
||||
variant: "android_arm64_armv8-a_dylib",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, sboxCompilationFilesWithCc, []string{
|
||||
"foo.rs",
|
||||
"src_lib1.rs",
|
||||
"src_lib2.rs",
|
||||
"src_lib3.rs",
|
||||
"src_lib4.rs",
|
||||
"src_filegroup1.rs",
|
||||
"src_filegroup2.rs",
|
||||
"compile_data1.txt",
|
||||
"compile_data2.txt",
|
||||
"dylib_only.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_dylib/out/src_filegroup1.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_dylib/out/src_filegroup2.rs",
|
||||
|
||||
"out/soong/.intermediates/defaults/cc/common/libc/android_arm64_armv8-a_shared/libc.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libc/android_arm64_armv8-a_shared/libc.so.toc",
|
||||
"out/soong/.intermediates/defaults/cc/common/libm/android_arm64_armv8-a_shared/libm.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libm/android_arm64_armv8-a_shared/libm.so.toc",
|
||||
"out/soong/.intermediates/defaults/cc/common/libdl/android_arm64_armv8-a_shared/libdl.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/libdl/android_arm64_armv8-a_shared/libdl.so.toc",
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_dylib/unstripped/libstd.dylib.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtbegin_so/android_arm64_armv8-a/crtbegin_so.o",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtend_so/android_arm64_armv8-a/crtend_so.o",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_dylib/libfizz_buzz.dylib.so.clippy",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"-C linker=build/soong/scripts/mkcratersp.py",
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/libfizz_buzz.dylib.so.rsp",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/libfizz_buzz.dylib.so.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library (rlib dylib-std)",
|
||||
moduleName: "libfizz_buzz",
|
||||
variant: "android_arm64_armv8-a_rlib_dylib-std",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, []string{
|
||||
"foo.rs",
|
||||
"src_lib1.rs",
|
||||
"src_lib2.rs",
|
||||
"src_lib3.rs",
|
||||
"src_lib4.rs",
|
||||
"src_filegroup1.rs",
|
||||
"src_filegroup2.rs",
|
||||
"rlib_only.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_rlib_dylib-std/out/src_filegroup1.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_rlib_dylib-std/out/src_filegroup2.rs",
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_dylib/unstripped/libstd.dylib.so",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/libfizz_buzz.rlib",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/libfizz_buzz.rlib.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library (rlib rlib-std)",
|
||||
moduleName: "libfizz_buzz",
|
||||
variant: "android_arm64_armv8-a_rlib_rlib-std",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, []string{
|
||||
"foo.rs",
|
||||
"src_lib1.rs",
|
||||
"src_lib2.rs",
|
||||
"src_lib3.rs",
|
||||
"src_lib4.rs",
|
||||
"src_filegroup1.rs",
|
||||
"src_filegroup2.rs",
|
||||
"rlib_only.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_rlib_rlib-std/out/src_filegroup1.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_rlib_rlib-std/out/src_filegroup2.rs",
|
||||
"out/soong/.intermediates/libfizz_buzz/android_arm64_armv8-a_rlib_rlib-std/libfizz_buzz.rlib.clippy",
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_rlib/libstd.rlib",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/libfizz_buzz.rlib",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/libfizz_buzz.rlib.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_binary",
|
||||
moduleName: "fizz_buzz",
|
||||
variant: "android_arm64_armv8-a",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, sboxCompilationFilesWithCc, []string{
|
||||
"foo.rs",
|
||||
"src_lib1.rs",
|
||||
"src_lib2.rs",
|
||||
"src_lib3.rs",
|
||||
"src_lib4.rs",
|
||||
"src_filegroup1.rs",
|
||||
"src_filegroup2.rs",
|
||||
"out/soong/.intermediates/fizz_buzz/android_arm64_armv8-a/out/src_filegroup1.rs",
|
||||
"out/soong/.intermediates/fizz_buzz/android_arm64_armv8-a/out/src_filegroup2.rs",
|
||||
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_dylib/unstripped/libstd.dylib.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtbegin_dynamic/android_arm64_armv8-a/crtbegin_dynamic.o",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtend_android/android_arm64_armv8-a/crtend_android.o",
|
||||
"out/soong/.intermediates/fizz_buzz/android_arm64_armv8-a/fizz_buzz.clippy",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/fizz_buzz",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/fizz_buzz.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_ffi static lib variant",
|
||||
moduleName: "librust_ffi",
|
||||
variant: "android_arm64_armv8-a_static",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, []string{
|
||||
"foo.rs",
|
||||
"src1.rs",
|
||||
"static_only.rs",
|
||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/librust_ffi.a.clippy",
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_rlib/libstd.rlib",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/librust_ffi.a",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/librust_ffi.a.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_ffi shared lib variant",
|
||||
moduleName: "librust_ffi",
|
||||
variant: "android_arm64_armv8-a_shared",
|
||||
rustcExpectedFilesToCopy: android.Concat(sboxCompilationFiles, sboxCompilationFilesWithCc, []string{
|
||||
"foo.rs",
|
||||
"src1.rs",
|
||||
"shared_only.rs",
|
||||
|
||||
"out/soong/.intermediates/defaults/rust/libstd/android_arm64_armv8-a_dylib/unstripped/libstd.dylib.so",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtbegin_so/android_arm64_armv8-a/crtbegin_so.o",
|
||||
"out/soong/.intermediates/defaults/cc/common/crtend_so/android_arm64_armv8-a/crtend_so.o",
|
||||
"out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/librust_ffi.so.clippy",
|
||||
}),
|
||||
expectedFlags: []string{
|
||||
"--emit link",
|
||||
"-o __SBOX_SANDBOX_DIR__/out/librust_ffi.so",
|
||||
"--emit dep-info=__SBOX_SANDBOX_DIR__/out/librust_ffi.so.d.raw",
|
||||
"foo.rs", // this is the entry point
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with cc deps (dylib)",
|
||||
moduleName: "libfizz_buzz_cc_deps",
|
||||
variant: "android_arm64_armv8-a_dylib",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with cc deps (rlib rlib-std)",
|
||||
moduleName: "libfizz_buzz_cc_deps",
|
||||
variant: "android_arm64_armv8-a_rlib_rlib-std",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with cc deps (rlib dylib-std)",
|
||||
moduleName: "libfizz_buzz_cc_deps",
|
||||
variant: "android_arm64_armv8-a_rlib_dylib-std",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with transitive cc deps (dylib)",
|
||||
moduleName: "libfizz_buzz_transitive_cc_deps",
|
||||
variant: "android_arm64_armv8-a_dylib",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with transitive cc deps (rlib rlib-std)",
|
||||
moduleName: "libfizz_buzz_transitive_cc_deps",
|
||||
variant: "android_arm64_armv8-a_rlib_rlib-std",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rust_library with transitive cc deps (rlib dylib-std)",
|
||||
moduleName: "libfizz_buzz_transitive_cc_deps",
|
||||
variant: "android_arm64_armv8-a_rlib_dylib-std",
|
||||
rustcExpectedFilesToCopy: []string{
|
||||
"out/soong/.intermediates/cc_dep_static/android_arm64_armv8-a_static/cc_dep_static.a",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so",
|
||||
"out/soong/.intermediates/cc_dep_shared/android_arm64_armv8-a_shared/cc_dep_shared.so.toc",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
writeFile := ctx.ModuleForTests(tc.moduleName, tc.variant).Rule("unescapedWriteFile")
|
||||
contents := writeFile.BuildParams.Args["content"]
|
||||
manifestProto := sbox_proto.Manifest{}
|
||||
err := prototext.Unmarshal([]byte(contents), &manifestProto)
|
||||
if err != nil {
|
||||
t.Errorf("expected no errors unmarshaling manifest proto; got %v", err)
|
||||
}
|
||||
|
||||
if len(manifestProto.Commands) != 1 {
|
||||
t.Errorf("expected 1 command; got %v", len(manifestProto.Commands))
|
||||
}
|
||||
|
||||
// check that sandbox contains correct files
|
||||
rustc := manifestProto.Commands[0]
|
||||
actualFilesToCopy := []string{}
|
||||
for _, copy := range rustc.CopyBefore {
|
||||
actualFilesToCopy = append(actualFilesToCopy, copy.GetFrom())
|
||||
}
|
||||
_, expectedFilesNotCopied, _ := android.ListSetDifference(tc.rustcExpectedFilesToCopy, actualFilesToCopy)
|
||||
if len(expectedFilesNotCopied) > 0 {
|
||||
t.Errorf("did not copy expected files to sbox: %v;\n files copied: %v", expectedFilesNotCopied, actualFilesToCopy)
|
||||
}
|
||||
|
||||
rustcCmd := proptools.String(rustc.Command)
|
||||
for _, flag := range tc.expectedFlags {
|
||||
android.AssertStringDoesContain(
|
||||
t,
|
||||
fmt.Sprintf(
|
||||
"missing flag in rustc invocation; expected to find substring %q; got %q",
|
||||
flag,
|
||||
rustcCmd,
|
||||
),
|
||||
rustcCmd,
|
||||
flag,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNo
|
|||
note_sync := "note_memtag_heap_sync"
|
||||
|
||||
found := None
|
||||
implicits := m.Rule("rustc").Implicits
|
||||
implicits := m.Rule("rustLink").Implicits
|
||||
for _, lib := range implicits {
|
||||
if strings.Contains(lib.Rel(), note_async) {
|
||||
found = Async
|
||||
|
|
326
rust/testing.go
326
rust/testing.go
|
@ -52,22 +52,6 @@ var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers(
|
|||
|
||||
func GatherRequiredDepsForTest() string {
|
||||
bp := `
|
||||
prebuilt_build_tool {
|
||||
name: "rustc",
|
||||
src: "linux-x86/1.69.0/bin/rustc",
|
||||
deps: [
|
||||
"linux-x86/1.69.0/lib/libstd.so",
|
||||
"linux-x86/1.69.0/lib64/libc++.so.1",
|
||||
],
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "clippy-driver",
|
||||
src: "linux-x86/1.69.0/bin/clippy-driver",
|
||||
}
|
||||
prebuilt_build_tool {
|
||||
name: "rustdoc",
|
||||
src: "linux-x86/1.69.0/bin/rustdoc",
|
||||
}
|
||||
rust_prebuilt_library {
|
||||
name: "libstd",
|
||||
crate_name: "std",
|
||||
|
@ -79,25 +63,6 @@ func GatherRequiredDepsForTest() string {
|
|||
},
|
||||
host_supported: true,
|
||||
sysroot: true,
|
||||
rlibs: [
|
||||
"libaddr2line",
|
||||
"libadler",
|
||||
"liballoc",
|
||||
"libcfg_if",
|
||||
"libcompiler_builtins",
|
||||
"libcore",
|
||||
"libgimli",
|
||||
"libhashbrown",
|
||||
"liblibc",
|
||||
"libmemchr",
|
||||
"libminiz_oxide",
|
||||
"libobject",
|
||||
"libpanic_unwind",
|
||||
"librustc_demangle",
|
||||
"librustc_std_workspace_alloc",
|
||||
"librustc_std_workspace_core",
|
||||
"libstd_detect",
|
||||
],
|
||||
}
|
||||
//////////////////////////////
|
||||
// Device module requirements
|
||||
|
@ -134,278 +99,6 @@ func GatherRequiredDepsForTest() string {
|
|||
nocrt: true,
|
||||
system_shared_libs: [],
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libaddr2line",
|
||||
crate_name: "addr2line",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libadler",
|
||||
crate_name: "adler",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "liballoc",
|
||||
crate_name: "alloc",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libcfg_if",
|
||||
crate_name: "cfg_if",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libcompiler_builtins",
|
||||
crate_name: "compiler_builtins",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libcore",
|
||||
crate_name: "core",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libgimli",
|
||||
crate_name: "gimli",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libhashbrown",
|
||||
crate_name: "hashbrown",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "liblibc",
|
||||
crate_name: "libc",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libmemchr",
|
||||
crate_name: "memchr",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libminiz_oxide",
|
||||
crate_name: "miniz_oxide",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libobject",
|
||||
crate_name: "object",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libpanic_unwind",
|
||||
crate_name: "panic_unwind",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "librustc_demangle",
|
||||
crate_name: "rustc_demangle",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "librustc_std_workspace_alloc",
|
||||
crate_name: "rustc_std_workspace_alloc",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "librustc_std_workspace_core",
|
||||
crate_name: "rustc_std_workspace_core",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library_rlib {
|
||||
name: "libstd_detect",
|
||||
crate_name: "std_detect",
|
||||
enabled:true,
|
||||
srcs: ["foo.rs"],
|
||||
no_stdlibs: true,
|
||||
product_available: true,
|
||||
host_supported: true,
|
||||
vendor_available: true,
|
||||
vendor_ramdisk_available: true,
|
||||
recovery_available: true,
|
||||
native_coverage: false,
|
||||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
rust_library {
|
||||
name: "libstd",
|
||||
crate_name: "std",
|
||||
|
@ -420,25 +113,6 @@ func GatherRequiredDepsForTest() string {
|
|||
sysroot: true,
|
||||
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
|
||||
min_sdk_version: "29",
|
||||
rlibs: [
|
||||
"libaddr2line",
|
||||
"libadler",
|
||||
"liballoc",
|
||||
"libcfg_if",
|
||||
"libcompiler_builtins",
|
||||
"libcore",
|
||||
"libgimli",
|
||||
"libhashbrown",
|
||||
"liblibc",
|
||||
"libmemchr",
|
||||
"libminiz_oxide",
|
||||
"libobject",
|
||||
"libpanic_unwind",
|
||||
"librustc_demangle",
|
||||
"librustc_std_workspace_alloc",
|
||||
"librustc_std_workspace_core",
|
||||
"libstd_detect",
|
||||
],
|
||||
}
|
||||
rust_library {
|
||||
name: "libtest",
|
||||
|
|
|
@ -1051,7 +1051,7 @@ func TestVendorSnapshotUse(t *testing.T) {
|
|||
ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
|
||||
|
||||
// libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
|
||||
libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").RuleParams.Command
|
||||
libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustLink").Args["linkFlags"]
|
||||
for _, input := range [][]string{
|
||||
[]string{sharedVariant, "libvndk.vndk.30.arm64"},
|
||||
[]string{staticVariant, "libvendor.vendor_static.30.arm64"},
|
||||
|
@ -1119,7 +1119,7 @@ func TestVendorSnapshotUse(t *testing.T) {
|
|||
t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName)
|
||||
}
|
||||
|
||||
binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").RuleParams.Command
|
||||
binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustLink").Args["linkFlags"]
|
||||
libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
|
||||
if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
|
||||
t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
|
||||
|
|
Loading…
Reference in a new issue