החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
מודולים בינאריים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אפשר ליצור קובצי Rust בינאריים באמצעות סוג המודול rust_binary
. לדוגמה:
rust_binary {
name: "hello_rust",
srcs: ["src/hello_rust.rs"],
}
באופן דומה, אפשר להשתמש ב-rust_binary_host
כדי לספק מודול למארח בלבד.
מאפיינים בולטים של rust_binary
בנוסף למאפיינים המשותפים החשובים, המאפיינים הבאים חשובים או שהתנהגות שלהם ייחודית לסוג המודול rust_binary
:
- static_executable: יצירת קובץ הבינארי הזה כקובץ בינארי סטטי, והמשמעות היא ש-
prefer_rlib
הוא true
. אפשר ליצור קובצי הפעלה סטטיים לחלוטין רק ליעדי bionic. ביעדים שאינם ביוניים, המשמעות היא רק ש-prefer_rlib
הוא true
, אבל עדיין מתבצע קישור דינמי בין libc
ל-libdl
.
- prefer_rlib: שינוי הקישור
rustlibs
כך שייבחר קישור rlib
כברירת מחדל לטירגוט למכשירים, וקישור libstd
כ-rlib
בטירגוט למכשירים. חשוב לזכור שזו ברירת המחדל של יעדים מארחים, ואין לה השפעה עליהם.
קישור
כברירת מחדל, מודולים של rust_binary
שמטרגטים מכשירים מקושרים תמיד באופן דינמי ל-libstd
, ותמיד ניתנת להם עדיפות על פני ספריות dylib
ליחסי התלות שמפורטים ב-rustlibs
, אלא אם הערך של prefer_rlib
הוא true
. אם אתם צריכים קובצי בינארי סטטיים לחלוטין, תוכלו לעיין במאפיין static_executable
.
מודולים מארחים תמיד מקושרים באופן סטטי ל-libstd
, ועל ברירת המחדל הם מעדיפים ספריות rlib
ליחסי התלות שמפורטים ב-rustlibs
.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[null,null,["עדכון אחרון: 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`."]]