2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、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 ターゲットに対してのみ生成できます。非 Bionic ターゲットの場合、これは prefer_rlib
が true
であることを示すだけですが、その場合も libc
と libdl
を動的にリンクします。
- prefer_rlib:
rustlibs
リンクを変更して、デバイス ターゲットに対してデフォルトで rlib
リンクを選択し、libstd
をデバイス ターゲットの rlib
としてリンクします。これはホスト ターゲットのデフォルトの動作であり、ホスト ターゲットには影響しません。
リンク
デフォルトでは、デバイスをターゲットとする rust_binary
モジュールは常に libstd
に対して動的にリンクされます。デフォルトでは、prefer_rlib
が true
の場合を除き、rustlibs
に挙げられる依存関係の dylib
ライブラリが優先されます。完全に静的なバイナリが必要な場合は、static_executable
プロパティをご覧ください。
ホスト モジュールは常に libstd
に対して静的にリンクされ、デフォルトでは、rustlibs
に挙げられている依存関係の rlib
ライブラリが優先されます。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-04-04 UTC。
[null,null,["最終更新日 2025-04-04 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`."]]