| commit | 79001ce73b281a6681130ce3cc08f8c14b74cc5d | [log] [tgz] |
|---|---|---|
| author | Jeff Vander Stoep <jeffv@google.com> | Mon Jun 16 08:36:50 2025 +0000 |
| committer | Jeff Vander Stoep <jeffv@google.com> | Mon Jun 16 10:21:27 2025 +0000 |
| tree | 217cb5f856a4897058d302c9f69f3d0d83a1377d | |
| parent | 99f22b749571ff60f5e573cf31880a62ac838f98 [diff] |
Add a memory safe alternative to libz This crate can be used directly from C and C++. This change includes a patch including two commits from upstream, squashed here because they cannot be cleanly cherry-picked because they span two subcrates, one of which is not included in Android. The first commit includes the header files in a subcrate not included in Android, the second commit moves them into the libz-rs-sys crate which we use in Android. This includes: https://github.com/trifectatechfoundation/zlib-rs/pull/385 - include `zlib.h` and `zconf.h` - move .h files to the `libz-rs-sys` crate Bug: 420420630 Test: atest Test: Move some targets from libz to libz_rs_ffi, build and run tests locally. Change-Id: Ifd72e4a460c640466d990ba4765b6c2b6e926aeb
This repository contains Rust crates imported from crates.io for use by the Android platform.
The files in this repository are managed by a tool, which you can run from this directory:
./crate_tool help
Most of the files here should not be edited manually, and pre-upload checks will catch and prevent such changes.
Do not edit Android.bp files directly. Instead, edit cargo_embargo.json and run ./crate_tool regenerate <crate name>.
Refer to the cargo_embargo documentation for more information.
Do not use external_updater. Use crate_tool as follows:
This will print every newer version of every crate:
./crate_tool updatable-crates
To check all newer versions of a crate for potential problems:
./crate_tool analyze-updates <crate name>
To update a crate to a specified version:
./crate_tool update <crate name> <version>
This does not do any repo or git operations, so if the update is successful, you will need to run repo start, git commit, repo upload, etc.
Several problems can occur when updating a crate:
patches/ directory.cargo_embargo may fail, requiring edits to cargo_embargo.jsonThe update command does not try to build the Android tree, but a recommended local test before repo upload is to build everything under external/rust:
source build/envsetup.sh lunch aosp_husky-trunk_staging-eng cd external/rust mm
Instead of running ./crate_tool update <crate name> <version>, you can edit pseudo_crate/Cargo.toml directly and run ./crate_tool regenerate <crate name>. This can be useful when pairs of crates need to be updated in lockstep. This can happen, for example, when a crate has an associated proc_macro crate. So to update foo and foo_derive together, edit the versions of both in pseudo_crate/Cargo.toml, then run:
./crate_tool regenerate foo foo_derive
If you don't have a specific crate you need to update, but want to help keep the crate repository up-to-date, the crate tool can suggest crate updates that seem likely to succeed:
./crate_tool suggest-updates
You should avoid creating patches, if possible. Every patch file is an ongoing operational burden that makes it more difficult to keep our crates up-to-date.
If a patch is absolutely necessary, you should, if possible, send a pull request to the upstream crate, so we can eliminate the Android patch in the future, when upgrading.
To create a patch for crate “foo”, edit the files directly. Then do:
git diff --relative=crates/foo -- crates/foo/<file1> crates/foo/<file2> > patches/<name>.patch`
If you stage or commit the change and the patch, you should see no new changes when you run “regenerate”.
The source code for crate_tool is here.
The basic principle of the tool is that every crate directory in crates/ must be exactly reproducible by an automatic process from a known set of inputs:
METADATA, TEST_MAPPING, and MODULE_LICENSE_* files.patches/ directory.cargo_embargo.json, which is used to generate Android.bp.Therefore, what ./crate_tool regenerate <crate name> does is:
cargo vendorMETADATA, TEST_MAPPING, etc.Android.bp by running cargo_embargo.The pre-upload check does exactly the same thing, but without the final step. Instead of replacing the directory contents, it checks that what it generated from scratch matches the actual crate directory contents.
Crate update are also built on top of regenerate. What ./crate_tool update <crate name> <version> does is:
cargo remove <crate_name>cargo add <crate_name>@=<version>./crate_tool regenerate <crate name>