aboutsummaryrefslogtreecommitdiff
path: root/rust/binary.go
Commit message (Collapse)AuthorAgeFilesLines
* Remove ConvertWithBp2build implementationsColin Cross2023-12-081-90/+0
| | | | | | | | | Remove the ConvertWithBp2build implementations from all the module types, along with the related code. Bug: 315353489 Test: m blueprint_tests Change-Id: I212672286686a318893bc7348ddd5a5ec51e77a7
* rust: Cache crateRootPath to avoid ctxMatthew Maurer2023-11-221-1/+1
| | | | | | | | | This makes it possible to call crateRootPath in situations where a ModuleContext is unavailable. Test: m nothing Bug: 309943184 Change-Id: Iee20b0606954a18ca516cdac40917d0016f94a05
* rust: internalize srcPathFromModuleSrcsMatthew Maurer2023-11-221-6/+1
| | | | | | | | | | | | This was frequently misused (for example, in the prebuilts module, it was used as a complex "assert(len(srcs))==1"), and can be superceded by getCrateRoot anywhere it was used. It's now only called from compiler.go, and can drop the second return parameter, as it was only actually used by the prebuilt assert misuse. Bug: 309943184 Test: m nothing Change-Id: I6c92580bc8f0ecb7586c544056b5409e6dd280e7
* Revert "Split Rust crate builds into compile and link phases."Colin Cross2023-10-021-5/+2
| | | | | | | | | | | | | 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
* Revert^4 "add crate_root property to rust modules"Sam Delmerico2023-09-251-2/+7
| | | | | | 9c64274b275a00d7753bbe1a15945652521b2044 Change-Id: I1c4dad76842cebf18cd82e04e435910f09038d07
* Revert^3 "add crate_root property to rust modules"Wen-yi Chu2023-09-221-7/+2
| | | | | | 60375c4adf0753d0e2519ebf1b908d424dd2d466 Change-Id: I356e936139592893a47d4c6b9e747f24470b11f9
* Revert "support sandboxed rust rules"Wen-yi Chu2023-09-221-1/+2
| | | | | | | | | | Revert submission 2629131-sandbox-rust-inputs Reason for revert: Fail on android build. Reverted changes: /q/submissionid:2629131-sandbox-rust-inputs Change-Id: Ifd9aa46e80a12d8f4ffa0a2daa74b96727cbb7e6
* Merge changes from topics ↵Sam Delmerico2023-09-201-3/+7
|\ | | | | | | | | | | | | | | | | | | | | "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"
| * support sandboxed rust rulesSam Delmerico2023-09-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | 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
| * Revert^2 "add crate_root property to rust modules"Sam Delmerico2023-09-151-2/+7
| | | | | | | | | | | | 5162ff14fc91db500e008a18840c3dfd4edc695a Change-Id: I9a76df938639676ee4aa7bdd2b2902e0e6df08d5
* | Have ConvertWBp2build use Bp2buildMutatorContextChris Parsons2023-09-201-2/+3
|/ | | | | | | | | | | | | 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
* Revert "add crate_root property to rust modules"Sam Delmerico2023-09-081-7/+2
| | | | | | | | | | Revert submission 2605644-rulebuilder-ninja-vars Reason for revert: b/299568218 Reverted changes: /q/submissionid:2605644-rulebuilder-ninja-vars Change-Id: I17645fcff117909c09a016157235805f0974340b
* add crate_root property to rust modulesSam Delmerico2023-08-311-2/+7
| | | | | | | | | | 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
* Implement bp2build converter for rust_binaryVinh Tran2023-08-251-0/+89
| | | | | | Test: go test Bug: 295910295 Change-Id: Ieb18d9071f28e53a0463614594cee0fd755b7b3c
* rust: Add vendor and recovery dylib support.Ivan Lozano2023-07-141-5/+0
| | | | | | | | | | | | | | 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
* Split Rust crate builds into compile and link phases.Peter Collingbourne2023-04-121-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Drop rust dependency on musl_linker_scriptColin Cross2022-09-301-1/+1
| | | | | | | | | musl_linker_script is no longer required as the entry point is now _start. Bug: 242601708 Test: m USE_HOST_MUSL=true host-native Change-Id: I5acfaeb181a2dd39aac72edd94bd2030881d9d27
* Add cross-referencing support for RustSasha Smundak2022-04-201-4/+3
| | | | | | 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
* Support building rust modules against musl libcColin Cross2022-01-241-3/+12
| | | | | | | | | 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
* Support multiple crtbegin and crtend dependenciesColin Cross2022-01-241-3/+3
| | | | | | | | | 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
* Merge changes I26198187,Ia904d07bIvan Lozano2021-11-121-0/+5
|\ | | | | | | | | | | * changes: rust: Support MTE memtag_heap sanitizer rust: Support global sanitizers
| * rust: Support MTE memtag_heap sanitizerIvan Lozano2021-11-041-0/+5
| | | | | | | | | | | | | | | | | | This CL adds support for the MTE memtag_heap sanitizer. This is controlled via inclusion of an ELF note. Bug: 170672854 Test: Heap MTE-enabled Rust test binary triggers MTE Change-Id: I2619818785e86a94667d02b30d102c83456b7925
* | rust: Refactor stripped output file pathIvan Lozano2021-11-091-5/+9
|/ | | | | | | | | | | | | | | | | | | | 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
* rust: Add common interface for binariesIvan Lozano2021-11-011-0/+13
| | | | | | | | | | | | | Structs embedding binaryDecorator (rust_test, rust_benchmark, rust_fuzz) are binaries as well, but won't pass checks against *binaryDecorator, such as the check in StaticExecutable(). Add a binaryInterface that can be checked instead to simplify these checks and ensure we catch all binaries. Bug: 170672854 Test: rust_test, rust_benchmark return true StaticallyLinked Change-Id: I2373d3663373a6977260785602a02d39a41320fe
* Remove IsDependencyRoot from interfaceLiz Kammer2021-07-071-4/+0
| | | | | | | | This is equivalent to Binary() -- reduce the interface and improve clarity. Test: go test soong tests Change-Id: I770f5ce79fd4d888586d31ec5e67be88153626b6
* Rust cdylib/statliclib support for vendor snapshot.Ivan Lozano2021-06-031-0/+5
| | | | | | | | | | | | | | | | | | 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
* Rustdoc support.Dan Albert2021-04-161-1/+1
| | | | | | | | | | | | | | 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
* rust: Drop libgcc dependencyThiébaud Weksteen2021-03-231-1/+1
| | | | | | | | | | 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
* Merge "rust: Pass cc static libs to rustc."Ivan Lozano2021-02-051-0/+1
|\
| * rust: Pass cc static libs to rustc.Ivan Lozano2021-02-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | bp2build: convert paths/module refs to Bazel labelLiz Kammer2021-02-041-1/+1
|/ | | | | | | | | | | 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
* Migrate Rust to LLVM coverage.Joel Galenson2021-01-151-16/+1
| | | | | | Bug: 177675913 Test: Manually compile, run, and see output with llvm-cov. Change-Id: I66729cff87a848782e9fa1b95cbbc06318c5761a
* Refactor CC to prep for Rust sanitizable modules.Ivan Lozano2021-01-081-0/+4
| | | | | | | | | | Adds a PlatformSanitizable interface which both CC and Rust can implement so that the sanitizer mutators in CC can sanitize Rust shared/static libraries appropriately. Bug: 147140513 Test: m nothing Change-Id: Ib31103b6c4902a4d5df2565c0d7c981298d100a3
* Move prefer_rlib from binary to base compiler.Ivan Lozano2020-12-091-8/+2
| | | | | | | | | | | | 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
* rust: Add static binary supportIvan Lozano2020-10-021-4/+23
| | | | | | | | | | | | 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
* rust: Refactor staticStd to stdLinkageIvan Lozano2020-09-281-2/+5
| | | | | | | | | 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
* rust: Add prefer_rlib property for static libstd.Ivan Lozano2020-09-281-0/+11
| | | | | | | | | | | | | Adds the prefer_rlib property to allow linking libstd statically for device rust binaries. This also changes the default behavior of rustlibs to also prefer rlib linkage. This is because dylibs do not provide rlib-libstd variants and always link in libstd dynamically. Thus a binary requesting libstd rlib linkage should not attempt to link against dylibs that link libstd dynamically. Bug: 168729404 Test: New Soong test passes. Change-Id: Idf8dfbbce8fd936f55a3fb323b17a1a7f0ee954e
* rust: strip libraries and binariesThiébaud Weksteen2020-08-281-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Merge "[rust] Pass cc dependencies as linker flags."Ivan Lozano2020-08-271-0/+1
|\
| * [rust] Pass cc dependencies as linker flags.Ivan Lozano2020-08-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Link device binaries dynamically by default.Ivan Lozano2020-08-251-12/+3
|/ | | | | | | | | | | | | | | Device binaries currently are linked statically by default. Instead we should be linking these dynamic by default. To avoid conflicts when manually specifying rlib dependencies on modules, we always link libstd dynamically for all device modules except static libraries. This removes the "prefer_dynamic" property entirely to avoid confusion. Bug: 165161105 Test: m profcollectd is built dynamically. Test: cd external/rust/; mma Test: cd external/crosvm/; mma Change-Id: I25ac897040acbcc2d97c791a33e8e01610632272
* Merge changes I4efdf333,I4abaf8e7Ivan Lozano2020-07-291-1/+1
|\ | | | | | | | | | | * changes: Ensure hermetic device rust_bindgen. Generate deps file for rust_bindgen modules.
| * Ensure hermetic device rust_bindgen.Ivan Lozano2020-07-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rust_bindgen was not hermetic previously as it would pull in host headers for device targets. This fixes that by using the same flags we use when compiling with Clang. This also makes sure our rust_bindgen headers are built as similar as possible to their respective cc_libraries. This also pulls in the bionic dependencies as well, which provide the headers required for device targets. Bug: 162007475 Test: device rust_bindgen deps file does not reference host headers. Change-Id: I4efdf333e011a6c6d73a0345e5485823f166d17a
* | Enforce correct variant usage for rust_bindgen.Ivan Lozano2020-07-221-2/+1
|/ | | | | | | | | | | | | | | | | | Modules defined in the srcs property are automatically added as dependencies with AddDependency(), which will use any variant available. This can cause incorrect architecture bindings to be silently pulled in, such as when a host module uses a rust_bindgen module that doesn't create a host variant. This moves populating depPaths.SrcDeps over to depsToPaths and adds a check for SourceProviders to make sure the correct OS and architecture is being used. Bug: 161826371 Test: Soong no longer silently pulls in bindings for the wrong target. Test: New Soong test to catch this case passes. Change-Id: I2b3651cf6fc7dabf4081434df1c455e637f5b3a4
* Allow rust module dependency on SourceProviders.Ivan Lozano2020-07-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Allow rust modules to depend on and use generated source code provided by SourceProvider modules and genrule modules without resorting to hardcoded output paths. All generated sources are now copied to a dependent module's intermediates directory, then OUT_DIR is set to point to that path when calling rustc. This matches the common convention used in most rust crates to include generated source code from the path defined in the OUT_DIR environment variable. A couple other small notable changes are included in this CL: * prebuiltLibraries can no longer include generated source files as they should be prebuilt. * srcPathFromModuleSrcs now excludes the main source file from the second return value so its a list of only the generated sources. Bug: 159064919 Test: Local example rust_library compiles with rust_bindgen dependency. Test: Local example rust_library compiles with genrule dependency. Test: Collision detected when multiple providers produce similar output. Test: New Soong tests pass. Change-Id: I59f54a25368c680b9086420c47ec24ab8cd1de6b
* Specify module dependency in the srcs listChih-Hung Hsieh2020-07-081-1/+2
| | | | | | | | | | | | * "srcs" list contains one main Rust source file, followed by optional dependent modules. * A dependent module included in the "srcs" list is the module name prefixed with ":". * Add a simple test. Bug: 160331255 Test: make and manual test build dependencies on genrule modules Change-Id: I4f079138c2599158810b6412fce81b612a3f64a4
* rust: Add rustlibs auto dependency selectionMatthew Maurer2020-07-011-0/+8
| | | | | | | | | Adds the rustlibs dependency type which will automatically select between rlib and dylib based on the type of the library. Bug: 143217452 Test: cd external/rust; mma Change-Id: I97faadae98bf957090a32939cfb2d3a10f74a057
* [Rust] Remove unused variables and deduplicate.Ivan Lozano2020-06-161-8/+2
| | | | | | Bug: 158731826 Test: cd external/rust/crates; mma Change-Id: I8c9e5cfeaf941b9676b92451b227c15db9a41bbc
* Add gcov coverage support to Rust modules.Ivan Lozano2020-05-051-4/+23
| | | | | | | | | | | | | | | | | | | This adds gcov coverage support for Rust device library and binary modules (including test modules). Support is provided to pass Rust static library gcno files to CC modules and visa versa. Additional changes: * Begin mutator added for Rust modules. * SuffixInList added to android package. * CoverageEnabled added to Coverage interface. * CoverageFiles added to LinkableLibrary interface. * Fix in coverage mutator for non-CC modules which marked the wrong variant as the coverage variant. * Added coverage libraries to the cc.GatherRequiredDepsForTest. Bug: 146448203 Test: NATIVE_COVERAGE=true COVERAGE_PATHS='*' m -j <rust_module> Change-Id: If20728bdde42a1dd544a35a40f0d981b80a5835f
* Install rust tests under nativetest(64)Chih-Hung Hsieh2019-12-131-1/+1
| | | | | | | | | | | | | | * Now the installation directories match those for C/C++ tests: * The relative_install_path refers to path under nativetest(64). * Device test files are installed in data/nativetest(64). * Automatically generated configuration files and copied test binaries are still in the "testcases" directory. * Change host test configuration to run test binary files in testcases/<mutated_module_name>/<arch_type>/<stem_name> Bug: 140938178 Test: atest --include-subdirs under external/rust/crates Change-Id: I4b29afb897f4ba8749e87f79857c5b1a959bb2b0