rustc, directly (see next section) may remove organizations from the wider Rust community. We share this same concern. When changes to imported third-party crates might be beneficial to the wider community, our goal is to upstream those changes. Likewise when crates developed for Android could benefit the wider Rust community, we hope to release them as independent crates. We believe that the success of Rust within Android is dependent on minimizing any divergence between Android and the Rust community at large, and hope that the Rust community will benefit from Android’s involvement. No nested build systems
Rust provides Cargo as the default takes this role instead in Android and calls rustc directly for several reasons:
- In Cargo, C dependencies are handled independently in an ad-hoc manner via build.rs scripts. Soong already provides a mechanism for building C libraries and defining them as dependencies, and Android carefully controls the compiler version and global compilation flags to ensure libraries are built a particular way. Relying on Cargo would introduce a second non-Soong mechanism for defining/building C libraries that would not be constrained by the carefully selected compilation controls implemented in Soong. This could also lead to multiple different versions of the same library, negatively impacting memory/disk usage.
- Calling compilers directly through Soong provides the stability and control Android requires for the variety of build configurations it supports (for example, specifying where target-specific dependencies are and which compilation flags to use). While it would technically be possible to achieve the necessary level of control over
rustcindirectly through Cargo, Soong would have no understanding of how theCargo.toml(the Cargo build file) would influence the commands Cargo emits torustc. Paired with the fact that Cargo evolves independently, this would severely restrict Soong’s ability to precisely control how build artifacts are created. - Builds which are self-contained and insensitive to the host configuration, known as hermetic builds, are necessary for Android to produce reproducible builds. Cargo, which relies on
build.rsscripts, doesn’t yet provide hermeticity guarantees. - Incremental builds are important to maintain engineering productivity; building Android takes a considerable amount of resources. Cargo was not designed for integration into existing build systems and does not expose its compilation units. Each Cargo invocation builds . This is too coarse for integration into Soong’s incremental build support, which expects smaller compilation units. This support is necessary to scale up Rust usage within Android.
Using the Rust compiler directly allows us to avoid these issues and is consistent with how we compile all other code in AOSP. It provides the most control over the build process and eases integration into Android’s existing build system. Unfortunately, avoiding it introduces several challenges and influences many other build system decisions because Cargo usage is so deeply ingrained in the Rust crate ecosystem.
No build.rs scripts
A
build.rsscript compiles to a Rust binary which Cargo builds and executes during a build to handle pre-build tasks, commonly setting up the build environment, or building libraries in other languages (for example C/C++). This is analogous to configure scripts used for other languages.Avoiding
build.rsscripts somewhat flows naturally from not relying on Cargo since supporting these would require replicating Cargo behavior and assumptions. Beyond this however, there are good reasons for AOSP to avoid build scripts as well:build.rsscripts can execute arbitrary code on the build host. From a security perspective, this introduces an additional burden when adding or updating third-party code as thebuild.rsscript needs careful scrutiny.- Third-party
build.rsscripts may not be hermetic or reproducible in for for crate-specific code.When the in a Soong . In other cases where Soong can provide the information without source generation, we may carry a modules.
Generated source as crates
Unlike C/C++ compilers,
rustconly accepts a single source file representing an entry point to a binary or library. It expects that the source tree is structured such that all required source files can be automatically discovered. This means that generated source either needs to be placed in the source tree or provided through an include directive in source:include!("/path/to/hello.rs");The Rust community depends on
build.rsscripts alongside assumptions about the Cargo build environment to which build.rs scripts are expected to place generated source code in. This source can then be included via:include!(concat!(env!("OUT_DIR"), "/hello.rs"));This presents a challenge for Soong as outputs for each module are placed in their own
out/directory checked-in throughout the tree and which needs to be maintained. Any boilerplate necessary to make the interactions between generated code and the surrounding crate. - Reduce pressure on memory and disk by dynamically liking commonly used generated sources.
As a result, all of Android’s Rust source generation module types produce code that can be compiled and used . The usual benefits of dynamic libraries are upgrades (whether for security or functionality) and decreased memory usage. Rust’s lack of a stable binary interface and usage of cross-crate information flow prevents upgrading libraries without upgrading all dependent code. Even when the same crate is used by two different programs on the system, it is unlikely to be provided by the same shared object while we to add support.
Current Status of Build Support
We support building all output types supported by
rustc(rlibs,dylibs,proc_macros,cdylibs,staticlibs, and executables). Rust modules can automatically request the appropriate crate linkage for a given dependency (rlibvsdylib). C and C++ modules can depend on Rustcdyliborstaticlibproducing modules the same way as they would for a C or C++ library.In addition to being able to build Rust code, Android’s build system also provides support for generated crates. First-class using for rust-analyzer into the build system so that any IDE which supports it can provide code completion and goto definitions for Android modules.
to provide performance metrics. In order to maintain a consistent style and level of code quality, a default set of
clippylints andrustclints are , with the HWASANrustcsupport on how to define and use Rust modules in Soong. We expect Android’s support for Rust to continue evolving alongside the Rust ecosystem and hope to continue to participate in discussions around how Rust can be integrated into existing build systems.Thank you to Matthew Maurer, Jeff Vander Stoep, Joel Galenson, Manish Goregaokar, and Tyler Mandry for their contributions to this post.
Notes
-
This can be mitigated to some extent with workspaces, but requires a very specific directory arrangement that AOSP does not conform to.
-
Since include! works by textual inclusion, it may reference values from the enclosing namespace, modify the namespace, or use constructs like #![foo]. These implicit interactions can be difficult to maintain. Macros should be preferred if interaction with the rest of the crate is truly required.
-
↗ Original-Artikel auf feedproxy.google.com lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf feedproxy.google.com.
Community-Analysen & Experten-Meinungen 0
Verwandte Story-Cluster & Quellen (Vektor-KI)
Ähnliche Beiträge
Auch interessante Nachrichten Integrating Rust Into the Android Open Source Project
Thematisch verwandte Begriffe: Integrating, Rust, Into, Android · 6 Treffer
Scaling Memory Safety: AI-Assisted Rewrites of C/C++ Dependencies to Rust
drakoarmy/datadome-rs: High-end Rust DataDome deobfuscator & solver with VM disassembly — all 3 challenge types (tags, interstitial, slider).
[webapps] Grav CMS 2.0.7 - RCE
Exploring the Future of Security with ChatGPT
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
SOCIAL SHARE CARD GENERATOR