2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
라이브러리 모듈
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Rust 라이브러리 모듈에는 두 가지 유형이 있습니다. 하나는 Rust 라이브러리를 생성하고, 다른 하나는 C 호환 라이브러리를 생성합니다. 빌드 시스템 용도로는 특수 유형의 라이브러리로 Rust 프로시저 매크로(proc-macros
)를 사용할 수 있습니다.
rust_library
rust_library
모듈은 다른 Rust 모듈에서 사용할 Rust 라이브러리를 생성합니다.
Rust 라이브러리에는 _host
변형 외에도 사용 가능한 링크를 제어하는 모듈 유형이 있습니다.
Rust 라이브러리 모듈 유형 |
정의 |
rust_library |
두 가지 라이브러리 변형(rlib 및 dylib )을 모두 제공합니다. 이 유형은 모듈이 rustlibs 속성 아래에 종속 항목으로 나열된 경우 모듈이 올바르게 작동하도록 하므로 AOSP에서는 Rust 라이브러리용으로 이 모듈 유형을 권장합니다. |
rust_library_rlib |
Rust 라이브러리의 rlib 변형만 제공합니다. rlib 변형만 제공하는 모듈은 rustlibs 속성과의 작동이 보장되지 않습니다. |
rust_library_dylib |
Rust 라이브러리의 dylib 변형만 제공합니다. dylib 변형만 제공하는 모듈은 rustlibs 속성과의 작동이 보장되지 않습니다. |
rust_ffi
rust_ffi
모듈은 CC 모듈과의 상호 운용을 위한 C 호환 라이브러리를 생성합니다.
Rust FFI 라이브러리에는 _host
변형 외에도 아래 표에 나와 있는 것처럼 사용 가능한 링크를 제어하는 모듈 유형이 있습니다.
Rust FFI 라이브러리 모듈 유형 |
정의 |
rust_ffi |
두 가지 C 라이브러리 변형(정적 및 공유)을 모두 제공합니다. |
rust_ffi_shared |
C 공유 라이브러리 변형만 제공합니다. |
rust_ffi_static |
C 정적 라이브러리 변형만 제공합니다. |
C에서 Rust를 호출하기 위해 rust_ffi
를 사용하는 기본적인 예는 Android Rust 패턴 페이지를 참고하세요.
고급 사용법에 관한 자세한 내용은 공식 Rust 도움말을 참고하세요.
rust_proc_macro
Rust 프로시저 매크로(proc-macros)는 컴파일러가 소스 코드를 변환하거나 새로운 속성을 제공하도록 확장하는 데 유용합니다. 자세한 내용은 공식 Rust 도움말의 프로시저 매크로 페이지를 참고하세요.
빌드 시스템 용도로는 rust_proc_macro
모듈이 rust_library
모듈과 비슷하게 작동합니다. rust_proc_macros
에 종속된 모듈의 경우 proc_macros
속성에 모듈 이름을 추가합니다.
proc_macros
는 컴파일러 플러그인이므로 반드시 호스트를 타겟팅하며, 기기에서 실행되는 어떤 코드도 생성하지 않습니다.
주목할 만한 Rust 라이브러리 속성
모든 모듈에 적용되는 주요 공통 속성 외에도 아래 표에 정의된 속성이 있습니다. 이들은 Rust 라이브러리 모듈에서 특히 중요한 속성이거나 rust_library
모듈 유형의 고유한 동작을 나타내는 속성입니다.
Rust 라이브러리 속성 |
정의 |
stem / name |
stem 속성은 출력 라이브러리 파일 이름을 제어합니다. 이 속성을 사용하지 않을 경우 기본값은 name 입니다.
Rust 컴파일러는 라이브러리 파일 이름에 특정 요구사항을 적용하며, 그 결과 빌드 시스템은 컴파일 문제를 방지하기 위해 다음과 같은 요구사항을 적용합니다.
출력 파일 이름은 lib<crate_name><suffix> 형식을 따라야 합니다.
(crate_name 속성에 종속 항목이 있습니다.) |
crate_name |
라이브러리를 생성하는 모든 모듈의 필수 속성입니다. 또한 출력 파일 이름과도 관계가 있습니다. (stem 정의를 참고하세요.) |
export_include_dirs |
rust_ffi 모듈의 경우 이 속성은 상대적인 포함 경로를 나타내는 문자열로 구성된 목록을 정의합니다. 경로는 종속된 cc 모듈이 사용할 수 있는 헤더를 포함합니다. |
rust_library 또는 rust_ffi의 링크
기기를 타게팅하는 Rust 라이브러리는 기본적으로 항상 libstd
에 동적으로 링크됩니다. 반면에 호스트 모듈은 항상 libstd
에 정적으로 링크됩니다.
rustlibs
종속 항목에 사용되는 링크는 루트 모듈 링크 설정에 종속됩니다. (예를 들어, prefer_rlib: true
를 포함하는 rust_binary
는 rustlibs
를 rlibs
로서 링크하는 Rust 라이브러리를 사용합니다.)
동적 Rust 라이브러리를 사용하지 않는 루트 종속 항목 모듈(예: 정적 실행 파일)을 생성할 수 있도록, rlibs
는 동적 및 정적 libstd
링크 변형을 모두 제공합니다. Soong에 의해 자동으로 올바른 변형이 링크됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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(UTC)"],[],[],null,["# Library modules\n\nThere are two types of Rust library modules, one that produces Rust libraries and\none that produces C-compatible libraries. Additionally, for build system\npurposes you can consider Rust procedural macros (`proc-macros`) as a special\ntype of library.\n\n### rust_library\n\nThe `rust_library` module produces Rust libraries for use by other Rust modules.\n\nIn addition to the `_host` variants, Rust libraries have module types that control\nthe available linkage.\n\n| Rust Library Module Type | Definition |\n|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **rust_library** | Provides both library variants, `rlib` and `dylib`. AOSP recommends this module type for Rust libraries, as it allows modules to work correctly when listed as a dependency under the `rustlibs` property |\n| **rust_library_rlib** | Provides only the `rlib` variant of a Rust library; modules providing only `rlib` variants can't be guaranteed to work with the `rustlibs` property. |\n| **rust_library_dylib** | Provides only the `dylib` variant of a Rust library; modules providing only `dylib` variants can't be guaranteed to work with the `rustlibs` property. |\n\n### rust_ffi\n\nThe `rust_ffi` module produces C-compatible libraries to interop with CC modules.\n\nIn addition to the `_host` variants, Rust FFI libraries have module types that\ncontrol the available linkage, shown in the following table.\n\n| Rust FFI Library Module Type | Definition |\n|------------------------------|------------------------------------------------------|\n| **rust_ffi** | Provides both C library variants: static and shared. |\n| **rust_ffi_shared** | Provides only the C shared library variant. |\n| **rust_ffi_static** | Provides only the C static library variant. |\n\nFor a basic example of using `rust_ffi` for calling Rust from C, see the\n[Android Rust Patterns](/docs/setup/build/rust/building-rust-modules/android-rust-patterns) page.\n\nFor information on more advanced usage, visit the [official Rust documentation](https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c).\n\n### rust_proc_macro\n\nRust procedural macros (proc-macros) can be useful for extending the compiler to\nperform source code transformations or providing new attributes. More information\ncan be found on these in the [Procedural Macros](https://doc.rust-lang.org/reference/procedural-macros.html)\npage of the official Rust documentation.\n\nFor the purposes of the build system, the `rust_proc_macro` module works similarly\nto the `rust_library` modules. For modules that depend on `rust_proc_macros`,\nadd the module name to the `proc_macros` property.\n\nAs `proc_macros` are compiler plugins, they necessarily target the host and don't\nproduce any code that would run on a device.\n\nNotable Rust library properties\n-------------------------------\n\nThe properties defined in the table below are in addition to the [Important common properties](/docs/setup/build/rust/building-rust-modules/android-rust-modules#important-common-properties)\nthat apply to all modules. These are either particularly important to Rust\nlibrary modules, or exhibit unique behavior specific to the `rust_library` module type.\n\n| Rust Library Properties | Definition |\n|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **stem / name** | The `stem` property controls the output library filename, which otherwise defaults to `name`. The Rust compiler imposes certain requirements on library filenames, and as a result the build system enforces these requirements to avoid compilation issues. The output filename must conform to the format `lib\u003ccrate_name\u003e\u003csuffix\u003e`. (There's a dependency here on the [`crate_name`](/docs/setup/build/rust/building-rust-modules/android-rust-modules#crate-name) property). |\n| **crate_name** | This is a required property for library-producing modules; it additionally has a relationship to the output filename. (See the [`stem`](/docs/setup/build/rust/building-rust-modules/android-rust-modules#stem) definition.) |\n| **export_include_dirs** | For `rust_ffi` modules, this property defines a list of strings representing relative include paths: paths which contain headers that dependent `cc` modules can use. |\n\nLinkage of rust_library or rust_ffi\n-----------------------------------\n\nBy default, Rust library modules targeting devices are always linked dynamically\nagainst `libstd`. Host modules, however, are always linked statically\nagainst `libstd`.\n\nThe linkage used for `rustlibs` dependencies depends on the root module's\nlinkage preferences. (For example, a `rust_binary` with `prefer_rlib: true` will\nuse Rust library variants that link `rustlibs` as `rlibs`.)\n\nTo allow production of root dependency modules that don't rely on any dynamic\nrust libraries (such as static executables), `rlibs` provides both dynamic and\nstatic `libstd` linkage variants. The correct variant is automatically linked by\nSoong."]]