اعتبارًا من 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 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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`."]]