Loading rust/binary.go +7 −2 Original line number Diff line number Diff line Loading @@ -138,9 +138,14 @@ func (binary *binaryDecorator) preferRlib() bool { func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput { fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix() srcPath, _ := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs) outputFile := android.PathForModuleOut(ctx, fileName) ret := buildOutput{outputFile: outputFile} var crateRootPath android.Path if binary.baseCompiler.Properties.Crate_root == nil { crateRootPath, _ = srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs) } else { crateRootPath = android.PathForModuleSrc(ctx, *binary.baseCompiler.Properties.Crate_root) } flags.RustFlags = append(flags.RustFlags, deps.depFlags...) flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...) Loading @@ -155,7 +160,7 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path } binary.baseCompiler.unstrippedOutputFile = outputFile ret.kytheFile = TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrcToBinary(ctx, crateRootPath, deps, flags, outputFile).kytheFile return ret } Loading rust/compiler.go +11 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,15 @@ type BaseCompilerProperties struct { // If no source file is defined, a single generated source module can be defined to be used as the main source. Srcs []string `android:"path,arch_variant"` // Entry point that is passed to rustc to begin the compilation. E.g. main.rs or lib.rs. // When this property is set, // * sandboxing is enabled for this module, and // * the srcs attribute is interpreted as a list of all source files potentially // used in compilation, including the entrypoint, and // * compile_data can be used to add additional files used in compilation that // not directly used as source files. Crate_root *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 Loading Loading @@ -511,6 +520,8 @@ func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, andr ctx.PropertyErrorf("srcs", "only a single generated source module can be defined without a main source file.") } // TODO: b/297264540 - once all modules are sandboxed, we need to select the proper // entry point file from Srcs rather than taking the first one paths := android.PathsForModuleSrc(ctx, srcs) return paths[srcIndex], paths[1:] } rust/library.go +10 −8 Original line number Diff line number Diff line Loading @@ -489,7 +489,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa var outputFile android.ModuleOutPath var ret buildOutput var fileName string srcPath := library.srcPath(ctx, deps) crateRootPath := library.crateRootPath(ctx, deps) if library.sourceProvider != nil { deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...) Loading Loading @@ -536,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, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.dylib() { ret.kytheFile = TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.static() { ret.kytheFile = TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.shared() { ret.kytheFile = TransformSrctoShared(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile } if library.rlib() || library.dylib() { Loading Loading @@ -585,13 +585,15 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa return ret } func (library *libraryDecorator) srcPath(ctx ModuleContext, _ PathDeps) android.Path { func (library *libraryDecorator) crateRootPath(ctx ModuleContext, _ PathDeps) android.Path { if library.sourceProvider != nil { // Assume the first source from the source provider is the library entry point. return library.sourceProvider.Srcs()[0] } else { } else if library.baseCompiler.Properties.Crate_root == nil { path, _ := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs) return path } else { return android.PathForModuleSrc(ctx, *library.baseCompiler.Properties.Crate_root) } } Loading @@ -606,7 +608,7 @@ func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags, return android.OptionalPath{} } return android.OptionalPathForPath(Rustdoc(ctx, library.srcPath(ctx, deps), return android.OptionalPathForPath(Rustdoc(ctx, library.crateRootPath(ctx, deps), deps, flags)) } Loading rust/toolchain_library.go +13 −6 Original line number Diff line number Diff line Loading @@ -41,8 +41,10 @@ func init() { } type toolchainLibraryProperties struct { // path to the toolchain source, relative to the top of the toolchain source Toolchain_src *string `android:"arch_variant"` // path to the toolchain crate root, relative to the top of the toolchain source Toolchain_crate_root *string `android:"arch_variant"` // path to the rest of the toolchain srcs, relative to the top of the toolchain source Toolchain_srcs []string `android:"arch_variant"` } type toolchainLibraryDecorator struct { Loading Loading @@ -88,15 +90,20 @@ func initToolchainLibrary(module *Module, library *libraryDecorator) android.Mod func rustSetToolchainSource(ctx android.LoadHookContext) { if toolchainLib, ok := ctx.Module().(*Module).compiler.(*toolchainLibraryDecorator); ok { prefix := filepath.Join(config.HostPrebuiltTag(ctx.Config()), GetRustPrebuiltVersion(ctx)) newSrcs := []string{path.Join(prefix, android.String(toolchainLib.Properties.Toolchain_src))} versionedCrateRoot := path.Join(prefix, android.String(toolchainLib.Properties.Toolchain_crate_root)) versionedSrcs := make([]string, len(toolchainLib.Properties.Toolchain_srcs)) for i, src := range toolchainLib.Properties.Toolchain_srcs { versionedSrcs[i] = path.Join(prefix, src) } type props struct { Crate_root *string Srcs []string } p := &props{} p.Srcs = newSrcs p.Crate_root = &versionedCrateRoot p.Srcs = versionedSrcs ctx.AppendProperties(p) } else { ctx.ModuleErrorf("Called rustSetToolchainSource on a non-Rust Module.") } Loading Loading
rust/binary.go +7 −2 Original line number Diff line number Diff line Loading @@ -138,9 +138,14 @@ func (binary *binaryDecorator) preferRlib() bool { func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput { fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix() srcPath, _ := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs) outputFile := android.PathForModuleOut(ctx, fileName) ret := buildOutput{outputFile: outputFile} var crateRootPath android.Path if binary.baseCompiler.Properties.Crate_root == nil { crateRootPath, _ = srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs) } else { crateRootPath = android.PathForModuleSrc(ctx, *binary.baseCompiler.Properties.Crate_root) } flags.RustFlags = append(flags.RustFlags, deps.depFlags...) flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...) Loading @@ -155,7 +160,7 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path } binary.baseCompiler.unstrippedOutputFile = outputFile ret.kytheFile = TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrcToBinary(ctx, crateRootPath, deps, flags, outputFile).kytheFile return ret } Loading
rust/compiler.go +11 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,15 @@ type BaseCompilerProperties struct { // If no source file is defined, a single generated source module can be defined to be used as the main source. Srcs []string `android:"path,arch_variant"` // Entry point that is passed to rustc to begin the compilation. E.g. main.rs or lib.rs. // When this property is set, // * sandboxing is enabled for this module, and // * the srcs attribute is interpreted as a list of all source files potentially // used in compilation, including the entrypoint, and // * compile_data can be used to add additional files used in compilation that // not directly used as source files. Crate_root *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 Loading Loading @@ -511,6 +520,8 @@ func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, andr ctx.PropertyErrorf("srcs", "only a single generated source module can be defined without a main source file.") } // TODO: b/297264540 - once all modules are sandboxed, we need to select the proper // entry point file from Srcs rather than taking the first one paths := android.PathsForModuleSrc(ctx, srcs) return paths[srcIndex], paths[1:] }
rust/library.go +10 −8 Original line number Diff line number Diff line Loading @@ -489,7 +489,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa var outputFile android.ModuleOutPath var ret buildOutput var fileName string srcPath := library.srcPath(ctx, deps) crateRootPath := library.crateRootPath(ctx, deps) if library.sourceProvider != nil { deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...) Loading Loading @@ -536,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, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.dylib() { ret.kytheFile = TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.static() { ret.kytheFile = TransformSrctoStatic(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile } else if library.shared() { ret.kytheFile = TransformSrctoShared(ctx, srcPath, deps, flags, outputFile).kytheFile ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile } if library.rlib() || library.dylib() { Loading Loading @@ -585,13 +585,15 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa return ret } func (library *libraryDecorator) srcPath(ctx ModuleContext, _ PathDeps) android.Path { func (library *libraryDecorator) crateRootPath(ctx ModuleContext, _ PathDeps) android.Path { if library.sourceProvider != nil { // Assume the first source from the source provider is the library entry point. return library.sourceProvider.Srcs()[0] } else { } else if library.baseCompiler.Properties.Crate_root == nil { path, _ := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs) return path } else { return android.PathForModuleSrc(ctx, *library.baseCompiler.Properties.Crate_root) } } Loading @@ -606,7 +608,7 @@ func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags, return android.OptionalPath{} } return android.OptionalPathForPath(Rustdoc(ctx, library.srcPath(ctx, deps), return android.OptionalPathForPath(Rustdoc(ctx, library.crateRootPath(ctx, deps), deps, flags)) } Loading
rust/toolchain_library.go +13 −6 Original line number Diff line number Diff line Loading @@ -41,8 +41,10 @@ func init() { } type toolchainLibraryProperties struct { // path to the toolchain source, relative to the top of the toolchain source Toolchain_src *string `android:"arch_variant"` // path to the toolchain crate root, relative to the top of the toolchain source Toolchain_crate_root *string `android:"arch_variant"` // path to the rest of the toolchain srcs, relative to the top of the toolchain source Toolchain_srcs []string `android:"arch_variant"` } type toolchainLibraryDecorator struct { Loading Loading @@ -88,15 +90,20 @@ func initToolchainLibrary(module *Module, library *libraryDecorator) android.Mod func rustSetToolchainSource(ctx android.LoadHookContext) { if toolchainLib, ok := ctx.Module().(*Module).compiler.(*toolchainLibraryDecorator); ok { prefix := filepath.Join(config.HostPrebuiltTag(ctx.Config()), GetRustPrebuiltVersion(ctx)) newSrcs := []string{path.Join(prefix, android.String(toolchainLib.Properties.Toolchain_src))} versionedCrateRoot := path.Join(prefix, android.String(toolchainLib.Properties.Toolchain_crate_root)) versionedSrcs := make([]string, len(toolchainLib.Properties.Toolchain_srcs)) for i, src := range toolchainLib.Properties.Toolchain_srcs { versionedSrcs[i] = path.Join(prefix, src) } type props struct { Crate_root *string Srcs []string } p := &props{} p.Srcs = newSrcs p.Crate_root = &versionedCrateRoot p.Srcs = versionedSrcs ctx.AppendProperties(p) } else { ctx.ModuleErrorf("Called rustSetToolchainSource on a non-Rust Module.") } Loading