Loading rust/builder.go +3 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,9 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path, rustcFlags = append(rustcFlags, flags.GlobalRustFlags...) rustcFlags = append(rustcFlags, flags.RustFlags...) rustcFlags = append(rustcFlags, "--crate-type="+crate_type) if crate_name != "" { rustcFlags = append(rustcFlags, "--crate-name="+crate_name) } if targetTriple != "" { rustcFlags = append(rustcFlags, "--target="+targetTriple) linkFlags = append(linkFlags, "-target "+targetTriple) Loading rust/compiler.go +4 −2 Original line number Diff line number Diff line Loading @@ -18,9 +18,10 @@ import ( "fmt" "path/filepath" "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/rust/config" "github.com/google/blueprint/proptools" ) func getEdition(compiler *baseCompiler) string { Loading Loading @@ -64,7 +65,7 @@ type BaseCompilerProperties struct { // list of C static library dependencies Static_libs []string `android:"arch_variant"` // crate name (defaults to module name); if library, this must be the expected extern crate name // crate name, required for libraries. This must be the expected extern crate name used in source Crate_name string `android:"arch_variant"` // list of features to enable for this crate Loading Loading @@ -207,6 +208,7 @@ func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string return stem } func (compiler *baseCompiler) relativeInstallPath() string { return String(compiler.Properties.Relative_install_path) } Loading rust/library.go +30 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ package rust import ( "regexp" "strings" "android/soong/android" ) Loading Loading @@ -354,6 +357,33 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa return outputFile } func (library *libraryDecorator) getStem(ctx ModuleContext) string { stem := library.baseCompiler.getStemWithoutSuffix(ctx) validateLibraryStem(ctx, stem, library.crateName()) return stem + String(library.baseCompiler.Properties.Suffix) } var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+") func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) { if crate_name == "" { ctx.PropertyErrorf("crate_name", "crate_name must be defined.") } // crate_names are used for the library output file, and rustc expects these // to be alphanumeric with underscores allowed. if validCrateName.MatchString(crate_name) { ctx.PropertyErrorf("crate_name", "library crate_names must be alphanumeric with underscores allowed") } // Libraries are expected to begin with "lib" followed by the crate_name if !strings.HasPrefix(filename, "lib"+crate_name) { ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>") } } func LibraryMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.compiler != nil { switch library := m.compiler.(type) { Loading rust/library_test.go +37 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,40 @@ func TestDylibPreferDynamic(t *testing.T) { t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) } } func TestValidateLibraryStem(t *testing.T) { testRustError(t, "crate_name must be defined.", ` rust_library_host { name: "libfoo", srcs: ["foo.rs"], }`) testRustError(t, "library crate_names must be alphanumeric with underscores allowed", ` rust_library_host { name: "libfoo-bar", srcs: ["foo.rs"], crate_name: "foo-bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", srcs: ["foo.rs"], crate_name: "foo_bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", stem: "libfoo", srcs: ["foo.rs"], crate_name: "foo_bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", stem: "foo_bar", srcs: ["foo.rs"], crate_name: "foo_bar" }`) } rust/proc_macro.go +7 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,10 @@ func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, dep TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) return outputFile } func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string { stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx) validateLibraryStem(ctx, stem, procMacro.crateName()) return stem + String(procMacro.baseCompiler.Properties.Suffix) } Loading
rust/builder.go +3 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,9 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path, rustcFlags = append(rustcFlags, flags.GlobalRustFlags...) rustcFlags = append(rustcFlags, flags.RustFlags...) rustcFlags = append(rustcFlags, "--crate-type="+crate_type) if crate_name != "" { rustcFlags = append(rustcFlags, "--crate-name="+crate_name) } if targetTriple != "" { rustcFlags = append(rustcFlags, "--target="+targetTriple) linkFlags = append(linkFlags, "-target "+targetTriple) Loading
rust/compiler.go +4 −2 Original line number Diff line number Diff line Loading @@ -18,9 +18,10 @@ import ( "fmt" "path/filepath" "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/rust/config" "github.com/google/blueprint/proptools" ) func getEdition(compiler *baseCompiler) string { Loading Loading @@ -64,7 +65,7 @@ type BaseCompilerProperties struct { // list of C static library dependencies Static_libs []string `android:"arch_variant"` // crate name (defaults to module name); if library, this must be the expected extern crate name // crate name, required for libraries. This must be the expected extern crate name used in source Crate_name string `android:"arch_variant"` // list of features to enable for this crate Loading Loading @@ -207,6 +208,7 @@ func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string return stem } func (compiler *baseCompiler) relativeInstallPath() string { return String(compiler.Properties.Relative_install_path) } Loading
rust/library.go +30 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ package rust import ( "regexp" "strings" "android/soong/android" ) Loading Loading @@ -354,6 +357,33 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa return outputFile } func (library *libraryDecorator) getStem(ctx ModuleContext) string { stem := library.baseCompiler.getStemWithoutSuffix(ctx) validateLibraryStem(ctx, stem, library.crateName()) return stem + String(library.baseCompiler.Properties.Suffix) } var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+") func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) { if crate_name == "" { ctx.PropertyErrorf("crate_name", "crate_name must be defined.") } // crate_names are used for the library output file, and rustc expects these // to be alphanumeric with underscores allowed. if validCrateName.MatchString(crate_name) { ctx.PropertyErrorf("crate_name", "library crate_names must be alphanumeric with underscores allowed") } // Libraries are expected to begin with "lib" followed by the crate_name if !strings.HasPrefix(filename, "lib"+crate_name) { ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>") } } func LibraryMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*Module); ok && m.compiler != nil { switch library := m.compiler.(type) { Loading
rust/library_test.go +37 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,40 @@ func TestDylibPreferDynamic(t *testing.T) { t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) } } func TestValidateLibraryStem(t *testing.T) { testRustError(t, "crate_name must be defined.", ` rust_library_host { name: "libfoo", srcs: ["foo.rs"], }`) testRustError(t, "library crate_names must be alphanumeric with underscores allowed", ` rust_library_host { name: "libfoo-bar", srcs: ["foo.rs"], crate_name: "foo-bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", srcs: ["foo.rs"], crate_name: "foo_bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", stem: "libfoo", srcs: ["foo.rs"], crate_name: "foo_bar" }`) testRustError(t, "Invalid name or stem property; library filenames must start with lib<crate_name>", ` rust_library_host { name: "foobar", stem: "foo_bar", srcs: ["foo.rs"], crate_name: "foo_bar" }`) }
rust/proc_macro.go +7 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,10 @@ func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, dep TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs) return outputFile } func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string { stem := procMacro.baseCompiler.getStemWithoutSuffix(ctx) validateLibraryStem(ctx, stem, procMacro.crateName()) return stem + String(procMacro.baseCompiler.Properties.Suffix) }