summaryrefslogtreecommitdiff
path: root/rust/library.go
AgeCommit message (Collapse)Author
2025-02-19rust: Propagate MTO libs linked whole through dylibs. Ivan Lozano
Because dylibs don't export symbols of whole-archive staticlibs, we simulate this by propagating those static libs through to dependent modules. Similarly, we must do the same for rlibs from cc_* modules used to generate MTO staticlibs. Bug: 395915782 Test: New soong tests Test: m rust Change-Id: I83d6a08234af04af5039764f5a80f659b24aa132
2025-02-12Merge "rust:Add Rust support for made-to-order staticlibs" into main Ivan Lozano
2025-02-12rust:Add Rust support for made-to-order staticlibs Ivan Lozano
If a cc_library_static has a whole_static dependency against a rust_ffi_static module, we need to ensure that rust_* dependents of the cc_library_static don't just throw away the rlibs the cc_library_static module is intending to include whole (and does so by propagating them down to dependents to be included in the generated Rust staticlib). This reuses the plumbing we have in cc to generate a Rust staticlib from the propagated dependencies. Bug: 395915782 Test: m rust Change-Id: I413c8d2476e0b2a1c623581fdbfb5734a62ae455
2025-02-11Merge changes from topics "apex_transition_info", ↵ Colin Cross
"bcp_dependency_through_apex" into main * changes: Convert android.TransitionMutator to TransitionInfo Pass libraryToApex and apexNameToFragment mappings into CreateClasspathElements Convert apex transition tag to dependency on apex Add extra dependency from apex to bootclasspath fragments to modules Move prebuilt mutators earlier
2025-02-11Merge "rust: Rename flag providers for clarity" into main Ivan Lozano
2025-02-07Move prebuilt mutators earlier Colin Cross
Move the prebuilt mutators from postdeps to predeps mutators. This ensures that the decisions on whether the source or prebuilt will be used can be made earlier, which simplifies the apex and dexpreopt code, allowing it to directly depend on the correct module. This requires some mutators that previously ran before the prebuilt mutator and now run after the prebuilt mutator be aware of prebuilts. In particular, the cc.linkageTransitionMutator and rust.libraryTransitionMutator now have to manually disable prebuilts when they don't produce a static or shared variant that the source module produces, and some mutators have to ignore PrebuiltDepTag dependencies when propagating transitions. The apexTransitionMutator also needs to temporarily use an interface on the dependency tag to correctly resolve some dependencies that exist before the apex variation is created onto the correct variation. This will shortly be replaced with depending on the apex itself instead, and then walking the dependencies of the apex to find the necessary module. Bug: 372543712 Test: go test ./... Change-Id: If125ea981be87673bae3bd0a7e3b2c16c337e8f7
2025-02-05Merge "rust: Propagate static libs correctly" into main Ivan Lozano
2025-02-05rust: Rename flag providers for clarity Ivan Lozano
Rename the Rust flag and export info providers to make it more clear when workign with the Rust exporter vs the cc exporter. Also renames a test for additional clarity. Test: m blueprint_tests Change-Id: I652b55ef000a2cd00f47b1dbfe86713c33ae9d63
2025-02-05rust: Propagate static libs correctly Ivan Lozano
A dylib link is a final link, so we should not propagate staticlibs through them. Most of the time this made no difference, but this was breaking edge cases on coverage builds. This CL breaks apart linkObjects so we can more finely tune which dependencies we propagate and which we should not. rlibs should only propagate non-whole static librares, while rlibs and dylibs propagate whole static libs. Bug: 377932175 Test: m Test: New Soong tests Change-Id: Ib2ae3dcb7d775a57bd4b1715ec528f48cc0ca026
2025-02-03rust: Don't produce coverage variants for stublibs Ivan Lozano
Stubs don't have code by definition, so we shouldn't be producing coverage variants for them. Bug: 393556022 Test: m <cov stubs> # inidicates target no longer exists Change-Id: I82a2848075259b9f115b19c46019ada3d29bad41
2025-01-29Convert rust module-info.json to soong Cole Faust
This leads to idendical results as before, with the exception of the "required" field in module-info.json. Make has more complicated logic to fill out the required field than soong, and it leads to make-specific names such as ones suffixed with :32 and don't make sense in soong. I'm don't think there are critical users of that field though, so I'll try removing it. Everything else should be identical to the make-generated information though. Bug: 389720048 Test: diff'd module-info.json before and after this cl in soong+make mode Change-Id: I74aefe578287f07474c15e5f92a0c2780a679047
2025-01-28rust: Don't pass crt objects for stubs Ivan Lozano
We don't need to pass crt objects to generate stubs, and doing so results in missing symbol errors at link time. Bug: 203478530 Test: m <rust stubs_library> Change-Id: Id400ae2db2530f84cea3b0a5cda4d9841d7a6985
2025-01-10rust: Add stub support for rust_ffi modules Ivan Lozano
This adds stubs support for rust_ffi and rust_ffi_shared modules. Usage should match current cc usage. The stubs generator leveraged is the cc stubs generator. Bug: 203478530 Test: m blueprint_tests Change-Id: I043b9714a357cd5fe17c183ccdf86900f5172e0e
2025-01-10Refactor cc/rust to prep for Rust stubs Ivan Lozano
This CL largely handles this refactoring in preparation for Rust stubs support. Rust modules need to be able to communicate stubs information to cc, and certain bits of cc needs to be exported so rust can reuse them. A new VersionedLinkableInterface is added to capture most of the stubs-related interface definitions. Bug: 203478530 Test: m blueprint_tests Change-Id: I380225402fa85a3c39e7b18deb657054b3a52fbe
2025-01-07rust: Force all dependencies to be linked, used or not Matthew Maurer
`rustc` added an unstable feature that makes `--extern` do what we originally wanted - it links the provided library, *even* if the source code does not reference it. The primary use case for this is that it makes it possible for us to build dylibs out of `#![no_std]` crates without modifying the source, because we can pass in `--extern force:path/to/libstd.dylib.so`. Bug: 168927099 Test: m, TH Change-Id: Ibc3b75012d54b73e40ae609784cdc74e02e8f008
2024-12-17Merge "rust: Remove rust_ffi_rlibs, keep rust_ffi_static" into main Ivan Lozano
2024-12-17Merge "rust: Alias rust_ffi_rlib to rust_library_rlib" into main Maciej Żenczykowski
2024-12-16rust: Remove rust_ffi_rlibs, keep rust_ffi_static Ivan Lozano
rust_ffi_static and rust_ffi_rlibs both alias to rust_library_rlib now. We need to think about whether we need these aliases at all. There are no users of rust_ffi_rlibs at the moment as developers are continuing to declare rust_ffi_static modules. Let's remove this alias in the meantime at least to simplify things. Bug: 350633786 Bug: 383552450 Test: m blueprint_tests && m rust Change-Id: I6be895ddbffc5ac6303f2edc9ab20f7c20cd1591
2024-12-13rust: Alias rust_ffi_rlib to rust_library_rlib Ivan Lozano
With the new transition mutators, the distinctions between rust_ffi_rlib and rust_library_rlib are not necessary. This CL removes the remaining distinctions to allow an unusual use case where a rust_library and a rust_ffi_rlib would otherwise be created from the same source. This would allow defining a single rust_library_rlib that works for both rust modules and cc modules. One key change is that rust_ffi_rlibs only produced an rlib-std variant previously, and now produce dylib-std variants as well.This surfaced an issue where a libstd linkage mismatch would cause rustc to throw a consufing missing crate error. We instead add logic to catch this in Soong and provide a more useful error message. Bug: 383552450 Test: m rust Test: m blueprint_tests Change-Id: I611ca46934059735d06229952cfd8e0ab7050486
2024-12-13rust: Add version scripts and symbol exports Ivan Lozano
This allows Rust modules to define a version_script for shared library variants. This requires using a wrapper for the linker (clang++) to intercept the flags which rustc emits. This also adds the ability to export additional symbols in addition to those exported by rustc by default, e.g. whole_static_library symbols. Bug: 314309643 Test: New Soong tests pass. Test: m Test: m <simple version script module> Test: m <simple extra symbols module> Change-Id: I93c9552e5e1181df4663d194c4df4b7053553dd4
2024-11-05Verify that libraries in apexes don't link to implementations outside the apex Colin Cross
As part of removing some of the complexity in Soong around using stub vs. implementations for shared library dependencies a syntax will be added to Soong to allow explicitly selecting stubs vs. implementation. To avoid incorrect use, add a verification pass on apexes that ensure that all transitive implementation libraries used to link native libraries or binaries in the apex are themselves in the apex. Bug: 372543712 Test: TestApexVerifyNativeImplementationLibs Flag: EXEMPT host only Change-Id: I4aeaca00a359ce97e8f9efd2d8bffb8f9d2dc0df
2024-10-24Update DepSet references Colin Cross
Update all references to depset to use blueprint/depset, and to use DepSet instead of *DepSet. Bug: 375276086 Test: all soong tests pass Flag: EXEMPT refactor Change-Id: I59a7836d0975366ddc336225fb770ac7e6e0c8ea
2024-08-27Add a property to rust_ffi targets to exclude them from APEXes. Ashutosh Agarwal
This is a temporary measure until stubs are properly supported by rust_ffi targets. Bug: 361441210 Bug: 362509506 Change-Id: Ieabd4e3abf442de660f39ec6c5776f5832b25e14 Test: manual
2024-07-17Convert rust_libraries and rust_stdlinkage mutators to TransitionMutators Colin Cross
Replace rust.LibraryMutator and rust.LibstdMutator with TransitionMutators. Bug: 319288033 Flag: EXEMPT refactor Test: all soong tests pass Test: no change to build.ninja Change-Id: Ia24a582119d39889279d7b93bac9259685153619
2024-07-11Remove obsolete rust VariantIsStatic Colin Cross
Rust modules no longer have static variants after I2925f67f6dc9329dae3dcccafb8560900ac8a6fc, remove the VariantIsStatic field. Bug: 254469782 Test: m Test: m blueprint_tests Change-Id: Ic63412a27c3a09dec43c4a9064a3e1f4181147db
2024-06-26cc/rust: Alias ffi rlib variant for static_libs Ivan Lozano
Alias the rlib variant to "link: static". This allows declaring rust_ffi_rlib modules in static_libs. This effectively removes any distinction between rust_ffi_static and rust_ffi_rlib. Removing the functionality for building Rust staticlib modules will be cleaned up in a follow-on CL. This should have the effect of changing the default linkage for all rust modules in static_libs from linking individual staticlibs to building a single staticlib that includes all rust_ffi rlib dependencies. This removes the static_rlibs property, as we're now handling the choice dynamically. This also makes rlibs only propagate through cc_library_static modules if the rlib is included in whole_static_lib. This both mirrors the expected behavior of cc libraries and helps control which version of a crate ends up in the final link (e.g. libdoh_ffi vs libdoh_ffi_for_test). Bug: 254469782 Test: m Test: m blueprint_tests Change-Id: I2925f67f6dc9329dae3dcccafb8560900ac8a6fc
2024-05-22Convert some properties to Configurable properties Cole Faust
Focusing on the properties needed to remove soong config modules from packages/modules/Virtualization. - prebuilt_etc's src and srcs - filegroup's srcs and exclude_srcs - rust's cfgs Bug: 342006386 Test: m nothing --no-skip-soong-tests Change-Id: I6971da744a17955f98104948e6f9614776955782
2024-05-17Merge changes from topic "rust-made-to-order-staticlibs" into main Ivan Lozano
* changes: rust: made-to-order rust staticlibs rust: refactored transformSrctoCrate
2024-05-16rust: made-to-order rust staticlibs Ivan Lozano
Whenever any two Rust static libraries are included as static libraries anywhere in a CC dependency tree, we sometimes get duplicate symbol errors. To avoid this, we no longer directly link multiple rust static libs to CC modules. Instead, we build rust_ffi_rlib modules and produce the actual static library that gets linked against the CC module based on that CC module's full list of Rust rlib dependencies. This introduces a new static_rlibs property for cc modules to define the rust_ffi_rlib dependencies, which are then used to generate the module above. This CL is intended to deprecate rust_ffi_static. It leaves rust_ffi_static and rust_ffi static variants in place until the remaining rust_ffi_static declarations and uses can be removed. In the meantime, rust_ffi_static produces rust_ffi_rlib variants as well to make the transition easier. Bug: 254469782 Test: m # with no changes Test: m libapexsupport # with static_rlibs Test: m libunwindstack # with static_rlibs Test: m netsimd # with static_rlibs, no duplicate symbols Test: m blueprint_tests # New Soong tests Change-Id: I47e27ac967ef0cad46d398ebf59d8275929ae28a
2024-05-16rust: refactored transformSrctoCrate Ivan Lozano
Refactor transformSrctoCrate and the functions it calls to not rely on rust.ModuleContext, preparing it to be callable from soong-cc context to build a Rust staticlib. This also refactors out common default flags used when building libraries, again to prepare for building a Rust staticlib from a soong-cc context. Bug: 254469782 Test: m blueprint_tests && m Change-Id: I678f6fee989c61bb15c340b9887e4d1934991907
2024-05-02Make the enabled property configurable Cole Faust
This allows using select statements with it. Bug: 323382414 Test: m nothing --no-skip-soong-tests Change-Id: I6f3efaaa3d82505e38a91ee4ba0e18e404360191 Merged-In: If355d24506e3f117d27b21442a6c02bca3402dc7
2024-04-05Deprecate Snapshot build Kiyoung Kim
Existing snapshot code will no longer work from VNDK deprecation, but it can give confusion to users if we keep code for the snapshot - and it adds complexity on existing code while it is not in use. This change removes all snapshot definition except host snapshot and its usage. Bug: 330100430 Bug: 332986564 Test: AOSP CF build succeeded Change-Id: Ieb6fa43d5e38315c662ce997bc305b744b367c24
2024-03-21rust: Add export_include_dirs property to rust_ffi Ivan Lozano
The cc property include_dirs is neverallowed in certain paths since it has been deprecated. The property in rust_ffi modules with the same name functionally works the same way as the CC property export_include_dirs. To reduce confusion, and avoid triggering the neverallow rule, deprecate include_dirs and create an export_include_dirs property which does the same thing. This brings rust module properties into better alignment with cc module property as well, reducing confusion. Bug: 330736943 Test: New Soong test Change-Id: Ib2020a22e6747ac690c46dbff84e38744f93ed15
2023-12-14Convert SetProvider to generic providers API Colin Cross
Convert all of the callers of SetProvider to use the type-safe android.SetProvider API. Bug: 316410648 Test: builds Change-Id: If58f4b5355264ddab2045bc3591a4eac19cd58fc
2023-12-08Remove ConvertWithBp2build implementations Colin Cross
Remove the ConvertWithBp2build implementations from all the module types, along with the related code. Bug: 315353489 Test: m blueprint_tests Change-Id: I212672286686a318893bc7348ddd5a5ec51e77a7
2023-11-22rust: Cache crateRootPath to avoid ctx Matthew Maurer
This makes it possible to call crateRootPath in situations where a ModuleContext is unavailable. Test: m nothing Bug: 309943184 Change-Id: Iee20b0606954a18ca516cdac40917d0016f94a05
2023-11-20rust: move crateRootPath to compiler Matthew Maurer
Test: m nothing Bug: 309943184 Change-Id: I45028945357c394301d93ca7995a4f9adf281931
2023-10-19Add bp2build converter for rust_ffi_static Vinh Tran
Test: go test Change-Id: Ibf0bb2687073f8650da4ca27c1f57e68a93025d4
2023-10-13Remove restriction on android config in generated rust_library targets Vinh Tran
Bug: b/290790800 Test: b build //external/rust/crates/... --config=android Change-Id: Id06dc94f8bff519c09de7a0de0f1999cf310f599
2023-10-02Revert "Split Rust crate builds into compile and link phases." Colin Cross
This reverts commit e7c71c344d462cac998b37d551bd78baa892082d. The intermediates created by the separated rust compile steps are very large, on the order of 60GB. This is more than CI can support for now, revert the split into compile and link phases. This comes at the expense of incremental build time, especially when modifying C/C++ sources that are dependencies of rust modules. Bug: 293349612 Test: builds Change-Id: I81169e7d0727330c8de5e7688dcdc87fe7b8d3b5
2023-09-25Revert^4 "add crate_root property to rust modules" Sam Delmerico
9c64274b275a00d7753bbe1a15945652521b2044 Change-Id: I1c4dad76842cebf18cd82e04e435910f09038d07
2023-09-22Revert^3 "add crate_root property to rust modules" Wen-yi Chu
60375c4adf0753d0e2519ebf1b908d424dd2d466 Change-Id: I356e936139592893a47d4c6b9e747f24470b11f9
2023-09-22Revert "support sandboxed rust rules" Wen-yi Chu
Revert submission 2629131-sandbox-rust-inputs Reason for revert: Fail on android build. Reverted changes: /q/submissionid:2629131-sandbox-rust-inputs Change-Id: Ifd9aa46e80a12d8f4ffa0a2daa74b96727cbb7e6
2023-09-20Merge changes from topics ↵ Sam Delmerico
"revert-2746976-revert-2605644-rulebuilder-ninja-vars-OAAWYCDDLT-KMAGKVIXAT", "sandbox-rust-inputs" into main * changes: support sandboxed rust rules conditionally escape rule builder command Revert^2 "allow Ninja variables in RuleBuilder API" Revert^2 "add crate_root property to rust modules" Revert^2 "add rust_toolchain_rustc_prebuilt module type"
2023-09-20Have ConvertWBp2build use Bp2buildMutatorContext Chris Parsons
This no-op refactoring facilitates some upcoming functional changes for "bp2build allowlist v2". The work requires that the bp2build conversion mutator be changed from a TopDown mutator to a BottomUp mutator. Refactoring all bp2build-related methods so that they use Bp2buildMutatorContext makes it easier to make this functional change without touching tens of files and multiple projects. Bug: 285631638 Test: m bp2build Change-Id: I3d1ef3064146e959c6f0dc315350fc9764bf2bd2
2023-09-15support sandboxed rust rules Sam Delmerico
This commit adds support for compiling rust rules inside the sbox sandbox. To compile a rust module with sandboxing enabled, the entry point to the crate must be specified via the `crate_root` property, and all input sources and compile-time data must be specified via the `srcs` and `compile_data` properties. Bug: 286077158 Change-Id: I8c9dc5cf7578037a583b4be2e2f73cf20ffd4408
2023-09-15Revert^2 "add crate_root property to rust modules" Sam Delmerico
5162ff14fc91db500e008a18840c3dfd4edc695a Change-Id: I9a76df938639676ee4aa7bdd2b2902e0e6df08d5
2023-09-08Revert "add crate_root property to rust modules" Sam Delmerico
Revert submission 2605644-rulebuilder-ninja-vars Reason for revert: b/299568218 Reverted changes: /q/submissionid:2605644-rulebuilder-ninja-vars Change-Id: I17645fcff117909c09a016157235805f0974340b
2023-08-31add crate_root property to rust modules Sam Delmerico
The crate_root property will be used to specify the entry point for a rustc compilation. This will allow the srcs property to be used to collect all src inputs to rustc rather than just the entry point. Bug: 286077158 Test: m libnum_traits Change-Id: I1a167182305dcc11cc927d562ceed622153111d3
2023-08-25Convert libprotobuf to Bazel Vinh Tran
Since this is a one-off just for building libprotobuf that will be removed when we handle cargo output more generically (b/297364081), I didn't write a unit test for this CL. Test: b build //external/rust/crates/protobuf:libprotobuf Bug: 295925256 Change-Id: I00cf44d54be27a09c184a96c13b250a2e54e2d10