Merge "Add bp2build converter for rust_ffi_static" into main
This commit is contained in:
commit
052f882a04
4 changed files with 118 additions and 3 deletions
|
@ -89,6 +89,7 @@ bootstrap_go_package {
|
||||||
"python_library_conversion_test.go",
|
"python_library_conversion_test.go",
|
||||||
"python_test_conversion_test.go",
|
"python_test_conversion_test.go",
|
||||||
"rust_binary_conversion_test.go",
|
"rust_binary_conversion_test.go",
|
||||||
|
"rust_ffi_conversion_test.go",
|
||||||
"rust_library_conversion_test.go",
|
"rust_library_conversion_test.go",
|
||||||
"rust_proc_macro_conversion_test.go",
|
"rust_proc_macro_conversion_test.go",
|
||||||
"rust_protobuf_conversion_test.go",
|
"rust_protobuf_conversion_test.go",
|
||||||
|
|
78
bp2build/rust_ffi_conversion_test.go
Normal file
78
bp2build/rust_ffi_conversion_test.go
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/rust"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runRustFfiTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||||
|
t.Helper()
|
||||||
|
RunBp2BuildTestCase(t, registerRustFfiModuleTypes, tc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerRustFfiModuleTypes(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterModuleType("rust_ffi_static", rust.RustFFIStaticFactory)
|
||||||
|
ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRustFfiStatic(t *testing.T) {
|
||||||
|
runRustFfiTestCase(t, Bp2buildTestCase{
|
||||||
|
Dir: "external/rust/crates/foo",
|
||||||
|
Blueprint: "",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"external/rust/crates/foo/src/lib.rs": "",
|
||||||
|
"external/rust/crates/foo/src/helper.rs": "",
|
||||||
|
"external/rust/crates/foo/Android.bp": `
|
||||||
|
rust_ffi_static {
|
||||||
|
name: "libfoo",
|
||||||
|
crate_name: "foo",
|
||||||
|
host_supported: true,
|
||||||
|
srcs: ["src/lib.rs"],
|
||||||
|
edition: "2015",
|
||||||
|
include_dirs: [
|
||||||
|
"include",
|
||||||
|
],
|
||||||
|
rustlibs: ["libbar"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
"external/rust/crates/bar/Android.bp": `
|
||||||
|
rust_library {
|
||||||
|
name: "libbar",
|
||||||
|
crate_name: "bar",
|
||||||
|
host_supported: true,
|
||||||
|
srcs: ["src/lib.rs"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTargetNoRestrictions("rust_ffi_static", "libfoo", AttrNameToString{
|
||||||
|
"crate_name": `"foo"`,
|
||||||
|
"deps": `["//external/rust/crates/bar:libbar"]`,
|
||||||
|
"srcs": `[
|
||||||
|
"src/helper.rs",
|
||||||
|
"src/lib.rs",
|
||||||
|
]`,
|
||||||
|
"edition": `"2015"`,
|
||||||
|
"export_includes": `["include"]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -801,6 +801,10 @@ func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
type rustLibraryAttributes struct {
|
type rustLibraryAttributes struct {
|
||||||
|
commonLibraryAttrs
|
||||||
|
}
|
||||||
|
|
||||||
|
type commonLibraryAttrs struct {
|
||||||
Srcs bazel.LabelListAttribute
|
Srcs bazel.LabelListAttribute
|
||||||
Compile_data bazel.LabelListAttribute
|
Compile_data bazel.LabelListAttribute
|
||||||
Crate_name bazel.StringAttribute
|
Crate_name bazel.StringAttribute
|
||||||
|
@ -811,7 +815,7 @@ type rustLibraryAttributes struct {
|
||||||
Proc_macro_deps bazel.LabelListAttribute
|
Proc_macro_deps bazel.LabelListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
func commonLibraryAttrsBp2build(ctx android.Bp2buildMutatorContext, m *Module) *commonLibraryAttrs {
|
||||||
lib := m.compiler.(*libraryDecorator)
|
lib := m.compiler.(*libraryDecorator)
|
||||||
|
|
||||||
srcs, compileData := srcsAndCompileDataAttrs(ctx, *lib.baseCompiler)
|
srcs, compileData := srcsAndCompileDataAttrs(ctx, *lib.baseCompiler)
|
||||||
|
@ -835,7 +839,7 @@ func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||||
rustcFLags = append(rustcFLags, fmt.Sprintf("--cfg=%s", cfg))
|
rustcFLags = append(rustcFLags, fmt.Sprintf("--cfg=%s", cfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs := &rustLibraryAttributes{
|
return &commonLibraryAttrs{
|
||||||
Srcs: bazel.MakeLabelListAttribute(
|
Srcs: bazel.MakeLabelListAttribute(
|
||||||
srcs,
|
srcs,
|
||||||
),
|
),
|
||||||
|
@ -865,6 +869,9 @@ func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{
|
bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: "rust_library",
|
Rule_class: "rust_library",
|
||||||
|
@ -873,7 +880,7 @@ func libraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||||
android.CommonAttributes{
|
android.CommonAttributes{
|
||||||
Name: m.Name(),
|
Name: m.Name(),
|
||||||
},
|
},
|
||||||
attrs,
|
commonLibraryAttrsBp2build(ctx, m),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -946,3 +953,30 @@ func cargoBuildScriptBp2build(ctx android.Bp2buildMutatorContext, m *Module) *st
|
||||||
|
|
||||||
return &name
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -1891,6 +1891,8 @@ func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||||
binaryBp2build(ctx, m)
|
binaryBp2build(ctx, m)
|
||||||
} else if ctx.ModuleType() == "rust_protobuf_host" || ctx.ModuleType() == "rust_protobuf" {
|
} else if ctx.ModuleType() == "rust_protobuf_host" || ctx.ModuleType() == "rust_protobuf" {
|
||||||
protoLibraryBp2build(ctx, m)
|
protoLibraryBp2build(ctx, m)
|
||||||
|
} else if ctx.ModuleType() == "rust_ffi_static" {
|
||||||
|
ffiStaticBp2build(ctx, m)
|
||||||
} else {
|
} else {
|
||||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue