Commit graph

109 commits

Author SHA1 Message Date
Cole Faust
fdec8723d5 Convert some properties to Configurable properties
Focusing on the properties needed to remove soong config modules from
packages/modules/Virtualization.

- prebuilt_etc's src and srcs
- filegroup's srcs and exclude_srcs
- rust's cfgs

Bug: 342006386
Test: m nothing --no-skip-soong-tests
Change-Id: I6971da744a17955f98104948e6f9614776955782
2024-05-22 13:33:42 -07:00
Ivan Lozano
ab58647b2e rust: Add an option to disable LTO for Rust
This adds an option to disable LTO when building a Rust module. This is
mostly intended to speedu p local prototyping, and LTO should not
normally be disabled for production builds.

Bug: 339628497
Test: m blueprint_tests && m rust
Change-Id: I21d5d4513a259a56f101ce8906e2bef7404e4efb
2024-05-17 10:11:57 -04:00
Ivan Lozano
28ed8f4f83 rust: refactored transformSrctoCrate
Refactor transformSrctoCrate and the functions it calls to not rely
on rust.ModuleContext, preparing it to be callable from soong-cc
context to build a Rust staticlib.

This also refactors out common default flags used when building
libraries, again to prepare for building a Rust staticlib from
a soong-cc context.

Bug: 254469782
Test: m blueprint_tests && m
Change-Id: I678f6fee989c61bb15c340b9887e4d1934991907
2024-05-16 10:32:08 -04:00
Andrew Walbran
52533237ef Add aliases property for renaming Rust dependencies.
This is equivalent to specifying a dependency name different to the
package name in cargo, which some external crates do.

Bug: 308790322
Test: Built libgrpcio with aliases for protobuf
Change-Id: I2801222051fdd962460cc7f4900cec357f63b974
2024-03-19 17:27:46 +00:00
Kiyoung Kim
aa39480d21 Split usage of UseVndk
UseVndk is a function to check if the module can use VNDK libraries, but
this function was also used to check if the module is installed in the
treblelized partition (vendor or product). As of VNDK deprecation,
UseVndk funtion will return false even when the module is installed in
vendor / product partition, so we need a separated function to check
this. This change introduces a new function 'InVendorOrProduct' which
replaces UseVndk based on its usage.

Bug: 316829758
Test: m nothing --no-skip-soong-tests passed
Change-Id: Ic61fcd16c4554c355f6005894a4519b044b27fe5
2024-01-09 11:37:14 +09:00
Colin Cross
5c1d5fb21b Move test data installation to Soong
To generate module-info.json in Soong for b/309006256 Soong needs to
know the test data paths. Moving test data installation into Soong will
also help later for test suite packaging.

Add ModuleContext.InstallTestData that installs the files listed in a
[]DataPath alongside the test.  The files will also be passed to Make
to allow it to continue packaging them into the test suites for now.

Update the module types that are producing LOCAL_TEST_DATA entries
in their Android.mk files to go through InstallTestData instead.

Bug: 311428265
Test: atest --host toybox-gtests --test-timeout=120000
Change-Id: Ia8b964f86e584ea464667fd86a48d754d118bead
2023-11-30 13:38:49 -08:00
Matthew Maurer
b103659c0b Merge changes I0caddbf6,Iee20b060,I6c92580b,I45028945,Ia7dd5220, ... into main
* changes:
  rust: Resolve crate roots outside rust-project
  rust: Cache crateRootPath to avoid ctx
  rust: internalize srcPathFromModuleSrcs
  rust: move crateRootPath to compiler
  rust: Privatize Cargo* methods on compiler
  rust: Move compiler interface to compiler.go
2023-11-22 20:37:27 +00:00
Matthew Maurer
db72f7ed80 rust: Resolve crate roots outside rust-project
Previously, we manually re-computed crate roots inside project_json for
rendering rust-project.json. In addition to added complexity, this meant
that generated sources and glob sources would not render correctly - it
would select e.g. `src/**.rs` or `:foo` as a crate root.

Use a centralized computation of crate roots instead.

