Merge changes from topic "rust-sysroot"
* changes: Enable x86_64 device support Build Rust Device Sysroots in Soong
This commit is contained in:
@@ -16,7 +16,6 @@ package rust
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/rust/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -91,12 +90,6 @@ func (binary *binaryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Fla
|
|||||||
func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps = binary.baseCompiler.compilerDeps(ctx, deps)
|
deps = binary.baseCompiler.compilerDeps(ctx, deps)
|
||||||
|
|
||||||
if binary.preferDynamic() || len(deps.Dylibs) > 0 {
|
|
||||||
for _, stdlib := range config.Stdlibs {
|
|
||||||
deps.Dylibs = append(deps.Dylibs, stdlib+"_"+ctx.toolchain().RustTriple())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.toolchain().Bionic() {
|
if ctx.toolchain().Bionic() {
|
||||||
deps = binary.baseCompiler.bionicDeps(ctx, deps)
|
deps = binary.baseCompiler.bionicDeps(ctx, deps)
|
||||||
deps.CrtBegin = "crtbegin_dynamic"
|
deps.CrtBegin = "crtbegin_dynamic"
|
||||||
|
@@ -102,6 +102,12 @@ func transformSrctoCrate(ctx android.ModuleContext, main android.Path, deps Path
|
|||||||
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
rustcFlags = append(rustcFlags, "--target="+targetTriple)
|
||||||
linkFlags = append(linkFlags, "-target "+targetTriple)
|
linkFlags = append(linkFlags, "-target "+targetTriple)
|
||||||
}
|
}
|
||||||
|
// TODO once we have static libraries in the host prebuilt .bp, this
|
||||||
|
// should be unconditionally added.
|
||||||
|
if !ctx.Host() {
|
||||||
|
// If we're on a device build, do not use an implicit sysroot
|
||||||
|
rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
|
||||||
|
}
|
||||||
// Collect linker flags
|
// Collect linker flags
|
||||||
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
|
||||||
linkFlags = append(linkFlags, flags.LinkFlags...)
|
linkFlags = append(linkFlags, flags.LinkFlags...)
|
||||||
|
@@ -32,6 +32,10 @@ func getDenyWarnings(compiler *baseCompiler) bool {
|
|||||||
return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
|
return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (compiler *baseCompiler) setNoStdlibs() {
|
||||||
|
compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
|
||||||
|
}
|
||||||
|
|
||||||
func NewBaseCompiler(dir, dir64 string) *baseCompiler {
|
func NewBaseCompiler(dir, dir64 string) *baseCompiler {
|
||||||
return &baseCompiler{
|
return &baseCompiler{
|
||||||
Properties: BaseCompilerProperties{},
|
Properties: BaseCompilerProperties{},
|
||||||
@@ -82,6 +86,9 @@ type BaseCompilerProperties struct {
|
|||||||
|
|
||||||
// install to a subdirectory of the default install path for the module
|
// install to a subdirectory of the default install path for the module
|
||||||
Relative_install_path *string `android:"arch_variant"`
|
Relative_install_path *string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// whether to suppress inclusion of standard crates - defaults to false
|
||||||
|
No_stdlibs *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseCompiler struct {
|
type baseCompiler struct {
|
||||||
@@ -161,6 +168,23 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
|
||||||
deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
|
deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
|
||||||
|
|
||||||
|
if !Bool(compiler.Properties.No_stdlibs) {
|
||||||
|
for _, stdlib := range config.Stdlibs {
|
||||||
|
// If we're building for host, use the compiler's stdlibs
|
||||||
|
if ctx.Host() {
|
||||||
|
stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This check is technically insufficient - on the host, where
|
||||||
|
// static linking is the default, if one of our static
|
||||||
|
// dependencies uses a dynamic library, we need to dynamically
|
||||||
|
// link the stdlib as well.
|
||||||
|
if (len(deps.Dylibs) > 0) || (!ctx.Host()) {
|
||||||
|
// Dynamically linked stdlib
|
||||||
|
deps.Dylibs = append(deps.Dylibs, stdlib)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ var (
|
|||||||
"external/rust",
|
"external/rust",
|
||||||
"external/crosvm",
|
"external/crosvm",
|
||||||
"external/adhd",
|
"external/adhd",
|
||||||
|
"prebuilts/rust",
|
||||||
}
|
}
|
||||||
|
|
||||||
RustModuleTypes = []string{
|
RustModuleTypes = []string{
|
||||||
|
@@ -41,8 +41,8 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
|
registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
|
||||||
|
|
||||||
pctx.StaticVariable("x86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " "))
|
pctx.StaticVariable("X86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " "))
|
||||||
pctx.StaticVariable("x86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " "))
|
pctx.StaticVariable("X86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " "))
|
||||||
|
|
||||||
for variant, rustFlags := range x86_64ArchVariantRustFlags {
|
for variant, rustFlags := range x86_64ArchVariantRustFlags {
|
||||||
pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
|
pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
|
||||||
@@ -57,11 +57,11 @@ type toolchainX86_64 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolchainX86_64) RustTriple() string {
|
func (t *toolchainX86_64) RustTriple() string {
|
||||||
return "x86_64-unknown-linux-gnu"
|
return "x86_64-linux-android"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolchainX86_64) ToolchainLinkFlags() string {
|
func (t *toolchainX86_64) ToolchainLinkFlags() string {
|
||||||
return "${config.x86_64ToolchainLinkFlags}"
|
return "${config.DeviceGlobalLinkFlags} ${config.X86_64ToolchainLinkFlags}"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolchainX86_64) ToolchainRustFlags() string {
|
func (t *toolchainX86_64) ToolchainRustFlags() string {
|
||||||
@@ -69,15 +69,21 @@ func (t *toolchainX86_64) ToolchainRustFlags() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolchainX86_64) RustFlags() string {
|
func (t *toolchainX86_64) RustFlags() string {
|
||||||
return "${config.x86_64ToolchainRustFlags}"
|
return "${config.X86_64ToolchainRustFlags}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *toolchainX86_64) Supported() bool {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func x86_64ToolchainFactory(arch android.Arch) Toolchain {
|
func x86_64ToolchainFactory(arch android.Arch) Toolchain {
|
||||||
toolchainRustFlags := []string{
|
toolchainRustFlags := []string{
|
||||||
"${config.x86_64ToolchainRustFlags}",
|
"${config.X86_64ToolchainRustFlags}",
|
||||||
"${config.X86_64" + arch.ArchVariant + "VariantRustFlags}",
|
"${config.X86_64" + arch.ArchVariant + "VariantRustFlags}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
|
||||||
|
|
||||||
for _, feature := range arch.ArchFeatures {
|
for _, feature := range arch.ArchFeatures {
|
||||||
toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...)
|
toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...)
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ func PrebuiltDylibFactory() android.Module {
|
|||||||
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
||||||
module, library := NewRustLibrary(hod)
|
module, library := NewRustLibrary(hod)
|
||||||
library.BuildOnlyDylib()
|
library.BuildOnlyDylib()
|
||||||
|
library.setNoStdlibs()
|
||||||
library.setDylib()
|
library.setDylib()
|
||||||
prebuilt := &prebuiltLibraryDecorator{
|
prebuilt := &prebuiltLibraryDecorator{
|
||||||
libraryDecorator: library,
|
libraryDecorator: library,
|
||||||
|
@@ -199,6 +199,25 @@ func TestProcMacroDeviceDeps(t *testing.T) {
|
|||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
crate_name: "bar",
|
crate_name: "bar",
|
||||||
}
|
}
|
||||||
|
// Make a dummy libstd to let resolution go through
|
||||||
|
rust_library_dylib {
|
||||||
|
name: "libstd",
|
||||||
|
crate_name: "std",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
no_stdlibs: true,
|
||||||
|
}
|
||||||
|
rust_library_dylib {
|
||||||
|
name: "libterm",
|
||||||
|
crate_name: "term",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
no_stdlibs: true,
|
||||||
|
}
|
||||||
|
rust_library_dylib {
|
||||||
|
name: "libtest",
|
||||||
|
crate_name: "test",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
no_stdlibs: true,
|
||||||
|
}
|
||||||
rust_proc_macro {
|
rust_proc_macro {
|
||||||
name: "libpm",
|
name: "libpm",
|
||||||
rlibs: ["libbar"],
|
rlibs: ["libbar"],
|
||||||
@@ -217,3 +236,18 @@ func TestProcMacroDeviceDeps(t *testing.T) {
|
|||||||
t.Errorf("Proc_macro is not using host variant of dependent modules.")
|
t.Errorf("Proc_macro is not using host variant of dependent modules.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that no_stdlibs suppresses dependencies on rust standard libraries
|
||||||
|
func TestNoStdlibs(t *testing.T) {
|
||||||
|
ctx := testRust(t, `
|
||||||
|
rust_binary {
|
||||||
|
name: "fizz-buzz",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
no_stdlibs: true,
|
||||||
|
}`)
|
||||||
|
module := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a_core").Module().(*Module)
|
||||||
|
|
||||||
|
if android.InList("libstd", module.Properties.AndroidMkDylibs) {
|
||||||
|
t.Errorf("no_stdlibs did not suppress dependency on libstd")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user