Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Mô-đun nhị phân
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn có thể tạo tệp nhị phân Rust bằng cách sử dụng loại mô-đun rust_binary
; ví dụ:
rust_binary {
name: "hello_rust",
srcs: ["src/hello_rust.rs"],
}
Tương tự, bạn có thể sử dụng rust_binary_host
để cung cấp mô-đun chỉ dành cho máy chủ lưu trữ.
Các thuộc tính rust_binary đáng chú ý
Ngoài Các thuộc tính chung quan trọng, các thuộc tính sau đây cũng quan trọng hoặc thể hiện hành vi riêng biệt dành riêng cho loại mô-đun rust_binary
:
- static_executable: Tạo tệp nhị phân này dưới dạng tệp nhị phân tĩnh và ngụ ý rằng
prefer_rlib
là true
. Bạn chỉ có thể tạo các tệp thực thi tĩnh hoàn toàn cho các mục tiêu bionic. Đối với các mục tiêu không phải là sinh học, điều này chỉ ngụ ý rằng prefer_rlib
là true
, nhưng vẫn liên kết động libc
và libdl
.
- prefer_rlib: Thay đổi mối liên kết
rustlibs
để chọn mối liên kết rlib
theo mặc định cho các mục tiêu thiết bị và liên kết libstd
dưới dạng rlib
trên các mục tiêu thiết bị. Xin lưu ý rằng đây là hành vi mặc định cho các mục tiêu lưu trữ và không ảnh hưởng đến các mục tiêu đó.
Liên kết
Theo mặc định, các mô-đun rust_binary
nhắm đến thiết bị luôn được liên kết động với libstd
và theo mặc định sẽ ưu tiên thư viện dylib
cho các phần phụ thuộc được liệt kê trong rustlibs
, trừ phi prefer_rlib
là true
. Nếu bạn cần tệp nhị phân tĩnh hoàn toàn, hãy xem thuộc tính static_executable
.
Các mô-đun lưu trữ luôn được liên kết tĩnh với libstd
và theo mặc định, ưu tiên thư viện rlib
cho các phần phụ thuộc được liệt kê trong rustlibs
.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Binary modules\n\nRust binaries can be produced using the `rust_binary` module type; for example: \n\n rust_binary {\n name: \"hello_rust\",\n srcs: [\"src/hello_rust.rs\"],\n }\n\nSimilarly, you can use `rust_binary_host` to provide a host-only\nmodule.\n\nNotable rust_binary properties\n------------------------------\n\nIn addition to the [Important common properties](/docs/setup/build/rust/building-rust-modules/android-rust-modules#important-common-properties),\nthe following properties are also either important, or exhibit unique behavior\nspecific to the `rust_binary` module type:\n\n- **static_executable** : Builds this binary as a static binary, and implies `prefer_rlib` is `true`. Fully static executables can only be produced for bionic targets. For non-bionic targets, this implies only that `prefer_rlib` is `true`, but it still links `libc` and `libdl` dynamically.\n- **prefer_rlib** : Changes the `rustlibs` linkage to select the `rlib` linkage by default for device targets, and links `libstd` as an `rlib` on device targets. Note that this is the default behavior for host targets, and has no impact on them.\n\nLinkage\n-------\n\nBy default, `rust_binary` modules that are targeting devices are always linked\ndynamically against `libstd` and by default will prefer `dylib` libraries for\ndependencies listed in `rustlibs` unless `prefer_rlib` is `true`. If fully\nstatic binaries are required, see the `static_executable` property.\n\nHost modules are always linked statically against `libstd` and\nby default prefer `rlib` libraries for dependencies that are listed in\n`rustlibs`."]]