Bug: 309943184
Test: SOONG_GEN_RUST_PROJECT=1 m nothing, compare rust-project.json
Change-Id: I0caddbf600d025a0041f45e69812cdd6f1761234
2023-11-22 00:52:34 +00:00
Matthew Maurer
a28404a7b0 rust: Cache crateRootPath to avoid ctx
This makes it possible to call crateRootPath in situations where a
ModuleContext is unavailable.

Test: m nothing
Bug: 309943184
Change-Id: Iee20b0606954a18ca516cdac40917d0016f94a05
2023-11-22 00:52:14 +00:00
Matthew Maurer
1d8e20d744 rust: internalize srcPathFromModuleSrcs
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
2023-11-22 00:52:10 +00:00
Matthew Maurer
d221d31534 rust: move crateRootPath to compiler
Test: m nothing
Bug: 309943184
Change-Id: I45028945357c394301d93ca7995a4f9adf281931
2023-11-20 21:02:40 +00:00
Matthew Maurer
cd41653b96 rust: Privatize Cargo* methods on compiler
These methods aren't used outside, and probably shouldn't be.

Bug: 309943184
Test: m nothing
Change-Id: Ia7dd5220ccd10c0136aa16f5e21149eaf7a03ea1
2023-11-20 20:25:27 +00:00
Matthew Maurer
689d6f63e4 rust: Move compiler interface to compiler.go
Refactor cleanup

Bug: 309943184
Test: m nothing
Change-Id: I7dcb0af64a4db71fdc46c0876b22e5015c02438e
2023-11-20 17:49:25 +00:00
Ivan Lozano
c518202e28 rust: Allow no_stdlibs per-target variants.
stdlibs can be set per-target, it makes to sense to allow no_stdlibs to
be set per-target as well.

Bug: 310924208
Test: Android.bp with per-target no_stdlibs builds.
Change-Id: I1c3a458a849367d2c363bd5f65af77b8cce8c0e0
2023-11-14 10:40:08 -05:00
Vinh Tran
50de8becd1 Export rust flags to bazel
Bug: 290790800
Test: Inspect out/soong/soong_inspection folder after running `m bp2build`
Change-Id: Iffc43a540f67e5f07d109a0a87f3248fae035267
2023-10-04 13:14:32 -04:00
Colin Cross
e18bd2097b Don't pass -lrt or -lgcc_s to darwin rust compiles
Fix mac builds by removing the -lrt and -lgcc_s flags from darwin
rust compiles.

Bug: 293349612
Test: builds
Change-Id: I99a9fea963761730efc4d3236135ee6d83dbca57
2023-10-03 21:45:33 -07:00
Colin Cross
004bd3f526 Revert "Split Rust crate builds into compile and link phases."
This reverts commit e7c71c344d.
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
2023-10-02 22:15:55 -07:00
Sam Delmerico
63ca14e9b7 Revert^4 "add crate_root property to rust modules"
9c64274b27

Change-Id: I1c4dad76842cebf18cd82e04e435910f09038d07
2023-09-25 12:13:17 +00:00
Wen-yi Chu
9c64274b27 Revert^3 "add crate_root property to rust modules"
60375c4adf

Change-Id: I356e936139592893a47d4c6b9e747f24470b11f9
2023-09-22 22:05:54 +00:00
Wen-yi Chu
41326c1f41 Revert "support sandboxed rust rules"
Revert submission 2629131-sandbox-rust-inputs

Reason for revert: Fail on android build.

Reverted changes: /q/submissionid:2629131-sandbox-rust-inputs

Change-Id: Ifd9aa46e80a12d8f4ffa0a2daa74b96727cbb7e6
2023-09-22 22:05:54 +00:00
Sam Delmerico
a588d153c8 support sandboxed rust rules
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
2023-09-15 22:46:56 +00:00
Sam Delmerico
60375c4adf Revert^2 "add crate_root property to rust modules"
5162ff14fc

Change-Id: I9a76df938639676ee4aa7bdd2b2902e0e6df08d5
2023-09-15 22:41:51 +00:00
Sam Delmerico
5162ff14fc Revert "add crate_root property to rust modules"
Revert submission 2605644-rulebuilder-ninja-vars

Reason for revert: b/299568218

