summaryrefslogtreecommitdiff
path: root/rust/library.go
AgeCommit message (Collapse)Author
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-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-07-31[rust] Clean up unused link variations. Ivan Lozano
rust_library modules no longer produce "link" variants alongside "rust_libraries" variants as the former have been moved to rust_ffi modules. rust_library modules however still create empty link variants and code paths still assume that modules can support both rust linkage and cc linkage. This adds unnecessary complexity that no longer serves a purpose. This cleans this up by removing the unused "link" variant for rust_library modules and simplifies code paths that can now assume modules are either a rust library or a cc library, but not both. This also fixes a bug where Shared() was returning the wrong value. Bug: 159064919 Test: cd external/rust/; mma Test: cd external/crosvm/; mma Change-Id: I3b5498c80b315c56b621dcb1388022fecc1bfc1b
2020-07-29Merge changes I4efdf333,I4abaf8e7 Ivan Lozano
* changes: Ensure hermetic device rust_bindgen. Generate deps file for rust_bindgen modules.
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-22Enforce correct variant usage for rust_bindgen. Ivan Lozano
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
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 list Chih-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 unconditionally Matthew 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/rlib Matthew 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 selection Matthew 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-01rust: Change default variants Matthew Maurer
rust_library now produces only rlib and dylib variants. rust_library_foreign now produces static and shared variants. This change was made because both are common cases, but all four together essentially never happens. This allows us to have fewer repeat module definitions. Bug: 143217452 Test: cd external/rust; mma Change-Id: Iaf69e8da38f7c12710331c51464699cf7cbbb656
2020-06-24Remove moduleContextImpl struct ThiƩ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-19Merge "[Rust] cdylibs can now link against dylibs." Treehugger Robot
2020-06-19[Rust] cdylibs can now link against dylibs. Ivan Lozano
Bug: 144861059 Test: cd external/rust/crates; mma Test: Manual verification through ldd that libstd is a dependency Change-Id: I603cf519215317aa8c400cd0f6ebb1b58f5bcf15
2020-06-16[Rust] Remove unused variables and deduplicate. Ivan Lozano
Bug: 158731826 Test: cd external/rust/crates; mma Change-Id: I8c9e5cfeaf941b9676b92451b227c15db9a41bbc
2020-06-09Specify SONAME when building Rust shared libs. Ivan Lozano
Without specifying -soname, cc binaries are unable to locate Rust provided shared libraries. This adds the -soname linker flag for shared libraries. Bug: 158490355 Test: readelf -d <cc_binary> shows the expected SONAME Change-Id: I66852a7ce24d5ea5e426f11bc1834fb56a150628
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-07Add crtbegin_so/crtend_so to Bionic Rust libraries. Ivan Lozano
Bug: 153430438 Test: Example library no longer experiences linkage errors during build. Change-Id: I73870a68693415b37c9b7bf051b1879bcb8df0c6
2020-01-15rust: Do not pass -C prefer-dynamic for cdylib Matthew Maurer
cdylib targets cannot currently dynamically link to Rust crates, so this flag was not actually doing anything, and in conjunction with -C lto which we *do* want on for this target, causes a hard error on rustc-1.40.0. Bug: 147438124 Test: Build a rust_library module, this implicitly tries to build cdylib Change-Id: I828b3e6bae7c58f4081db3e73009b443a382a296
2020-01-15rust: Include Soong module name as metadata Matthew Maurer
If we want to build a component which uses two versions of a crate in the dependency graph (for example, libc in std and libc from external/crates), Rust requires at least one of them have a metadata field to differentiate them. Since Soong module names should be distinct for a given target, they should serve as metadata. Bug: 147397356 Test: Build a rust library with "rlibs: ["liblibc"]" in the blueprint Change-Id: I5d85ea8b3197972c09de301c9523efaff08adf81
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-21Change stdlib linkage for C libraries. Ivan Lozano
Rust C libraries cannot currently depend on dylibs. This prevents device libraries from attempting to link the stdlib dynamically, instead using rlibs. Bug: 144861059 Test: Simple Rust library compiles as a shared/static library. Change-Id: I38e5aae90e50ddcc5fc72d5a8d1820d92955cf48
2019-11-14Allow cc modules to pull in rust includes. Ivan Lozano
Make sure LinkabeInterfaces can export include dirs to cc modules. This fixes the Rust implementation and makes sure these are pulled in for cc modules. Bug: 144052093 Test: cc module depending on a rust library includes dirs correctly. Change-Id: I6b5d5e6ab6afb507178b4f2cbdc45f01031dbfe4
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
2019-10-28Add support for Rust C libraries. Ivan Lozano
Adds the ability for rust modules to be compiled as C libraries, and allows cc modules to depend on these rust-generated modules. This also means that soong-rust should not have any dependencies on soong-cc aside from what's required for testing. There's a couple small fixes included as well: - A bug in libNameFromFilePath that caused issues when library's had "lib" in their name. - VariantName is removed from rust library MutatedProperties since this was unused. Bug: 140726209 Test: Soong tests pass. Test: Example cc_binary can include a rust shared library as a dep. Test: m crosvm.experimental Change-Id: Ia7deed1345d2423001089014cc65ce7934123da4
2019-09-24Add AArch64 device Rust toolchain. Ivan Lozano
Bug: 141207434 Test: build example rust device module. Change-Id: I0932a614942bf4a4d4b6c153fcc4fc79c7f202bd
2019-08-28Add Rust support to Soong. Ivan Lozano
Adds support to Soong for building rust modules. This currently only supports x86_64 device and x86 linux host targets. The functionality is sufficient to build crosvm. Bug: 136189233 Test: Test module builds. Test: crosvm builds. Change-Id: I6ea04615834a6d673578ab10ea1a2eb04259fe09