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

How do you write copy that will inspire users to place orders after reading it?

Copywriting with sufficient promotional power wil...

3 ways to run a social network!

In 1960, Theodore Levitt published his famous art...

A complete guide to mobile DSP advertising in 10 major industries!

More and more industries are beginning to enter t...

The latest Android keep-alive implementation principle in 2020

Keep-alive implementation principle This article ...

Technology Post: How to apply AI natively to Android system

[51CTO.com Quick Translation] Compared to reading...

4 strategies for private domain marketing

In the era of "traffic thinking", we ar...

Madam, can you do some erotic art?

Have you seen these two emoticons recently? Color...

Advanced event planning: 4 steps to control event costs

An activity is generally divided into four parts ...

Fashion + AI: Can we create another wearable craze?

Recently, the wearable field has been in decline:...

Jack Ma is also optimistic! Will VR achieve a qualitative change in 2016?

[[161438]] At the end of October 2015, news came ...

Do you have unbearable stomach pain? Be careful! It may be...

I haven't had a bowel movement or passed gas ...

CES2015: Razer Forge TV Gaming Set-Top Box

Are you tired of the smartphones, watches and car...