diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/afdo.go | 2 | ||||
-rw-r--r-- | rust/bindgen.go | 60 | ||||
-rw-r--r-- | rust/bindgen_test.go | 45 | ||||
-rw-r--r-- | rust/config/global.go | 2 | ||||
-rw-r--r-- | rust/doc.go | 2 | ||||
-rw-r--r-- | rust/library.go | 2 | ||||
-rw-r--r-- | rust/project_json.go | 2 | ||||
-rw-r--r-- | rust/rust.go | 2 | ||||
-rw-r--r-- | rust/sanitize.go | 2 |
9 files changed, 101 insertions, 18 deletions
diff --git a/rust/afdo.go b/rust/afdo.go index 6116c5e21..6bd4bae1a 100644 --- a/rust/afdo.go +++ b/rust/afdo.go @@ -39,7 +39,7 @@ func (afdo *afdo) addDep(ctx BaseModuleContext, actx android.BottomUpMutatorCont return } - if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { + if mod, ok := ctx.Module().(*Module); ok && mod.Enabled(ctx) { fdoProfileName, err := actx.DeviceConfig().AfdoProfile(actx.ModuleName()) if err != nil { ctx.ModuleErrorf("%s", err.Error()) diff --git a/rust/bindgen.go b/rust/bindgen.go index eaed1b9d4..427775351 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -102,8 +102,17 @@ type BindgenProperties struct { // "my_bindgen [flags] wrapper_header.h -o [output_path] -- [clang flags]" Custom_bindgen string - // flag to indicate if bindgen should handle `static inline` functions (default is false) - Handle_static_inline bool + // flag to indicate if bindgen should handle `static inline` functions (default is false). + // If true, Static_inline_library must be set. + Handle_static_inline *bool + + // module name of the corresponding cc_library_static which includes the static_inline wrapper + // generated functions from bindgen. Must be used together with handle_static_inline. + // + // If there are no static inline functions provided through the header file, + // then bindgen (as of 0.69.2) will silently fail to output a .c file, and + // the cc_library_static depending on this module will fail compilation. + Static_inline_library *string } type bindgenDecorator struct { @@ -159,6 +168,18 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr var cflags []string var implicits android.Paths + var implicitOutputs android.WritablePaths + var validations android.Paths + + if Bool(b.Properties.Handle_static_inline) && b.Properties.Static_inline_library == nil { + ctx.PropertyErrorf("handle_static_inline", + "requires declaring static_inline_library to the corresponding cc_library module that includes the generated C source from bindgen.") + } + + if b.Properties.Static_inline_library != nil && !Bool(b.Properties.Handle_static_inline) { + ctx.PropertyErrorf("static_inline_library", + "requires declaring handle_static_inline.") + } implicits = append(implicits, deps.depGeneratedHeaders...) @@ -235,8 +256,11 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr bindgenFlags := defaultBindgenFlags bindgenFlags = append(bindgenFlags, esc(b.Properties.Bindgen_flags)...) - if b.Properties.Handle_static_inline { - bindgenFlags = append(bindgenFlags, "--experimental --wrap-static-fns") + if Bool(b.Properties.Handle_static_inline) { + outputStaticFnsFile := android.PathForModuleOut(ctx, b.BaseSourceProvider.getStem(ctx)+".c") + implicitOutputs = append(implicitOutputs, outputStaticFnsFile) + validations = append(validations, outputStaticFnsFile) + bindgenFlags = append(bindgenFlags, []string{"--experimental", "--wrap-static-fns", "--wrap-static-fns-path=" + outputStaticFnsFile.String()}...) } // cat reads from stdin if its command line is empty, @@ -285,11 +309,13 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr } ctx.Build(pctx, android.BuildParams{ - Rule: bindgen, - Description: strings.Join([]string{cmdDesc, wrapperFile.Path().Rel()}, " "), - Output: outputFile, - Input: wrapperFile.Path(), - Implicits: implicits, + Rule: bindgen, + Description: strings.Join([]string{cmdDesc, wrapperFile.Path().Rel()}, " "), + Output: outputFile, + Input: wrapperFile.Path(), + Implicits: implicits, + ImplicitOutputs: implicitOutputs, + Validations: validations, Args: map[string]string{ "cmd": cmd, "flags": strings.Join(bindgenFlags, " "), @@ -299,6 +325,14 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr }) b.BaseSourceProvider.OutputFiles = android.Paths{outputFile} + + // Append any additional implicit outputs after the entry point source. + // We append any generated .c file here so it can picked up by cc_library_static modules. + // Those CC modules need to be sure not to pass any included .rs files to Clang. + // We don't have to worry about the additional .c files for Rust modules as only the entry point + // is passed to rustc. + b.BaseSourceProvider.OutputFiles = append(b.BaseSourceProvider.OutputFiles, implicitOutputs.Paths()...) + return outputFile } @@ -350,6 +384,14 @@ func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps { deps = muslDeps(ctx, deps, false) } + if !ctx.RustModule().Source() && b.Properties.Static_inline_library != nil { + // This is not the source variant, so add the static inline library as a dependency. + // + // This is necessary to avoid a circular dependency between the source variant and the + // dependent cc module. + deps.StaticLibs = append(deps.StaticLibs, String(b.Properties.Static_inline_library)) + } + deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs...) deps.StaticLibs = append(deps.StaticLibs, b.ClangProperties.Static_libs...) deps.HeaderLibs = append(deps.HeaderLibs, b.ClangProperties.Header_libs...) diff --git a/rust/bindgen_test.go b/rust/bindgen_test.go index 11cfe4e88..2b7362f08 100644 --- a/rust/bindgen_test.go +++ b/rust/bindgen_test.go @@ -228,7 +228,6 @@ func TestBindgenFlagFile(t *testing.T) { // we may be able to check libbinder.RuleParams.Command to see if it contains $(cat /dev/null flag_file.txt) } - func TestBindgenHandleStaticInlining(t *testing.T) { ctx := testRust(t, ` rust_bindgen { @@ -237,7 +236,14 @@ func TestBindgenHandleStaticInlining(t *testing.T) { crate_name: "bindgen", stem: "libbindgen", source_stem: "bindings", - handle_static_inline: true + handle_static_inline: true, + static_inline_library: "libbindgen_staticfns" + } + + cc_library_static { + name: "libbindgen_staticfns", + srcs: [":libbindgen"], + include_dirs: ["src/"], } `) libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs") @@ -245,4 +251,39 @@ func TestBindgenHandleStaticInlining(t *testing.T) { if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns") { t.Errorf("missing flag to handle static inlining in rust_bindgen rule: flags %#v", libbindgen.Args["flags"]) } + + if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns-path") { + t.Errorf("missing flag to define path for static inlining C source from bindgen (--wrap-static-fns-path): flags %#v", libbindgen.Args["flags"]) + } + +} + +func TestBindgenStaticInlineProperties(t *testing.T) { + // Make sure handle_static_inline without static_inline_library generates an error + testRustError(t, "requires declaring static_inline_library to the corresponding cc_library module that includes the generated C source from bindgen", ` + rust_bindgen { + name: "libbindgen", + wrapper_src: "src/any.h", + crate_name: "bindgen", + stem: "libbindgen", + source_stem: "bindings", + handle_static_inline: true + } + `) + testRustError(t, "requires declaring handle_static_inline", ` + rust_bindgen { + name: "libbindgen", + wrapper_src: "src/any.h", + crate_name: "bindgen", + stem: "libbindgen", + source_stem: "bindings", + static_inline_library: "libbindgen_staticfns" + } + + cc_library_static { + name: "libbindgen_staticfns", + srcs: [":libbindgen"], + include_dirs: ["src/"], + } + `) } diff --git a/rust/config/global.go b/rust/config/global.go index 03333b80c..e83e23aa5 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -24,7 +24,7 @@ import ( var ( pctx = android.NewPackageContext("android/soong/rust/config") - RustDefaultVersion = "1.77.1" + RustDefaultVersion = "1.77.1.p1" RustDefaultBase = "prebuilts/rust/" DefaultEdition = "2021" Stdlibs = []string{ diff --git a/rust/doc.go b/rust/doc.go index 6970d7979..fe205233d 100644 --- a/rust/doc.go +++ b/rust/doc.go @@ -38,7 +38,7 @@ func (n *rustdocSingleton) GenerateBuildActions(ctx android.SingletonContext) { FlagWithArg("-D ", docDir.String()) ctx.VisitAllModules(func(module android.Module) { - if !module.Enabled() { + if !module.Enabled(ctx) { return } diff --git a/rust/library.go b/rust/library.go index 6be4917bf..f58a54fcc 100644 --- a/rust/library.go +++ b/rust/library.go @@ -713,7 +713,7 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { if sourceVariant { sv := modules[0] for _, v := range modules[1:] { - if !v.Enabled() { + if !v.Enabled(mctx) { continue } mctx.AddInterVariantDependency(sourceDepTag, v, sv) diff --git a/rust/project_json.go b/rust/project_json.go index 05fc09b3a..24dcc89f1 100644 --- a/rust/project_json.go +++ b/rust/project_json.go @@ -119,7 +119,7 @@ func isModuleSupported(ctx android.SingletonContext, module android.Module) (*Mo if !ok { return nil, false } - if !rModule.Enabled() { + if !rModule.Enabled(ctx) { return nil, false } return rModule, true diff --git a/rust/rust.go b/rust/rust.go index c2b61515c..de049f77f 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -1697,7 +1697,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { } func BeginMutator(ctx android.BottomUpMutatorContext) { - if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { + if mod, ok := ctx.Module().(*Module); ok && mod.Enabled(ctx) { mod.beginMutator(ctx) } } diff --git a/rust/sanitize.go b/rust/sanitize.go index bfd397155..c086880ed 100644 --- a/rust/sanitize.go +++ b/rust/sanitize.go @@ -258,7 +258,7 @@ func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps { func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { if mod, ok := mctx.Module().(*Module); ok && mod.sanitize != nil { - if !mod.Enabled() { + if !mod.Enabled(mctx) { return } |