summaryrefslogtreecommitdiff
path: root/rust/compiler.go
AgeCommit message (Collapse)Author
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 rustLiz 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 APEXJiyong 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 propertyThié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_libIvan 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 dependencyThié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.jsonThié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 supportIvan 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 stdLinkageIvan 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
2020-09-15Don't disable rust modules for linux_bionicJiyong Park
With If4300583edfb6d75bd4d984b38f73b6a406b4447, linux_bionic supports arm64 and rust toolchain was configured to support the new target. However, rust module types still have been disabled for linux_bionic targets which forces many rust modules to be annotated with target.linux_bionic_arm64.enabled: true, which will be very cumbersome. Therefore, stop disabling the rust modules for linux_bionic. Bug: 159685774 Test: HOST_CROSS_OS=linux_bionic m nothing Change-Id: I68b97a43e8252fb82da6e87b3481fa237e1f2691
2020-08-28rust: strip libraries and binariesThié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-25Link device binaries dynamically by default.Ivan Lozano
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
2020-08-13rust: modify linting propertiesThiébaud Weksteen
Move the linting properties to an enum with 4 possible options: "default", "android", "vendor" or "none". The previous logic for default, based on the module's location, is kept. It is now possible to force the upgrade to a certain lint level for some modules (e.g. external/[...]/android). Update the unit tests and documentation. Bug: 163400111 Test: m Change-Id: I8e464b04401158ed2d3c518a9b72f145a9835c99
2020-08-07rust: fully disable all lints when no_lint is setThiébaud Weksteen
If the no_lint attribute is set, we now explicitly disable any warning or error. Bug: 162897623 Test: cd external/selinux; mma; check the build log for warnings Change-Id: I5338bda77ab25ded7cc43cc3afd29419fcbd9808
2020-08-04[rust] Disable lints for generated bindingsStephen Crane
Bindgen generated bindings will not pass lints, so we need to disable them when building bindings crates. Test: m libbinder_ndk_bindgen Change-Id: I4536f15f8505ff8d5436f1e6cbc2035e6801276d
2020-08-04Merge "[rust] Add SourceProviders as crates support."Ivan Lozano
2020-08-04[rust] Add SourceProviders as crates support.Ivan Lozano
This allows SourceProvider modules to create rust_library variants so that generated source can be referenced as an external crate rather than via an include macro. This is done by including rust_bindgen modules like any other library, as a dependency in either rlibs, dylibs, or rustlibs. This renames the stem and flags properties for rust_bindgen modules to source_stem and bindgen_flags, respectively. This deconflicts with the usage in baseCompiler. This also removes 'subName' from the Module struct and moves it over to SourceProvider, which was the only user. This allows us to set it in baseSourceProvider's AndroidMk; setting it in Module's AndroidMk was causing problems finding NOTICE files for bindgen library variants. Bug: 159064919 Test: New Soong tests pass. Test: Local test rust_binary can use rust_bindgen module as a crate. Change-Id: Ieb2cb614c2dd0b5aa7120541d77f6f822a6a1806
2020-08-03Move getEdition to a baseCompiler methodThiébaud Weksteen
Test: cd build/soong; mma Test: cd external/rust/; mma Change-Id: Ide63b2e633e7c4345c6338e107f5d66688e4cf58
2020-07-28Ensure hermetic device rust_bindgen.Ivan Lozano
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
2020-07-20Allow rust module dependency on SourceProviders.Ivan Lozano
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
2020-07-08Specify module dependency in the srcs listChih-Hung Hsieh
* "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
2020-07-01rust: Suppress default sysroot unconditionallyMatthew Maurer
With proper prebuilt modules, we can avoid any rustc implicit sysroot searching. Asd a bonus, this should make rust-project.json generation correctly grab otherwise implicit dependencies. Prebuilt rlibs may include several dependency rlibs. Without a link_dirs attribute, every dependency (even if unexported) would need a separate module. Previously we were casing out on exact structs, which might be OK when libraryDecorator and procMacroDecorator were the only possibilities, but repeating the logic for three types is too much. Using an interface makes this logic scale better. Bug: 159591910 Test: cd external/rust; mma; m crosvm.experimental Change-Id: Ia1124e09f48cd05e39f094bbcb988622ebd2272f
2020-07-01rust: Mutate prebuilt modules dylib/rlibMatthew Maurer
This change makes it possible to use a single module to provide both dylib and rlib varieties of a library. This allows the use of libstd and libtest from a rustlibs property, allowing linkage type to change for different variants. Bug: 159718669 Test: cd external crates; mma; m crosvm.experimental Change-Id: I477c4d2faec63703fdc6dd42ba020747d6a50714
2020-07-01rust: Add rustlibs auto dependency selectionMatthew Maurer
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
2020-07-01Merge "Explicitly define Rust default lints"Thiébaud Weksteen
2020-07-01Explicitly define Rust default lintsThiébaud Weksteen
Add documentation on how lints are defined and used in Android. Merge the deny_warnings attribute with a new attribute (no_lint) which can be used to disable the default linting parameters. Explicitly allow all lints for external/ and prebuilts/, which remove any warning when building sysroot for the devices. Test: cd external/rust/crates; mma Test: add dummy internal Rust module; mma Change-Id: I62be1c41aeda4068fb9e288038727c1de5ffe547
2020-06-24Remove moduleContextImpl structThiébaud Weksteen
The moduleContextImpl structure contains duplicate information on the contexts. BaseModuleContext, ModuleContext and DepsContext can already surface which Module is being processed via Module(). Because most of the Rust-specific methods on the *Context structures simply forward to the Module methods, expose a RustModule() method. Test: cd external/rust/crates; mma Change-Id: Ifee90825d54081fc5e9a8df0b7c4580412e9158c
2020-06-16[Rust] Remove unused variables and deduplicate.Ivan Lozano
Bug: 158731826 Test: cd external/rust/crates; mma Change-Id: I8c9e5cfeaf941b9676b92451b227c15db9a41bbc
2020-05-05Add gcov coverage support to Rust modules.Ivan Lozano
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
2020-04-29Provide 32-bit and 64-bit Rust libs by default.Ivan Lozano
CC libraries which depend on Rust libraries get missing dependency errors when building 32-bit variants dependent on Rust modules which don't explicitly have "multilib: both" declared. Because CC libraries use MultilibBoth by default, Rust should do the same. This also fixes a bug where the ARM32 toolchain incorrectly embedded toolchain64Bit instead of toolchain32Bit. Bug: 154730212 Test: Rust libraries provide both variants by default. Change-Id: Ia545fe069d3c6b77c3d18f4f10267e2c72ee0bab
2020-04-07Fix incorrect Rust installation paths.Ivan Lozano
Rust binaries were installing to the wrong paths. This fixes the install path by only including the archtype subdir when there's a multilib conflict for that archtype. Bug: 153423714 Test: Example rust module installs to expected path. Change-Id: I63ea1ce7dae0d97d65522e0917d916b44808f442
2019-12-13Install rust tests under nativetest(64)Chih-Hung Hsieh
* 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
2019-11-14Merge changes from topic "rust-sysroot"Jeffrey Vander Stoep
* changes: Enable x86_64 device support Build Rust Device Sysroots in Soong
2019-11-13Build Rust Device Sysroots in SoongMatthew Maurer
In order to ensure we are using current platform Bionic for any platform Rust binaries, we need to build the sysroot in Soong. This will also enable us too hook the "test" crate if necessary. While both a dynamic and static sysroot are available, on device only a dynamic sysroot will be injected. On host, we continue using the sysroot used to build the compiler as before. Bug: 139486496 Change-Id: I127377e5b056610ceb5015a34d266250320fbc31
2019-11-04Enforce correct rust library file names.Ivan Lozano
rustc expects libraries and proc_macro filenames to conform to a particular format, alphanumeric with underscores and lib${crate_name}.*. Enforce this with a check when getStem() is called. This makes the crate_name property required for proc_macros and libraries. This also removes the notion of a default crate name derived from the module name. It's not needed for binaries, so this won't impact them. Bug: 143579265 Test: m -j crosvm.experimental Change-Id: I2770cf7d02dd4291c3d240d58d242b940098dcee