add rust_toolchain_rustc_prebuilt module type am: b45c844ce7 am: 28ef26653e am: e82a8a05fe

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2654319

Change-Id: I9995df5d7a6e0af2c255a113fa57992bdead1dc3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sam Delmerico
2023-09-08 02:10:25 +00:00
committed by Automerger Merge Worker
3 changed files with 50 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ package android
import "path/filepath" import "path/filepath"
func init() { func init() {
RegisterModuleType("prebuilt_build_tool", prebuiltBuildToolFactory) RegisterModuleType("prebuilt_build_tool", NewPrebuiltBuildTool)
} }
type prebuiltBuildToolProperties struct { type prebuiltBuildToolProperties struct {
@@ -101,10 +101,6 @@ var _ HostToolProvider = &prebuiltBuildTool{}
// prebuilt_build_tool is to declare prebuilts to be used during the build, particularly for use // prebuilt_build_tool is to declare prebuilts to be used during the build, particularly for use
// in genrules with the "tools" property. // in genrules with the "tools" property.
func prebuiltBuildToolFactory() Module {
return NewPrebuiltBuildTool()
}
func NewPrebuiltBuildTool() Module { func NewPrebuiltBuildTool() Module {
module := &prebuiltBuildTool{} module := &prebuiltBuildTool{}
module.AddProperties(&module.properties) module.AddProperties(&module.properties)

View File

@@ -35,6 +35,7 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
multitree.RegisterApiImportsModule(ctx) multitree.RegisterApiImportsModule(ctx)
ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool)
ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory) ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory)
ctx.RegisterModuleType("cc_object", ObjectFactory) ctx.RegisterModuleType("cc_object", ObjectFactory)
ctx.RegisterModuleType("cc_genrule", GenRuleFactory) ctx.RegisterModuleType("cc_genrule", GenRuleFactory)

View File

@@ -21,6 +21,8 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/rust/config" "android/soong/rust/config"
"github.com/google/blueprint/proptools"
) )
// This module is used to compile the rust toolchain libraries // This module is used to compile the rust toolchain libraries
@@ -33,6 +35,8 @@ func init() {
rustToolchainLibraryRlibFactory) rustToolchainLibraryRlibFactory)
android.RegisterModuleType("rust_toolchain_library_dylib", android.RegisterModuleType("rust_toolchain_library_dylib",
rustToolchainLibraryDylibFactory) rustToolchainLibraryDylibFactory)
android.RegisterModuleType("rust_toolchain_rustc_prebuilt",
rustToolchainRustcPrebuiltFactory)
} }
type toolchainLibraryProperties struct { type toolchainLibraryProperties struct {
@@ -101,3 +105,47 @@ func rustSetToolchainSource(ctx android.LoadHookContext) {
func GetRustPrebuiltVersion(ctx android.LoadHookContext) string { func GetRustPrebuiltVersion(ctx android.LoadHookContext) string {
return ctx.AConfig().GetenvWithDefault("RUST_PREBUILTS_VERSION", config.RustDefaultVersion) return ctx.AConfig().GetenvWithDefault("RUST_PREBUILTS_VERSION", config.RustDefaultVersion)
} }
type toolchainRustcPrebuiltProperties struct {
// path to rustc prebuilt, relative to the top of the toolchain source
Toolchain_prebuilt_src *string
// path to deps, relative to the top of the toolchain source
Toolchain_deps []string
// path to deps, relative to module directory
Deps []string
}
func rustToolchainRustcPrebuiltFactory() android.Module {
module := android.NewPrebuiltBuildTool()
module.AddProperties(&toolchainRustcPrebuiltProperties{})
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
var toolchainProps *toolchainRustcPrebuiltProperties
for _, p := range ctx.Module().GetProperties() {
toolchainProperties, ok := p.(*toolchainRustcPrebuiltProperties)
if ok {
toolchainProps = toolchainProperties
}
}
if toolchainProps.Toolchain_prebuilt_src == nil {
ctx.PropertyErrorf("toolchain_prebuilt_src", "must set path to rustc prebuilt")
}
prefix := "linux-x86/" + GetRustPrebuiltVersion(ctx)
deps := make([]string, 0, len(toolchainProps.Toolchain_deps)+len(toolchainProps.Deps))
for _, d := range toolchainProps.Toolchain_deps {
deps = append(deps, path.Join(prefix, d))
}
deps = append(deps, toolchainProps.Deps...)
props := struct {
Src *string
Deps []string
}{
Src: proptools.StringPtr(path.Join(prefix, *toolchainProps.Toolchain_prebuilt_src)),
Deps: deps,
}
ctx.AppendProperties(&props)
})
return module
}