summaryrefslogtreecommitdiff
path: root/rust/compiler.go
AgeCommit message (Collapse)Author
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-16Merge "rust: Add support for host fuzzers." into main Ivan Lozano
2023-08-14Remove dylibs prop from rust module types Vinh Tran
For device build, rust defaults to dylib linkage for rustlibs deps. `dylibs` prop was provided for flexibility. By removing it, we're enforcing users to either use the default linkage (dylibs for device and rlibs for host) or rlibs prop explicitly. This means no dylibs for host modules. This makes sense because host modules always uses rlib linkage against libstd. The flexibility with dylibs prop opened room for linkage collisions because the dependencies don't link against libstd the same way. Test: go test Change-Id: I2fc221daa8a9bb42bdcf6d9823c723a4ddabe7b5
2023-08-10rust: Add support for host fuzzers. Ivan Lozano
Adds support for host-based Rust fuzzers. Bug: 282897366 Test: SANITZE_HOST="address" m <host_fuzzer> Test: run fuzzer Change-Id: Ibb951f651ef12e763778ebbf12e66769a7113920
2023-02-24rust: Set android_vendor and android_product cfg Matthew Maurer
Add `android_vendor` and `android_product` cfgs, similar to __ANDROID_VENDOR__ and __ANDROID_PRODUCT__ defines for C++ Bug: 270718001 Test: m nothing with added test Change-Id: Ibeabe2983d1454e5a2ec0bb2f43e793b8f32a5c2
2023-02-14rust: Fix coverage in no-std crates Ivan Lozano
Coverage builds for no_std crates currently fail because profiler_builtins are part of libstd and therefore do not get included. When calculating the dependencies for coverage enabled targets, check if the stdlib is being included, and if it is not then pull the profiler_builtins sysroot. Bug: 249551848 Test: CLANG_COVERAGE=true NATIVE_COVERAGE_PATHS='*' make libtinyvec_nostd.rlib-std Change-Id: I73f89bddcb2d4d9c704cb3962ee39b73888c7f3f
2023-01-11Use the same rpaths for tests and binaries and cc and rust Colin Cross
Rust and cc binaries currently use $ORIGIN/lib64:$ORIGIN/../lib64 as the rpath, and cc tests add $ORIGIN/../../lib64:$ORIGIN/../../../$ORIGIN:$ORIGIN. This causes problems when a binary is included as test data in out/host/linux-x86/testcases/<test dir>/<CPU>/<test>, as the binaries can't find the libraries in out/host/linux-x86/lib64. Use the same rpath for test and binaries, and for cc and rust. Bug: 264604160 Test: m USE_HOST_MUSL=true out/host/linux-x86/testcases/acpi_tables_test_src_lib/x86_64/acpi_tables_test_src_lib && out/host/linux-x86/testcases/acpi_tables_test_src_lib/x86_64/acpi_tables_test_src_lib Test: m USE_HOST_MUSL=true out/host/linux-x86/testcases/gen_sdk_test/x86_64/gen_sdk_test && out/host/linux-x86/testcases/gen_sdk_test/x86_64/toybox Change-Id: I10fe5dc0de01d1f3c6aea8dbabbf60edab5989c3
2022-09-29Remove spurious trailing backslash in prefer_rlib docstring Martin Geisler
Change-Id: I851306c73cb86df4bc4c82c3471ce3b6eaad9ded
2022-07-01Don't use prebuilt rust stdlibs for linux bionic Colin Cross
Linux bionic doesn't have rust stdlib prebuilts, don't use the prebuilts when it is configured as the host os. Bug: 216192129 Test: builds Change-Id: I03425dee4b2e3659bf90c0a0c808cc286daa4b7f
2022-07-01Use musl rust prebuilts for USE_HOST_MUSL=true Colin Cross
Building rust code with musl enabled can load proc macro crates built against musl into rustc, so we have to use a version of rustc also built against musl. Bug: 216192129 Test: m USE_HOST_MUSL=true host-native Change-Id: Icd23b542a4b64a975850a8a4bb4b69183cc6c2c6
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-03-07Add stdlibs property for Rust build rules. Andrew Walbran
This lets no_std crates depend on system crates like core and alloc. Bug: 223152204 Test: built pVM firmware skeleton with rust_ffi_static rule Change-Id: I0f9b0ab3f5e3289fb8ce66f28d779bcf62a7181f
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
2021-11-12rust: Support new rust_stdlib_prebuilt_host type Ivan Lozano
Refactor Rust prebuilts to support the new rust_stdlib_prebuilt_host module type, and change the format for depending on the prebuilt host stdlibs. Bug: 140642453 Test: m Change-Id: Ifbc4741818777934e917631c788b20911856c44a
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-10-14Flag an error on empty rust module srcs Seth Moore
It's an error if a rust module's srcs is empty. Prior to this change the output was a panic that complains loudly about a slice error and nothing else. This change doesn't stop the panic, but at least adds a bit of context so devs who make a simple mistake can more easily fix it. Test: SOONG_GEN_RUST_PROJECT=1 m nothing Change-Id: Id7d8465d533413c3000699661222a53a7c8678f3
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-08-20rust: Hook up InstallIn functions + Product Matthew Maurer
InstallIn functions must be hooked up not only to install to special images, but also to receive special handling by android/arch.go such that some images are implicitly multilib: first. Also hook up more product details. Bug: 178565008 Bug: 165791368 Test: lunch aosp_arm64; m Change-Id: I1980d5aa9d55f78c222b98d60a404cd6ea5abbfb
2021-08-13Merge "rust: Allow modules to use only generated sources" Ivan Lozano
2021-08-13rust: Allow modules to use only generated sources Ivan Lozano
Removes the need for rust_test modules that test generated source to define a source file that simply calls include()! to pull in the generated source. Bug: 196076408 Test: m libselinux_bindgen_test Change-Id: I600301ab74f6ece861916fa2545b061c81b0d92d
2021-08-13rust: Link libunwind into Rust static executables. Ivan Lozano
Rust static executables fail to build due to missing unwind symbols. Make sure we link libunwind when building these. Bug: 194386505 Test: rust_binary with static_executable: true builds. Change-Id: I74bab25e186e181bc1ac8fdd608687707c662e4d
2021-08-12rust: Add support to emit certain Cargo env vars. Ivan Lozano
Some crates expect Cargo to provide certain environment variables. This CL adds a compatability flag that emulates the behavior of Cargo by setting these environment variables when building. Bug: 171011485 Test: New soong tests pass Test: quiche no longer requires patch removing CARGO_PKG_VERSION Change-Id: I4c95c284846f6075428c6f61fe8c260f2e35fbd9
2021-07-27rust: Prevent manually defined lib link flags. Ivan Lozano
Adds a filter to prevent modules from manually defining certain linkage flags. These flags should only be automatically generated based on listed dependencies. Bug: 161942165 Test: Soong tests pass Change-Id: Ibc014391ef1de10188c2d139d41d0241d6c68b5f
2021-07-20Replace android.BuildOs with Config.BuildOS Colin Cross
Replace the android.BuildOs constant with Config.BuildOS so that it can vary based on the product config. Bug: 190084016 Test: all Soong tests Change-Id: Ia67f872d8b2ab788747a22e3a9659dc21c9775cd
2021-07-07Remove IsDependencyRoot from interface Liz Kammer
This is equivalent to Binary() -- reduce the interface and improve clarity. Test: go test soong tests Change-Id: I770f5ce79fd4d888586d31ec5e67be88153626b6
2021-05-12Refactor vendor snapshot to use LinkableInterface. Ivan Lozano
Refactors the vendor snapshot support to use the LinkableInterface so that support can be extended to Rust. This CL does not add vendor snapshot support for Rust; that is left for a follow-on CL. Bug: 184042776 Test: m nothing Change-Id: Id0c4970ca00053484a52677d182153cbc454c301
2021-04-21Merge "Remove unnecessary `android:"path"` tags in rust" Treehugger Robot
2021-04-20Remove unnecessary `android:"path"` tags in rust Liz Kammer
Custom_bindgen is handled by adding a relevant dependency tag. Flags and Ld_flags are not paths/references to other modules. Test: go test soong tests Change-Id: Ic6a69521102318b3b9f29b59560bcefbc9aff8fa
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-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-04-08Merge "rust: Add cfgs property" Thiébaud Weksteen
2021-04-07Stripped rust bin/libs are included in APEX Jiyong Park
Previously, when a rust bin or library is selected for an APEX, OutputFile() was used to get the file to be used. However, OutputFile() always returns the unstripped output file even when the stripped output file is available. As a result, APEX having a rust module was very big due to the debugging information that exists in the unstripped file. When a rust module is directly installed to the built-in partitions, we use the stripped one whenever it's available. To make the same happen when the rust module is placed in an APEX, OutputFile() is modified to return the unstripped output if it's available. Bug: 181751814 Test: TARGET_BUILD_APPS=com.android.virt m The size is reduced from 180MB to 43MB Change-Id: I6f8479e6a4794aac8bf94a84afdf65d417c75db0
2021-04-07rust: Add cfgs property Thiébaud Weksteen
Rust configuration options ("--cfg") are currently defined using the "flags" property. Adds a specific property to be able to forward these to the rust-analyzer configuration (rust-project.json). Bug: 183727250 Test: m libstd Change-Id: Ida89097814bcd1a45c02a8a79ec5a8e9e59701bd
2021-03-25rust: Add whole_static_libs, revert static_lib Ivan Lozano
Revert the static_lib behavior to the previous behavior (pass static libs to the linker rather than via to rustc using `-lstatic=<lib>`). To bundle static libraries into libraries, provide the whole_static_libs property which retains the current static_libs behavior. Passing all static libraries via -lstatic was resulting in odd bloat where in some cases static symbols were duplicated in binaries and libraries. This split makes it possible to be explicit about when static libraries should be bundled. Bug: 183182230 Test: mma system/bt; mma system/security/keystore2; mma external/rust Change-Id: Ic2dde5d1542dca5ce145aa3a3fbd9ea54440d991
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-03-15Export OUT_DIR variable to rust-project.json Thiébaud Weksteen
This variable is required by rust-analyzer to correctly process crates that uses the include!(concat!(env!("OUT_DIR"), ...)) pattern. Adds an initialize method to baseCompiler to save the computed path for this directory. It is not possible to use the BeginMutator as the BaseModuleContext does not contain enough information to use PathForModuleOut. Bug: 175004835 Test: SOONG_GEN_RUST_PROJECT=1 m nothing; inspect rust-project.json Change-Id: If47b3832d3cca5712ae87773c174a61f5ee27bf8
2021-02-14Merge "rust: Emit android vndk cfg flag." Ivan Lozano
2021-02-12rust: Emit android vndk cfg flag. Ivan Lozano
Pass an "android_vndk" cfg flag that indicates this code targets the vndk. This can be useful in instances where code might need to behave differently. This also includes a fix to make sure our vendor Soong tests are correctly configured. Bug: 179907868 Test: Soong tests pass. Test: Example module emits new cfg flags. Change-Id: I01cdf91f6f9d42cd8a759266d5170479664bf4bc
2021-02-09rust: Use prebuilts for x86 host target. Ivan Lozano
Use prebuilts for x86 host targets to make both x86 and x86_64 builds more consistent with one another. This fixes building x86 binaries. Bug: 162063992 Bug: 169347277 Test: Build 32-bit host module. Change-Id: Id11eb0f3b949439cec090060a33b755af94b5883
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-01-26Merge "Migrate Rust to LLVM coverage." Treehugger Robot
2021-01-25Add Rust fuzzing support. Ivan Lozano
Add a rust_fuzz module which builds a libfuzzer binary that enabes asan+sancov. This relies on the libfuzzer-sys crate. Bug: 147140513 Test: Local rust_fuzz example builds, fuzzes with asan+sancov. Change-Id: I57db3b8d25869791824ccfab768d13b0bb9d42fa
2021-01-15Migrate Rust to LLVM coverage. Joel Galenson
Bug: 177675913 Test: Manually compile, run, and see output with llvm-cov. Change-Id: I66729cff87a848782e9fa1b95cbbc06318c5761a
2021-01-08Refactor CC to prep for Rust sanitizable modules. Ivan Lozano
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
2020-12-22Remove unnecessary snake case variables. Jaewoong Jung
Test: m nothing + TreeHugger Change-Id: I99f7162944daa6c57c6ae4763261e108bb5cb6b1
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-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-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