summaryrefslogtreecommitdiff
path: root/rust/library.go
AgeCommit message (Collapse)Author
2023-08-25Implement bp2build converter for rust_proc_macro Vinh Tran
Test: WIP Bug: 297356482 Change-Id: I17d1a0a95d4a67ccbc9b2d74e49bcacd6ff4d26b
2023-08-25Implement bp2build converter for rust_library Vinh Tran
Test: go test Bug: 297294749 Change-Id: I5400fe2c0fe2097b7a5810c736fbd1de4f35c6f7
2023-08-14Rust library linking fixes A. Cody Schuffelen
- Hide universal binary dependency for rust Without a darwin_arm64 libstd prebuilt, many rust binaries are not possible to build as a universal binary anyway. This fixes an intermediate error with compiling rust FFI targets, where C++ shared library dependencies for both architectures were combined into the same linker command. There is still an outstanding problem with C++ executable targets that include rust FFI library targets, as the rust FFI library targets fail to find a proper libstd to build the arm64 side of the universal executable. - Use dynamic_lib instead of soname This matches similar logic in cc/library.go : linkerFlags for including shared libraries. Bug: 291830024 Test: m libkmr_cf_ffi (when enabled for darwin) Change-Id: I1d6b6a7855c6649b93ab6592ea43b17c6e37b3a3
2023-07-14rust: Add vendor and recovery dylib support. Ivan Lozano
Adds dylib support for vendor and recovery images. This changes the default linkage for vendor and recovery images to dylib, which matches the platform default linkage. This also means that by default, dylib-std variants are used for rlib dependencies. Bug: 204303985 Test: Soong tests. Test: m dist vendor-snapshot Test: RECOVERY_SNAPSHOT_VERSION=current m dist recovery-snapshot Change-Id: If84074b8615a70c45e7e162abeb853dc8c34d49a
2023-06-22Merge "Use generics for DepSets" Colin Cross
2023-06-22Use generics for DepSets Colin Cross
Use Go's generics for DepSets so they don't require a type-specific wrapper and reflection. Test: depsets_test.go Change-Id: I22ba0b7d680d37d2cd05230b0f560d166c4dd20b
2023-06-15rust: Make dylib-std the canonical rlib form Ivan Lozano
This removes the dylib-std suffix from rlib variants which link against libstd dynamically. This is by far the common case. This fixes an issue where 'm <rust_library_rlib>' would fail since Make would expect the suffix to be included (e.g. 'm libfoo.dylib-std'). Bug: 173312517 Bug: 268086496 Test: m <rust_library_rlib> # without a suffix Change-Id: I1e5778c57468302a8d672d5eb540047d8bb79314
2023-04-12Split Rust crate builds into compile and link phases. Peter Collingbourne
Teach rustc to generate object files instead of a linked executable for binary and shared library crates. This lets us skip the lengthy Rust compilation phase when only the C++ dependencies of these crates have changed. This works using a Python script that replaces the linker invoked by rustc and converts the linker command line into a rspfile that can be used during the link phase. The script makes certain assumptions about how rustc invokes the linker, but since we control the version of Rust we use, we can update the script if those assumptions ever break. I've asked the Rust developers about adding an official way to do this so hopefully we won't need to rely on this hack in the future. The rustc rule for Kythe has been altered to pass linker=true, somewhat consistent with the main rustc rule, which now doesn't invoke the actual linker either. `m xref_rust` still succeeds, but hopefully we can find someone who knows more about the rest of the Kythe pipeline who can let us know whether it should still work. Otherwise, let's use this CL as an opportunity to find out whether the rest of the pipeline is happy with linker=true, since otherwise we will find it hard to maintain the Kythe rule in the future. Change-Id: Ifb9c8689c1bd78c0afcf6fdfd111140d20377536
2022-11-18rust: expand docstrings for Rust module types Martin Geisler
This gives a tiny bit of context in the documentation and allows people to more easily map the Soong build rules to the Rust terminology. Bug: 254469782 Test: atest Change-Id: Ia8fde42c15919dd03954e9ebf83022d0a569407e
2022-05-13Clean up some bp2build technical debt Liz Kammer
Previously we ran mutators in bp2build mode to add dependencies, now we look up modules by name directly. Remove workarounds to allow bp2build mode to not fail when adding/handling dependencies. Test: m bp2build Change-Id: Ibf6fd905150cac306e5c395902ef28f609f4df2a
2022-04-20Add cross-referencing support for Rust Sasha Smundak
Bug: 222044478 Test: run TARGET_BUILD_VARIANT=userdebug TARGET_PRODUCT=cf_x86_64_phone XREF_CORPUS=googleplex-android.googlesource.com/codesearch/android build/soong/build_kzip.bash Change-Id: Ia12eed53fafd0cbbbf2cc499fa20a0f5a40031de
2022-02-07Update error messages for failed globs. Liz Kammer
Currently error messages appear like: &fs.PathError{Op:"open", Path:"..." Err:0x18} which make them difficult to parse. Test: CI Change-Id: I18da18abc43230d0ea37d166179d07e585077f51
2022-01-24Support building rust modules against musl libc Colin Cross
Add a rust toolchain for musl libc, use std library built from source, and add default dependencies on musl libc. Bug: 216192129 Test: m USE_HOST_MUSL=true host-native Change-Id: Ic5ff4487db9693aeb08a13405f4d18465eecdc4b
2022-01-24Support multiple crtbegin and crtend dependencies Colin Cross
Musl libc with an embedded linker uses multiple crtbegin dependencies, convert rust's CrtBegin and CrtEnd to lists. Bug: 190084016 Test: m USE_HOST_MUSL=true host-native Change-Id: Ie843801e87b1f38ace84502d9e4f938a92ec1fa2
2021-12-16rust: Disable dylib vendor modules Matthew Maurer
These modules do not currently build correctly. Support is planned but not complete. Bug: 204303985 Test: Presubmit + build `rust_library` with `vendor_available: true` Change-Id: Iac7df9fe0d4eaa9a5ec0ff5a9cd5670af23df2a6
2021-11-09rust: Refactor stripped output file path Ivan Lozano
Rust installed files reside in "$MODULE_OUT/stripped/" when they are stripped, otherwise they reside in "$MODULE_OUT". However, other parts of Soong assume that installed files are always in $MODULE_OUT (cc_modules place *unstripped* files in $MODULE_OUT/unstripped). This notably causes problems when adding Rust modules as test data in AndroidMkDataPaths. When Rust modules are parsed by AndroidMkDataPaths, if they are stripped then they incorrectly get installed as test data with the path: <install_root>/<relative_install_path>/stripped/file. This CL refactors how we handle Rust stripped output such that the installed file always resides in $MODULE_OUT. Bug: 171710847 Test: Installed files now always reside in $MODULE_OUT Change-Id: I53a6ff57a0a5a55cd95ea78ae592ce22abfa20c9
2021-11-03rust: Emit toc files for cdylibs Ivan Lozano
Write toc files that list the exported symbols so dependents are only rebuilt if the exported symbols change. This exports the CC function TransformSharedObjectToToc, and also removes an unused arg from its signature. Bug: 178185435 Test: New Soong test passes. Test: m <toc file path> Change-Id: I7ab69bf7e7f32f25eb4c7ca9d18d877dac1511db
2021-09-23rust: Refactor cfg and feature flag calculation Ivan Lozano
Move the cfg and feature flag calculation out of compilerFlags so that it's a separate step. The previous arrangement resulted in overridden compilerFlags which must to set any additional cfgs/features before calling the base. This is a bit confusing and undocumented behavior, so instead break it out into a separate call that can itself be overriden. Bug: N/A Test: Soong tests pass Change-Id: I28e4f707b3b3ca6eb621b7613c3737817f877bb8
2021-07-22Merge changes I3574d2a1,Ifb69fb3d Kiyoung Kim
* changes: Update prebuilt_etc available for snapshot Separate snapshot definition
2021-07-19Separate snapshot definition Kiyoung Kim
Current snapshot definition is located in the CC module, so it is difficult to capture non-CC module (such as prebuilt_etc) to the snapshot. Separate general snapshot definition from cc so other modules can also define its own snapshot. Bug: 192430376 Test: m nothing passed Change-Id: Ifb69fb3d2ec555b629aa31ec03e7ce5831fd3063
2021-07-07[rust] Add android_dylib cfg flag Stephen Crane
Adds an android_dylib cfg when building a Rust crate as a dylib. This cfg lets us make the hack to add a dependency on std for the panic_handler and eh_personality conditional on actually building a dylib. Test: m nothing Bug: 193087363 Change-Id: Idad5b98245264f916afa327812a435b368f99321
2021-06-08Only store what's used in SharedLibraryInfo Liz Kammer
There was a reference to the static library provider, but only the transitive static deps were used, so only store that part. Other members were stored but unused anywhere. Test: go test soong tests Test: m nothing Change-Id: I12a6b94806c052c3f0df3cab0a10f17042af1c38
2021-06-03Rust rlib vendor snapshot support. Ivan Lozano
Adds support for snapshotting Rust rlibs. This allows us vendor-specific code that uses rlib-only linkage until dylib snapshot support is added. Bug: 184042776 Test: m nothing # new Soong tests pass Test: Example test Rust vendor module builds Test: m dist vendor-snapshot # includes rlibs Change-Id: I4976d3e1efec0ee778cc97730d45be471dffb678
2021-06-03Rust cdylib/statliclib support for vendor snapshot. Ivan Lozano
Adds support for platform vendor_available Rust FFI libraries and binaries to be included in the vendor snapshot. Because rlib and dylibs are not yet in snapshots, libstd cannot be included in a vendor snapshot. As a result, vendor-specific Rust code can't be guaranteed to work with the platform-provided vendor_available modules built with a newer toolchain. For now, a check is added indicating vendor-specific Rust code is unsupported. This changes the linkage for vendor variants of these modules to default to rlib linkage since dylibs cannot be included in the snapshot yet. Bug: 184042776 Test: m nothing # new Soong tests pass Change-Id: I502eaa4bb962eb87ff868fcf49b435f0d2f982e6
2021-04-19Merge "Rustdoc support." Treehugger Robot
2021-04-17Merge changes from topic "tvts-test-host-jni" Treehugger Robot
* changes: Add jni_libs property to java tests Add Target to cc.SharedLibraryInfo
2021-04-16Rustdoc support. Dan Albert
Adds `m rustdoc` which generates documentation for all Rust libraries to $OUT_DIR/soong/rustdoc. Follow up work: * Generate an index page that lists all modules. * Preserve the artifacts so we can have an always-up-to-date go link. Test: m rustdoc Bug: None Change-Id: Id2d6b9cbab5b02e36b575567563d7cc7606b9401
2021-04-15Merge changes I59439b77,I7dbaf8be Thiébaud Weksteen
* changes: bloaty: measure stripped Rust binaries rust: do not strip static library
2021-04-14rust: do not strip static library Thiébaud Weksteen
Test: m Change-Id: I7dbaf8be625acae89b0a62ea13d0b250c6542a79
2021-04-13Add more Rust vendor image support. Ivan Lozano
This adds Rust vendor image support for all module types except Rust prebuilts. Bug: 184042776 Test: New Soong tests. Test: Example cc_library vendor module can depend on rust_ffi_shared. Test: Example rust_library vendor-only module compiles. Change-Id: Iaa30ad51fdaedcbf14687da5472581f6af62ff59
2021-03-23rust: Drop libgcc dependency Thiébaud Weksteen
Rustc unstable option "link-native-libraries" is used to prevent the linkage of other libraries via the #[link] directive. Add a dependency to libclang_rt.builtins, similarly to cc. Bug: 141331117 Test: lunch aosp_crosshatch-userdebug; m Change-Id: I5c232291a5dd08a99e6a12a1295e30bb8e4fcaf1
2021-02-05Merge "rust: Pass cc static libs to rustc." Ivan Lozano
2021-02-04rust: Pass cc static libs to rustc. Ivan Lozano
Pass static libraries to rustc via the "-lstatic" flag so that rustc can reason how to handle these libraries. This means that these static libraries get bundled into rlibs, reducing the need to redeclare these dependencies in dependent modules. Additionally, exported depFlags were never used anywhere, so remove this from flagExporter. Bug: 175886967 Bug: 179122837 Test: m Test: Checked that static symbols aren't duplicated in a resulting binary when it appears in a dependency graph more than once. Change-Id: Ifeb3c384e4fad8704206997242a0156ddcb87d2c
2021-02-04bp2build: convert paths/module refs to Bazel label Liz Kammer
This currently expands all globs, still need to support converting glob syntax. Test: go build_conversion_test Test: GENERATE_BAZEL_FILES=true m nothing Test: m nothing Bug: 165114590 Change-Id: If7b26e8e663d17566fad9614ca87a8da1f095284
2021-01-26Add Target to cc.SharedLibraryInfo Colin Cross
Dependencies from common arch modules like java libraires to cc modules may need to retrieve the Target of the library, add it to SharedLibraryInfo. Bug: 176593487 Test: cc_test.go Change-Id: I93ab9da5fab2ccc42c6b483a6d83c071b541d1e6
2021-01-15Migrate Rust to LLVM coverage. Joel Galenson
Bug: 177675913 Test: Manually compile, run, and see output with llvm-cov. Change-Id: I66729cff87a848782e9fa1b95cbbc06318c5761a
2020-12-11Merge "Rust: WriteFileRule instead of printf for protos" Ivan Lozano
2020-12-11Merge "Rust: Vendor support for Rust static libraries." Ivan Lozano
2020-12-10Rust: WriteFileRule instead of printf for protos Ivan Lozano
Use WriteFileRule instead of a rule that calls printf for generating the module source file for rust_protobuf. Bug: 171361369 Test: rust_protobuf modules compile Change-Id: Ie83a30e19d7d09875f3d209662526783862d8ea0
2020-12-10Rust: Vendor support for Rust static libraries. Ivan Lozano
We don't have Rust VNDK support yet, but static linkage can be supported in the interim. This adds support for making rust_ffi_static libraries available to CC vendor modules. Since rust_ffi_static modules will link against rlibs, we allow rlib linkage into vendor as well, but only for the variants which use the rlib libstd. Bug: 172525289 Test: New Soong tests pass Test: Example vendor cc_binary links against rust_ffi_static module. Change-Id: Idf3aeb51e32293866f1ad965e329aa6b9e0bf2ef
2020-12-09Move prefer_rlib from binary to base compiler. Ivan Lozano
Moves the prefer_rlib property out from being exclusively a binary property to one thats part of the base compiler properties. This provides a little more control over the libstd linkage in our libraries. Specifically, this enables a usecase where rust_ffi_shared needs to link against libstd statically rather than dynamically. Bug: 175121262 Test: New Soong tests pass. Change-Id: If68014c684a75ba70e9d7dacbb01c7d360dc25a1
2020-11-30rust: Add support for multiple protos per module. Ivan Lozano
This further emulates the rust-protobuf gen_mod_rs flag by providing support for generating a single module containing multiple protobuf definitions. Bug: 171361369 Test: New Soong tests. Test: Example module containing multiple protos works. Change-Id: I815f9628a8289ae512758073dac49bc4535abf01
2020-10-12Start using Providers instead of direct module access Colin Cross
Export information about static libraries, shared libraries and exported flags through Providers instead of accessing the module directly. Much more is left to be converted, but this significantly simplifies the dependencies on libraries with stubs by making it easy for a module to masquerade as another by simply exporting the providers from the other module. Instead of depending on all the versions of a library and then picking which one to use later, it can depend only on the implementation variant and then select the right SharedLibraryInfo from the variant. Test: m checkbuild Test: only expected changes to build.ninja Change-Id: I1fd9eb4d251cf96ed8398d586efc3e0817663c76
2020-10-02rust: Add static binary support Ivan Lozano
Adds the "static_executable" property to rust_binary modules which allows for building fully static executables. This only impacts bionic targets. Bug: 169434439 Test: rust_binary module with static_executable true builds, runs on device. Change-Id: I83c19fddd070859b7e56d248237cfd73e1768519
2020-09-28rust: Refactor staticStd to stdLinkage Ivan Lozano
Instead of returning a boolean, return an enum value to improve readability and provide greater flexibility for future modifications. Bug: 168729404 Test: Soong tests pass Change-Id: Iddcdae8c34be09e476404382e43d1ea5935bae65
2020-09-25Avoid Rust source provider rule duplication Thiébaud Weksteen
Until now, source provider modules duplicated the rule to generate the source for each variant. Add a inter-variant dependency between the source and the other variants (e.g. rlib, dylib) to avoid this duplication. Add documentation on this behaviour. Bug: 162588681 Test: m Change-Id: I41c9e2220f8875245415e17374852e540dfd47ec
2020-09-18rust: Add libstd linkage mutator for rlibs. Ivan Lozano
The current state of linkage is that device targets always link libstd dynamically except for rust_ffi_static which requires a static libstd linkage. However this prevents producing rust_ffi_static modules which depend on other Rust libraries as those dependencies will link libstd dynamically and cause a collision. We also want our rust_test modules to statically link in libstd as well. This adds a linkage mutator for rlibs that creates a variant for each libstd linkage. Dependent modules can then select the variant that matches their linkage of libstd. Also fixes an issue where installation paths were being generated for rlibs and static libs even though they weren't being installed. This broke when adding the linkage mutator as Make would complain about multiple targets producing the same output. Bug: 168729404 Test: rust_ffi_static module with other rustlib dependency can be built. Change-Id: I955b484bf5809e8fc5517750c7f8df82d3ca8895
2020-08-28rust: strip libraries and binaries Thiébaud Weksteen
Reuses the cc.Stripper logic. Abstracts Stripper to avoid the spreading of references to the cc package. rustc requires unstripped libraries (precisely, with the `.rustc` section) when building dependent targets. Contrary to cc, the output of a compiler module will remain unstripped and only an extra build rule will be added. This rule will be referenced at install time (in baseCompiler.install or androidmk). This change drastically reduces the size of the installed libraries: (unstripped, from out/target/product/crosshatch/system) $ find . -name \*.dylib.so -print0 | du -c --files0-from=- 149996 total (stripped, with this change) $ find . -name \*.dylib.so -print0 | du -c --files0-from=- 42380 total Bug: 153430439 Test: cd external/rust; mma Change-Id: I94fd8bbcec97e0610aa325d3db4460be84d01734
2020-08-27Merge "[rust] Pass cc dependencies as linker flags." Ivan Lozano
2020-08-26[rust] Pass cc dependencies as linker flags. Ivan Lozano
In order to support cc dependencies which do not start with the 'lib' prefix, we can't pass them through the -l flag. Instead, we can pass them directly to linker flags. Bug: 166151658 Test: cd external/rust/; mma Test: cd external/crosvm/; mma Test: Test linking to a cc dep that does not begin with 'lib' Change-Id: I5acbf3d3405e66446f3eae600b35683c4eb3d8a5