diff options
Diffstat (limited to 'rust/library.go')
-rw-r--r-- | rust/library.go | 186 |
1 files changed, 0 insertions, 186 deletions
diff --git a/rust/library.go b/rust/library.go index c0ff741db..199ffbb4c 100644 --- a/rust/library.go +++ b/rust/library.go @@ -21,10 +21,7 @@ import ( "strings" "android/soong/android" - "android/soong/bazel" "android/soong/cc" - - "github.com/google/blueprint/proptools" ) var ( @@ -402,8 +399,6 @@ func (library *libraryDecorator) BuildOnlyShared() { func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { module := newModule(hod, android.MultilibBoth) - android.InitBazelModule(module) - library := &libraryDecorator{ MutatedProperties: LibraryMutatedProperties{ BuildDylib: false, @@ -801,184 +796,3 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext, // TODO(185577950): If support for generated headers is added, they need to be collected here as well. l.collectedSnapshotHeaders = ret } - -type rustLibraryAttributes struct { - commonLibraryAttrs -} - -type commonLibraryAttrs struct { - Srcs bazel.LabelListAttribute - Compile_data bazel.LabelListAttribute - Crate_name bazel.StringAttribute - Edition bazel.StringAttribute - Crate_features bazel.StringListAttribute - Deps bazel.LabelListAttribute - Rustc_flags bazel.StringListAttribute - Proc_macro_deps bazel.LabelListAttribute -} - -func commonLibraryAttrsBp2build(ctx android.Bp2buildMutatorContext, m *Module) *commonLibraryAttrs { - lib := m.compiler.(*libraryDecorator) - - srcs, compileData := srcsAndCompileDataAttrs(ctx, *lib.baseCompiler) - - deps := android.BazelLabelForModuleDeps(ctx, append( - lib.baseCompiler.Properties.Rustlibs, - lib.baseCompiler.Properties.Rlibs..., - )) - - cargoBuildScript := cargoBuildScriptBp2build(ctx, m) - if cargoBuildScript != nil { - deps.Add(&bazel.Label{ - Label: ":" + *cargoBuildScript, - }) - } - - procMacroDeps := android.BazelLabelForModuleDeps(ctx, lib.baseCompiler.Properties.Proc_macros) - - var rustcFLags []string - for _, cfg := range lib.baseCompiler.Properties.Cfgs { - rustcFLags = append(rustcFLags, fmt.Sprintf("--cfg=%s", cfg)) - } - - return &commonLibraryAttrs{ - Srcs: bazel.MakeLabelListAttribute( - srcs, - ), - Compile_data: bazel.MakeLabelListAttribute( - compileData, - ), - Crate_name: bazel.StringAttribute{ - Value: &lib.baseCompiler.Properties.Crate_name, - }, - Edition: bazel.StringAttribute{ - Value: lib.baseCompiler.Properties.Edition, - }, - Crate_features: bazel.StringListAttribute{ - Value: lib.baseCompiler.Properties.Features, - }, - Deps: bazel.MakeLabelListAttribute( - deps, - ), - Proc_macro_deps: bazel.MakeLabelListAttribute( - procMacroDeps, - ), - Rustc_flags: bazel.StringListAttribute{ - Value: append( - rustcFLags, - lib.baseCompiler.Properties.Flags..., - ), - }, - } - -} - -func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) { - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "rust_library", - Bzl_load_location: "@rules_rust//rust:defs.bzl", - }, - android.CommonAttributes{ - Name: m.Name(), - }, - commonLibraryAttrsBp2build(ctx, m), - ) -} - -type cargoBuildScriptAttributes struct { - Srcs bazel.LabelListAttribute - Edition bazel.StringAttribute - Version bazel.StringAttribute -} - -func cargoBuildScriptBp2build(ctx android.Bp2buildMutatorContext, m *Module) *string { - // Soong treats some crates like libprotobuf as special in that they have - // cargo build script ran to produce an out folder and check it into AOSP - // For example, https://cs.android.com/android/platform/superproject/main/+/main:external/rust/crates/protobuf/out/ - // is produced by cargo build script https://cs.android.com/android/platform/superproject/main/+/main:external/rust/crates/protobuf/build.rs - // The out folder is then fed into `rust_library` by a genrule - // https://cs.android.com/android/platform/superproject/main/+/main:external/rust/crates/protobuf/Android.bp;l=22 - // This allows Soong to decouple from cargo completely. - - // Soong decouples from cargo so that it has control over cc compilation. - // https://cs.android.com/android/platform/superproject/main/+/main:development/scripts/cargo2android.py;l=1033-1041;drc=8449944a50a0445a5ecaf9b7aed12608c81bf3f1 - // generates a `cc_library_static` module to have custom cc flags. - // Since bp2build will convert the cc modules to cc targets which include the cflags, - // Bazel does not need to have this optimization. - - // Performance-wise: rust_library -> cargo_build_script vs rust_library -> genrule (like Soong) - // don't have any major difference in build time in Bazel. So using cargo_build_script does not slow - // down the build. - - // The benefit of using `cargo_build_script` here is that it would take care of setting correct - // `OUT_DIR` for us - similar to what Soong does here - // https://cs.android.com/android/platform/superproject/main/+/main:build/soong/rust/builder.go;l=202-218;drc=f29ca58e88c5846bbe8955e5192135e5ab4f14a1 - - // TODO(b/297364081): cargo2android.py has logic for when generate/not cc_library_static and out directory - // bp2build might be able use the same logic for when to use `cargo_build_script`. - // For now, we're building libprotobuf_build_script as a one-off until we have a more principled solution - if m.Name() != "libprotobuf" { - return nil - } - - lib := m.compiler.(*libraryDecorator) - - name := m.Name() + "_build_script" - attrs := &cargoBuildScriptAttributes{ - Srcs: bazel.MakeLabelListAttribute( - android.BazelLabelForModuleSrc(ctx, []string{"build.rs"}), - ), - Edition: bazel.StringAttribute{ - Value: lib.baseCompiler.Properties.Edition, - }, - Version: bazel.StringAttribute{ - Value: lib.baseCompiler.Properties.Cargo_pkg_version, - }, - } - - // TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented - var restriction bazel.BoolAttribute - restriction.SetSelectValue(bazel.OsConfigurationAxis, "android", proptools.BoolPtr(false)) - - ctx.CreateBazelTargetModuleWithRestrictions( - bazel.BazelTargetModuleProperties{ - Rule_class: "cargo_build_script", - Bzl_load_location: "@rules_rust//cargo:cargo_build_script.bzl", - }, - android.CommonAttributes{ - Name: name, - }, - attrs, - restriction, - ) - - return &name -} - -type ffiStaticAttributes struct { - commonLibraryAttrs - Export_includes bazel.StringListAttribute -} - -func ffiStaticBp2build(ctx android.Bp2buildMutatorContext, m *Module) { - lib := m.compiler.(*libraryDecorator) - - attrs := &ffiStaticAttributes{ - Export_includes: bazel.StringListAttribute{ - Value: lib.Properties.Include_dirs, - }, - commonLibraryAttrs: *commonLibraryAttrsBp2build(ctx, m), - } - - ctx.CreateBazelTargetModule( - bazel.BazelTargetModuleProperties{ - Rule_class: "rust_ffi_static", - Bzl_load_location: "//build/bazel/rules/rust:rust_ffi_static.bzl", - }, - android.CommonAttributes{ - Name: m.Name(), - }, - attrs, - ) -} |