Google reveals more about integrating Rust into Android

Google reveals more about integrating Rust into Android

Since 2019, the Android team has been working on introducing the Rust programming language to AOSP (Android Open Source Project) as a memory-safe alternative to platform native code development. Recently, Google further elaborated on the integration of Rust into AOSP in a blog post.

[[399571]]

The blog content points out that, like any large project, introducing a new language requires careful consideration. For Android, an important aspect is to evaluate how to best integrate Rust into Android's build system. According to the Android team, there are many challenges in integrating Rust into large projects; for example, abandoning Cargo and using the Rust compiler rustc directly may risk isolating the organization from the broader Rust community.

The team also said that when crates developed for Android can benefit the Rust community, they hope to release them as independent crates. They believe that Rust's success in Android depends on minimizing the divide between Android and the entire Rust community, and hope that the Rust community can benefit from Android's participation.

Rust provides Cargo as the default build system and package manager, which collects dependencies and calls rustc (Rust compiler) to build the target crate (Rust package). In Android, Soong replaces this role and calls rustc directly. The reasons are:

  • C language dependencies in Cargo are handled independently, and Soong already provides a related mechanism;
  • Calling the compiler directly through Soong provides more stability and control that Android needs to support a variety of build configurations;
  • Independent builds are very important for creating reproducible builds on Android;
  • Incremental builds are important to maintaining engineering productivity.

"Using the Rust compiler directly allows us to avoid these issues and is consistent with how we compile all other code in AOSP," said Ivan Lozano from the Android team. "It provides the most control over the build process and simplifies integration with Android's existing build system. However, because Cargo usage is so ingrained in the Rust crate ecosystem, avoiding Cargo poses some challenges and affects many other build system decisions."

In addition, as to why proc_macros is supported instead of build.rs scripts, the team explained that this is because build.rs code is written as one-time code, while proc_macros defines reusable functions in the compiler, which may be more useful to the Rust community. And proc_macros is usually better maintained and has more upstream reviews, which makes it easier to handle and enter the sandbox during the code review process.

The Android team also revealed that they plan to add documentation on how to define and use Rust modules in Soong to source.android.com in the near future. They hope that Android's support for Rust will continue to grow along with the Rust ecosystem, and hope to continue to participate in discussions about how to integrate Rust into existing build systems.

This article is reproduced from OSCHINA

Title of this article: Google reveals more about integrating Rust into Android

This article address: https://www.oschina.net/news/141612/integrating-rust-into-android-open

<<:  WeChat will stop opening the App technical service for Mini Programs after May 19

>>:  APP infringement continues despite repeated bans? The Ministry of Industry and Information Technology strikes hard again

Recommend

​What's on your mind but you can't remember it? Sorry, I'm "TOT"

You are chatting with your friends and suddenly y...

Domestic companies fined for infringing BMW trademark rights

According to a recent report by Shanghai Daily, t...

iOS source code: Chart library developed in Swift

Functional classification: Other Supported platfo...

What is the focus of brand marketing in 2021?

With the disappearance of traffic dividends, the ...

In just 4 steps, you can quickly create heartfelt social advertising ideas!

Today I will analyze a social advertisement in Mo...

Definition, advantages and disadvantages of CPA advertising

Definition of CPA Advertising The CPA (Cost Per A...

Analysis of common problems in bidding promotion!

In bidding promotion , we often encounter some co...