Reverted changes: /q/submissionid:2605644-rulebuilder-ninja-vars

Change-Id: I17645fcff117909c09a016157235805f0974340b
2023-09-08 16:10:47 +00:00
Sam Delmerico
553edff9dd add crate_root property to rust modules
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-31 18:03:33 +00:00
Ivan Lozano
b0e1035417 Merge "rust: Add support for host fuzzers." into main 2023-08-16 14:07:19 +00:00
Vinh Tran
4eeb2a9514 Remove dylibs prop from rust module types
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-14 14:03:28 -04:00
Ivan Lozano
2fcbffa4a1 rust: Add support for host fuzzers.
Adds support for host-based Rust fuzzers.

Bug: 282897366
Test: SANITZE_HOST="address" m <host_fuzzer>
Test: run fuzzer
Change-Id: Ibb951f651ef12e763778ebbf12e66769a7113920
2023-08-10 09:48:13 -04:00
Matthew Maurer
65a54a8e3d rust: Set android_vendor and android_product cfg
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-24 19:21:08 +00:00
Ivan Lozano
9ef9cb8b3f rust: Fix coverage in no-std crates
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-02-14 11:04:21 -05:00
Colin Cross
225a37a7f0 Use the same rpaths for tests and binaries and cc and rust
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
2023-01-11 16:04:19 -08:00
Martin Geisler
46329e9ba4 Remove spurious trailing backslash in prefer_rlib docstring
Change-Id: I851306c73cb86df4bc4c82c3471ce3b6eaad9ded
2022-09-29 13:12:27 +00:00
Colin Cross
a8941ec69f Don't use prebuilt rust stdlibs for linux bionic
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-01 18:30:17 +00:00
Colin Cross
567d342ed8 Use musl rust prebuilts for USE_HOST_MUSL=true
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-07-01 02:58:14 +00:00
Sasha Smundak
a76acba553 Add cross-referencing support for Rust
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-04-20 20:02:28 -07:00
Andrew Walbran
797e4be221 Add stdlibs property for Rust build rules.
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-03-07 15:42:34 +00:00
Colin Cross
e32f093120 Support building rust modules against musl libc
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-24 17:33:05 -08:00
Ivan Lozano
fba2aa255c rust: Support new rust_stdlib_prebuilt_host type
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-12 08:58:17 -05:00
Ivan Lozano
8d10fc39af rust: Refactor stripped output file path
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-09 21:43:58 -05:00
Seth Moore
3afac0b36f Flag an error on empty rust module srcs
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-10-14 15:25:07 +00:00
Ivan Lozano
67eada34db rust: Refactor cfg and feature flag calculation
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-09-23 12:21:04 -04:00
Matthew Maurer
9f59e8db27 rust: Hook up InstallIn functions + Product
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-20 12:14:54 -07:00
Ivan Lozano
0ad64f50fd Merge "rust: Allow modules to use only generated sources" 2021-08-13 19:37:04 +00:00
Ivan Lozano
e4db0036d7 rust: Allow modules to use only generated sources
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-13 13:37:19 -04:00
Ivan Lozano
8711c5cf8c rust: Link libunwind into Rust static executables.
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-13 13:15:31 -04:00
Ivan Lozano
a9a1fc0747 rust: Add support to emit certain Cargo env vars.
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-08-12 13:18:34 +00:00
Ivan Lozano
45a9e3196c rust: Prevent manually defined lib link flags.
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-27 15:05:13 -04:00
Colin Cross
0c66bc615b Replace android.BuildOs with Config.BuildOS
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-20 12:46:48 -07:00
Liz Kammer
187d5445e8 Remove IsDependencyRoot from interface
This is equivalent to Binary() -- reduce the interface and improve
clarity.

Test: go test soong tests
Change-Id: I770f5ce79fd4d888586d31ec5e67be88153626b6
2021-07-07 16:29:09 -04:00
Ivan Lozano
d7586b6526 Refactor vendor snapshot to use LinkableInterface.
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-05-12 14:01:10 -04:00
Treehugger Robot
f9b3e22293 Merge "Remove unnecessary android:"path" tags in rust" 2021-04-21 15:53:44 +00:00