Commit graph

264 commits

Author SHA1 Message Date
Spandan Das
0c7ea9582a Merge "Build rust libraries against C ModuleLib API surface." 2023-03-21 17:22:23 +00:00
Spandan Das
604f376dcf Build rust libraries against C ModuleLib API surface.
Previously, rust libs in platform would build against stubs even if the
dependency was part of platform. Port the correct logic from the
recently implemented aosp/2421967

Test: TH

Change-Id: I7f6a0ca24654b4424d2f4cfcef2d15e15b1298fc
2023-03-16 23:17:36 +00:00
Justin Yun
24b246a7a8 Fix the make name of rust snapshots
Rust snapshot must have proper suffix for androidmk to avoid conflict
with the existing modules.

Bug: 230780263
Bug: 235895567
Test: m nothing
Change-Id: I35794196553621cd722c067d7965b2a61aa351bd
2023-03-16 11:05:41 +09:00
Liz Kammer
884fe9e174 Update non-user-facing properties to be mutated
Test: m nothing
Test: CI
Change-Id: Ibfbb91653fa36277a19555a39a5df8da27a7a765
2023-02-28 14:29:13 -05: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
Ivan Lozano
0f9963e9e4 Copy Rust fuzzer dependencies to /data.
Fix an issue where rust_fuzz modules were
not correctly packaging and copying their
dependencies.

This is done by extending the CC fuzz packager
to simply handle both Rust and CC modules,
ensuring this doesn't get out of sync again.
Fuzzer related functions are added to the
Linkable interface to facilitate this.

There was a bug where the Make definitions for
Rust fuzzers were not being created as well,
and that is addressed here.

Bug: 249551848
Test: m android_log_fuzzer #check $OUT/data/fuzz/arm64/libs
Change-Id: I9b41153e0cf08ab510476b75003c3a3baccc3858
2023-02-06 13:48:23 -05:00
Jihoon Kang
0b5f7f153f Merge "Specify jnilib partition in Android-<target>.mk" 2022-10-05 16:19:51 +00:00
Jihoon Kang
f78a890183 Specify jnilib partition in Android-<target>.mk
Context
- Android-<target>.mk currently does not contain information about partition for its dependent unembedded jni libraries, but only lists the name of the unembedded jni libraries.
- If an android_app module depends on an unembedded jni library that is located in a different partition, make cannot find the library.

Implementation
- Create a string field partition in jniLib struct.
- Add variable "LOCAL_SOONG_JNI_LIBS_PARTITION_<target>", an array of mappings of the name of the jni library to its partition.

Bug: 154162945
Test: m
Change-Id: I6b8e1272ff59dc70e3dd6ce8c6c8e4686dad76df
2022-10-04 03:26:05 +00:00
Matthew Maurer
581b6d82ab rust: Don't propagate apex across customBindgenTag
customBindgenTag is used to describe a particular host tool - don't
propagate apex dependency across it.

Bug: 249849807
Test: Adding rusqlite to apex no longer requires bindgen allowed
Change-Id: Ifcb2a94c577c72558f757bf10e975212558fe790
2022-09-29 16:46:25 -07:00
Treehugger Robot
3a4088dfd1 Merge "Introduce cc_api_library" 2022-08-10 04:12:32 +00:00
Kiyoung Kim
487689eaee Introduce cc_api_library
Introduce cc_api_library, which reflects imported API from other
inner-tree. This cc_api_library module type will later refer from
the other ninja module which generates stub library from the interface
description.

Tested environment :
* original libc definition has been removed temporarily, to ensure that
  imported api stub library is being used from build
* Added new definition of libc as below
 cc_api_library {
  name: "libc",
  arch: {
    x86: {
      src: "libs/x86/libc.so",
    },
    x86_64: {
      src: "libs/x86_64/libc.so",
    },
  },
  header_libs: [
    "libc_headers",
  ],
  export_header_lib_headers: ["libc_headers"],
  min_sdk_version: "9",
  vendor_available: true,
 }

Bug: 236087698
Test: `ALLOW_MISSING_DEPENDENCIES=true m vendorimage` succeeded
Change-Id: I67070b0f3561aa2afd73b6c1c0fdf4255218baac
2022-08-10 10:12:18 +09:00
Matthew Maurer
cf3844c879 rust: Rust is now GA for platform usage
Rust is now approved for general platform use without project-specific
review.

Bug: 240501326
Test: m
Change-Id: I6fd4c22ba2c6a3a5bac6f91fd087fe5cffe46c01
2022-07-28 06:57:26 -07:00
Ivan Lozano
7f67c2a665 rust: Allow rust_ffi_shared in jni_libs
Allow listing rust_ffi_shared modules as a jni_libs dependency
in conjunction with platform_api: true. This allows inclusion by
android_app modules.

Bug: 237304791
Test: android_app module builds with a rust_ffi_shared dependency.
Change-Id: I3a28e1baa522ad8f9c2aa86f1d23b19ce9f967e1
2022-06-27 16:00:26 -04: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
Ivan Lozano
3736abfa01 Merge "rust: Allow rustlibs to fallback to rlibs." 2022-04-18 18:53:58 +00:00
Ivan Lozano
f1868af5d5 rust: Don't append '.vendor' to vendor modules.
Rust vendor-only modules would have the '.vendor' subname appended to
them, which meant that 'm <vendor_module>' would not work -- instead
you would need to call 'm <vendor_module>.vendor', which leads to some
confusion.

This CL fixes the behavior by using the same SubName logic as the cc
module.

Bug: 205577906
Test: m <vendor_module> # works without .vendor suffix
Change-Id: I6ba18ce1d7281a1f8342ed6014644b48009d78e0
2022-04-12 13:42:04 -04:00
Ivan Lozano
2d407633ae rust: Allow rustlibs to fallback to rlibs.
Allow adding rlib-only libraries to rustlibs by having it fallback to
selecting the rlib variant if a dylib variant is requested but not
available.

Bug: 224771894
Test: m nothing
Test: New Soong test
Change-Id: I47b19ec9dbf3da90a2b090aeda04556a0400c7d1
2022-04-12 11:30:40 -04:00
Ivan Lozano
872d579a22 rust: rust_proc_macro host snapshot support.
Adds support for capturing rust_proc_macros as part of the host
snapshot. Proc macros target the host and can be thought of as compiler
plugins. Because of this, they don't have vendor image variants and
can't be easily captured as part of the vendor snapshot. Instead we
capture them as part of the host snapshot.

This adds a rust_prebuilt_proc_macro module type.

Bug: 204304380
Test: m HOST_FAKE_SNAPSHOT_ENABLE=true host-fake-snapshot dist
Test: python3 development/vendor_snapshot/update.py --image=host
  --install-dir=vendor/vendor_name/ 31 --local out/dist
Test: Checked Android.bp for rust_prebuilt_proc_macro modules.
Change-Id: I4a8c4d9c41b7ca361b5b97d3f74973918c2a5fe3
2022-03-25 09:25:07 -04: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
Justin Yun
2b3ed6403c Fix rust snapshot to capture static libs correctly
SnapshotStaticLibs must include static libs, but it had shared libs.

Bug: 219746113
Test: build vendor snapshot
Change-Id: I0660811bb94446129ae97f52306b065dec73cabd
2022-02-16 08:15:07 +09:00
Treehugger Robot
6bf833f428 Merge changes from topic "musl_rust"
* changes:
  Support building rust modules against musl libc
  Support genrules as CrtBegin and CrtEnd in rust
  Support multiple crtbegin and crtend dependencies
2022-01-27 21:39:18 +00:00
Colin Cross
018cbebd71 Support genrules as CrtBegin and CrtEnd in rust
Musl will use a genrule output as a linker script in CrtBegin,
support genrules as Crt* dependencies.

This is equivalent to Ie384089d26459797d0b4b5fef84846507fc508ad
in cc.

Bug: 216192129
Test: m USE_HOST_MUSL=true host-native
Change-Id: Ibc08fdcff7a6bca2a1ec05b781ce929080e211bd
2022-01-24 17:33:05 -08:00
Colin Cross
fe605e14ee Support multiple crtbegin and crtend dependencies
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
2022-01-24 17:33:05 -08:00
Yi Kong
46c6e59415 AFDO for Rust
Bug: 195134194
Bug: 165018530
Test: build
Change-Id: I30932a22dc0b22716cdc925a3fcc5f9a169fcec4
2022-01-21 18:13:18 +08:00
Ivan Lozano
a91ba25464 rust: Fix exported MinSdkVersion
The exported rust.MinSdkVersion always returns an empty string. Instead
it should return the Min_sdk_version property like rust.minSdkVersion.

This CL renames minSdkVersion to MinSdkVersion so the exported function
has the correct behavior.

Bug: 211858959
Test: m
Change-Id: I4fecfba711c0d3d7a22f4fdf7684924a9457b464
Merged-In: I4fecfba711c0d3d7a22f4fdf7684924a9457b464
2022-01-14 19:57:55 +00:00
Treehugger Robot
9b3b15c382 Merge "rust: Register rustdoc with checkbuild" 2022-01-05 21:54:40 +00:00
Colin Cross
c68db4b305 Remove InstallBypassMake and ToMakePath
InstallBypassMake and ToMakePath are obsolete, remove them.

Bug: 204136549
Test: m checkbuild
Change-Id: Ie5a6f7254b3d317ed6039e114ed6aec35e1ce273
2021-12-15 15:22:53 -08:00
Colin Cross
65cb314c92 Revert^2 "Add dependency license annotations"
abe2a4b7bf

Change-Id: Ibcd16b5b779a4e6d4372dab9d21de76abae9ca9c
2021-12-10 23:05:02 +00:00
Colin Cross
abe2a4b7bf Revert "Add dependency license annotations"
Revert submission 1899703

Reason for revert: b/210158272
Reverted Changes:
I142c19284:Reuse license metadata files from Soong
Ife89b8f23:Add dependency license annotations
I8e7410837:Build license metadata files in Soong

Change-Id: I51f33ae67311a3cff00d3e581d24c9a3411b7131
2021-12-10 23:02:41 +00:00
Matthew Maurer
e3803630c2 rust: Register rustdoc with checkbuild
Bug: 197237709
Test: m checkbuild, manually verify rustdoc targets built
Change-Id: Icfcc4a8c1bc7de4c5e1abbe495646504490ac927
2021-12-10 21:59:15 +00:00
Colin Cross
b674b43656 Add dependency license annotations
Add annotations to dependency tags that are dynamic or classpath
linkage.

Bug: 207445310
Test: m checkbuild
Change-Id: Ife89b8f234aa40c380c721eda7dd18cab697fbb3
2021-12-08 15:08:59 -08:00
Ivan Lozano
9fdba2844e Merge "rust: Add rust_toolchain_library module." 2021-11-17 16:59:15 +00:00
Ivan Lozano
45e0e5b012 rust: Add rust_toolchain_library module.
Adds a new rust_toolchain_library module, a module which can compute the
source path from the toolchain root.

Bug: 140642453
Test: m

Change-Id: I2d90722880279533eb93d2d946ac8c31fc0b1835
2021-11-16 08:51:48 -05:00
Ivan Lozano
b993a835c3 Merge "rust: Add data_libs and data_bins to rust_test" 2021-11-16 13:46:49 +00:00
Ivan Lozano
4e5f07d27b rust: Add data_libs and data_bins to rust_test
Allows defining data binaries and libraries that should be installed
alongside a rust_test module, similar to cc_test.

This refactors cc_test as well so it can define rust_ffi_shared and
rust_binary modules as data.

Bug: 171710847
Test: New Soong tests pass.
Test: Example module installs data appropriately.
Change-Id: I0b56098fb475ec54f9b7a761220d260fe68cbee1
2021-11-15 17:18:42 -05: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
aa1a9e4086 Merge "rust: Refactor stripped output file path" 2021-11-10 21:34:21 +00:00
Ivan Lozano
e950cdad6d rust: Add missing variation -D flags to bindgen.
rust_bindgen calls are missing a large set of -D cflags which control
how headers are interpretted for certain variations (such as
-D__ANDROID_VNDK__). This CL introduces the full set of these flags.

Bug: 205609024
Test: rust_bindgen vendor variant builds correctly.

Change-Id: Id781c1f88352e9c238c49619f0dce20f804cfc77
2021-11-10 13:28:55 -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
Colin Cross
7743557a23 Move rust module installation into Soong
Move rust module installation rules into Soong by overriding
InstallBypassMake.

Bug: 204136549
Bug: 205530905
Test: m checkbuild
Test: m && acloud create --local-instance --local-image
Change-Id: Icc00c4ea5d91ae489c1d9d3b66a072c9de86c717
2021-11-08 13:31:51 -08:00
Ivan Lozano
7b0781d14c rust: Emit toc files for cdylibs
Write toc files that list the exported symbols so dependents are
only rebuilt if the exported symbols change.

This exports the CC function TransformSharedObjectToToc, and also
removes an unused arg from its signature.

Bug: 178185435
Test: New Soong test passes.
Test: m <toc file path>
Change-Id: I7ab69bf7e7f32f25eb4c7ca9d18d877dac1511db
2021-11-03 15:34:50 -04:00
Ivan Lozano
21fa0a5844 rust: Add common interface for binaries
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
2021-11-01 14:57:44 -04:00
Ivan Lozano
fdadcd7937 rust: Support whole static libraries with any name
This CL allows binaries to depend on whole static libraries which
don't begin with the 'lib' prefix.

Bug: 170672854
Test: Whole static library that doesn't have lib prefix can be linked
Change-Id: I908496d9369c7bec3232e2feed0599f6cf6d9383
2021-11-01 14:56:59 -04:00
Ivan Lozano
39b0bf0326 rust: Package shared libraries with fuzzer zips
Rust fuzzers were not packaging up their CC shared dependencies.
This would lead to fuzzers using the shared libraries included on
system, which may not be sanitized, leading to incorrect behavior.

This refactors the relevant code from CC and calls it from the Rust
build logic.

Bug: 202282599
Test: output rust fuzzer zip file includes shared dependencies.
Change-Id: I92196eb0141733797a67eae24f8e9aedea94c3bc
2021-10-14 15:31:47 -04:00
Jiyong Park
d1e366a072 Installation routine for rust is similar to that of cc
This change makes the installation routine for rust be similar to that
of cc. Previously, rust.baseCompiler.install() (which internally calls
android.ModuleContext.InstallFile()) was not called when the module is
not installable. Although this may sound right at first glance, it is a
behavior different from that of cc and prevents an uninstallable rust
module from being packaged into a packaging module like
android_filesystem. This is because the packaging happens inside
InstallFile().

Fixing the issue by following the behavior of cc modules; Call
HideFromMake() or SkipInstall() when a rust module is not installable,
but call InstallFile() as long as the output file is valid.
InstallFile() internally skips the installation (but the packaging) when
HideFromMake() or SkipInstall() was called.

Bug: N/A
Test: atest MicrodroidHostTestCases
Change-Id: I15f4adc8544dac53647647d8bc4273f9f4acbeb2
2021-10-05 09:12:41 +09:00
Jiyong Park
2811e07868 rust modules respects the installable property
So far, the property wasn't respected.

Bug: N/A
Test: m
Change-Id: Ie3b011250595f02c3ab315efbac6694df3e181e7
2021-09-30 17:25:21 +09: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
Matthew Maurer
c6868383f4 Support Rust in Ramdisk
Bug: 178565008
Bug: 165791368
Test: Build and link a Rust library into a ramdisk binary
Change-Id: I9682b978936624133e5a62e94caace0e8958fd0f
2021-08-17 15:08:49 -07:00
Matthew Maurer
a61e31f66a Support Rust in native-bridge
Bug: 178565008
Bug: 165791368
Test: Build and link a Rust library into a native-bridge binary
Change-Id: I3546571530529203d9dbfd62777f20de18c6bd51
2021-08-17 15:08:49 -07:00
Matthew Maurer
52af5b052b Support Rust in Product
Bug: 178565008
Bug: 165791368
Test: Build and link a Rust library into a product binary
Change-Id: I9c5aa5f3a1f323af9aa2aee804635045f1b91bd4
2021-08-17 15:08:49 -07:00
Matthew Maurer
460ee9429e Support Rust in Recovery
Bug: 178565008
Bug: 165791368
Test: Build and link a Rust library into a recovery binary
Change-Id: I1c76e6204019443c567082730a4cf680f4a2a74a
2021-08-17 15:08:49 -07:00
Ivan Lozano
dd7107c84b Merge "rust: Add support to emit certain Cargo env vars." 2021-08-12 17:05:39 +00: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
hamzeh
c0a671fc80 Moving common fuzzing code to fuzz package
Test: make haiku and make haiku-rust
Change-Id: Ife80cc10672f51bd6afbae7061cc9373a2a15e7d
2021-08-11 23:54:15 +00:00
Treehugger Robot
40fa08bfa7 Merge "Add a phony target for all Rust targets" 2021-07-23 20:28:02 +00:00
Chris Wailes
74be764496 Add a phony target for all Rust targets
Test: m rust
Change-Id: Id347edf9998f6714622c9f173420477a9e534723
2021-07-23 10:38:01 -07:00
Ivan Lozano
a2268635f4 rust: Add support for bootstrap linker.
Adds the 'bootstrap' property to Rust modules to set the linker to the
bootstrap linker.

Bug: 194276829
Test: set bootstrap: true on module, checked .interp section on output.
Test: bootstrapped binary runs.
Change-Id: I459c8194902cfea3c44b060e70d28a43fcba3ade
2021-07-22 14:23:27 -04:00
hamzeh
41ad881e16 Refactoring fuzz packaging code
Rust and cc fuzz packaging have common. This change is to put this
common methods and fields into fuzz_common.

Test: make haiku and make haiku-rust ran locally and verify corpus,
dict and config are packaged along with the executable.

Change-Id: I04bf535cd2597ed8b2bd3d8e6ea8c28f38bdc18b
2021-07-16 17:43:33 -07:00
Paul Duffin
d5cf92e298 Support customizing behavior around sourceOrOutputDependencyTag
Previously, modules customized behavior around the handling of
sourceOrOutputDependencyTag by comparing them to android.SourceDepTag
and retrieving the module using something like this:
    ctx.GetDirectDepWithTag(m, android.SourceDepTag)

The problem with that is it does not allow an output tag to be
specified and does not handle fully qualified names properly.

This adds the following:
* IsSourceDepTag and IsSourceDepTagWithOutputTag to check whether a
  blueprint.DependencyTag is a sourceOrOutputDependencyTag. The latter
  also checks that it has the correct output tag.
* GetModuleFromPathDep(ctx, moduleName, outputTag) as a replacement for
  ctx.GetDirectDepWithTag(m, android.SourceDepTag).

Replaces usages of:
* t == SourceDepTag with IsSourceDepTagWithOutputTag(t, "")
* ctx.GetDirectDepWithTag(m, android.SourceDepTag) with
  GetModuleFromPathDep(ctx, m, "")

It also deprecates the following:
* android.SourcDepTag - as a follow up change needs to modify the
  sourceOrOutputDependencyTag will make this useless.
* ExpandSources, ExpandsSources - copies existing deprecated messages
  from the implementation to the interface so that they can be seen
  by users of that interface.

Bug: 193228441
Test: m nothing
Change-Id: I8c397232b8d7dc1f9702c04ad45ea7819d4631ae
2021-07-09 23:54:01 +01: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
Justin Yun
5e03586365 Include static lib information for the snapshot modules
snapshot modules require the list of static libs to find the NOTICE
files for the snapshot modules.
snapshot binaries must include static_executable property to check if
non static binaries have libc as a static lib.

Bug: 190690041
Test: Check NOTICE for libaudiopreprocessing.so built from snapshots.
Change-Id: I53f7549a158ab27ada87833a3f4d58620aa7c3cf
2021-07-01 11:42:28 +00:00
Ivan Lozano
6eb16f8f87 Merge "rust: Add missing Rust allow path modules." 2021-06-28 19:05:51 +00:00
Ivan Lozano
03a94c48da rust: Add missing Rust allow path modules.
Adds rust_benchmark and rust_fuzz to the list of Rust module types which
need to be in the allowed paths, and a comment about rust_bindgen and
rust_protobuf.

This also adds a downstream allow path list which helps prevent merge
conflicts if downstream wants to extend the list of allowed paths.

Bug: 191507775
Test: Paths are checked for the newly added module types.
Test: Paths in DownstreamRustAllowedPaths allow Rust modules.
Change-Id: Ida80c33a815d47ffdfb1f648125d71316a2a9d8a
2021-06-28 11:59:07 -04:00
Jiyong Park
7d55b61783 Rust module in APEX uses stub libraries across APEX boundaries
This change fixes a bug that rust module in APEX has access to private
symbols of a native library even when the native library is outside of
the APEX.

To fix this, the stub selection logic in the cc package is exctacted as
a function ChooseStubOrImpl and is used also in the rust package.

Bug: 190767845
Test: m
Merged-In: I5c4cbdd5d27f257ab329d9dadbcd87d41a87f46a
Change-Id: I5c4cbdd5d27f257ab329d9dadbcd87d41a87f46a
(cherry picked from commit 3b5f88e091)
2021-06-24 11:27:41 +09:00
Ivan Lozano
3149e6ed18 Rust rlib vendor snapshot support.
Adds support for snapshotting Rust rlibs. This allows us
vendor-specific code that uses rlib-only linkage until dylib
snapshot support is added.

Bug: 184042776
Test: m nothing # new Soong tests pass
Test: Example test Rust vendor module builds
Test: m dist vendor-snapshot # includes rlibs
Change-Id: I4976d3e1efec0ee778cc97730d45be471dffb678
2021-06-03 08:36:09 -04:00
Ivan Lozano
1921e8003d Rust cdylib/statliclib support for vendor snapshot.
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
2021-06-03 08:32:05 -04:00
Jiyong Park
bf8147ab66 Don't install rust modules that are never installable
rust modules that return false on EverInstallable don't get installed.
Currently, proc_macro modules are such ones.

Bug: 187810017
Test: m microdroid on aosp_arm64 and inspect that *.dylib.so files
from host x86_64 are not there.

Change-Id: Ia57289a04dbff6e4f2ce2733c60de5338305904c
2021-05-17 13:27:20 +09: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
Colin Cross
5271fea26c Remove global state from vendor public libraries
Remove the global list of vendor public library modules used to rewrite
dependencies from the vendor module to the stubs for system modules,
and replace it with building the stubs directly in the system variant
of the vendor module.

Bug: 178231622
Test: vendor_public_library_test.go
Change-Id: I826e69ffd507d7e85fa3d4d85b5157428c642143
2021-04-27 16:26:00 -07:00
Colin Cross
203b421043 Remove obsolete llndk_library
Remove llndk_library in favor of cc_library with llndk.symbol_file.

Bug: 170784825
Test: m checkbuild
Test: TestLlndkLibrary
Change-Id: I43580976589a7a2a176d7442be53fa043c0c8324
2021-04-26 18:41:00 -07:00
Colin Cross
627280f091 Remove llndk_headers
Replace llndk_headers with cc_library_headers with
llndk.llndk_headers: true.

Bug: 170784825
Test: m checkbuild
Test: compare out/soong/build.ninja
Test: TestLlndkHeaders
Change-Id: I33b411cd4d474318796c2073375176b82dd8c216
2021-04-26 18:40:53 -07:00
Colin Cross
1f3f130e29 Add support for cc_library_headers to replace llndk_headers
Set llndk.llndk_headers: true to allow a cc_library_headers
module to be used by a cc_library module with llndk.symbol_file set.

Bug: 170784825
Test: TestLlndkHeaders
Change-Id: Ib65a4b70717dc9a54ae30f2991485bb1bb9b8409
2021-04-26 18:37:44 -07:00
Dan Albert
06feee9352 Rustdoc support.
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-16 13:38:01 -07:00
Thiébaud Weksteen
45c647d4dc Merge changes I59439b77,I7dbaf8be
* changes:
  bloaty: measure stripped Rust binaries
  rust: do not strip static library
2021-04-15 18:46:32 +00:00
Thiébaud Weksteen
e4dd14b25f bloaty: measure stripped Rust binaries
Modify bloaty's MeasureSizeForPath to allow a module to provide multiple
paths. This is used to measure both unstripped and stripped
libraries/binaries. Add unit test to ensure correct measurements are
generated for Rust.

Test: m out/soong/binary_sizes.pb.gz
Change-Id: I59439b77dbf1cf5ad71e1c02996a6a90938536b4
2021-04-15 12:02:51 +02:00
Ivan Lozano
d466b4a1f5 Merge changes from topic "rust_vendor_support"
* changes:
  Add more Rust vendor image support.
  rust: Use new common image mutator interface.
2021-04-14 19:02:49 +00:00
Ivan Lozano
e8dfbdfb59 Merge "cc: Create a common image mutator interface" 2021-04-14 18:53:18 +00:00
Jeffrey Vander Stoep
d587ec225a Merge changes from topic "rust_benchmark"
* changes:
  Attach rust_benchmark to atest and tradefed.
  Add rust_benchmark module to soong.
2021-04-14 08:02:46 +00:00
Ivan Lozano
c08897c1e4 Add more Rust vendor image support.
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-13 13:17:12 -04:00
Ivan Lozano
3a7d000d12 cc: Create a common image mutator interface
As part of adding Vendor support to Rust, refactor the image mutator in
CC to a new common image mutator interface so this logic can be reused
across both CC and Rust.

Bug: 184042776
Test: m nothing
Change-Id: Ia55d5ad840db7cf1a64d6c65ed86487230cb8742
2021-04-13 11:04:44 -04:00
Jiyong Park
94e22fd35e Shared lib dependencies from rlib are included in APEX
This change fixes a bug that shared lib dependencies of an rlib is not
installed to the APEX even when the rlib is part of the APEX.

Bug: N/A
Test: m
Change-Id: I88fe461584499839d8018d6b4292374592e7562b
2021-04-08 18:20:39 +09:00
Jiyong Park
e54f07e38a Stripped rust bin/libs are included in APEX
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-07 22:23:31 +09:00
Jakub Kotur
1d640d0521 Add rust_benchmark module to soong.
This commit adds rust_benchmark and rust_benchmark_host commands to
soong. Respectively running rust benchmarks on device and host. Currently
only criterion based benchmarks are supported and criterion library is
automatically linked.

Test: atest <module with rust_benchmark defined>
Bug: 155309706
Change-Id: I6edfc2b4bf30b1163fe59b8c2ecdcd4e7125e7b9
2021-04-06 12:40:32 +02:00
Ivan Lozano
352bdf29b3 Merge "rust: Add whole_static_libs, revert static_lib" 2021-03-26 13:01:14 +00:00
Ivan Lozano
63bb7680c9 rust: Add whole_static_libs, revert static_lib
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-25 13:50:17 -04:00
Jiyong Park
fdaa5f7164 Versioned CRT objects are built with correct __ANDROID_API__
Background: `min_sdk_version` of a crt object is the oldest SDK version
that the crt object supports. When it's set to for example 16, Soong
creates a number of versioned variants of the crt object starting from
16 to the latest version. The variant for version X is provided to NDK
clients having `min_sdk_version` set to X.

Problem: all versioned variants of a crt object were built with `-target
<arch>-linux-android16`. Therefore they all have been with `#define __ANDROID_API__
16`.  This is because the mutated variants still have the same
min_sdk_version property and the clang triple follows min_sdk_version,
not sdk_version. This is too conservative and against our intention to
provide the latest crt object that matches with the min_sdk_version of
the client.

In the other hand, the platform(non-sdk) variant of the crt object
doesn't have such a problem. min_sdk_version is completely ignored.
However, this is a bug and will be fixed by aosp/1640364. As a side
effect of the fixing, the platform variant will begin to built with a
very old __ANDROID_API__ which unnecessarily turns off the new platform
features like the TLS segment over-alignment.

This change fixes the problems:

* For the versioned variants of crt objects, we set both
`min_sdk_version` and `sdk_versio` to the version that the variant is
created for.

* For the platform variant of crt objects, `min_sdk_version` is force
reset to "current".

Bug: 183191008
Test: m

Change-Id: I8c9d0fcea816de8cd1532dac4a47eee4f726c037
2021-03-23 01:18:31 +09:00
Thiébaud Weksteen
ee6a89ba44 Export OUT_DIR variable to rust-project.json
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-03-15 08:13:20 +00:00
Ivan Lozano
4ccfcc2ee4 Merge "rust: Add rust_ffi_static vendor ramdisk Support" 2021-02-09 13:49:28 +00:00
Ivan Lozano
e6d3098c1b rust: Add rust_ffi_static vendor ramdisk Support
Similar to our vendor support, this adds support for linking rust static
libraries to vendor ramdisk cc modules.

A bug fix is also included where a restriction against setting rust_ffi
vendor-specific was not being enforced.

Bug: 179397942
Test: Example modules link, Soong tests pass.
Change-Id: I737cdf0c2f49ab349bcea2a0429e6298ebc1313e
2021-02-08 09:36:26 -05:00
Ivan Lozano
fb6f36f3e4 rust: Only pass "-lstatic" for rlibs.
Passing '-lstatic' for dylib static dependencies results in some
unexpected bloat as the static libraries are included as
whole-archives.

For now, limit this to rlibs while we investigate.

Bug: 175886967
Bug: 179122837
Test: cd system/bt/; mma
Test: Checked size of dylibs.
Change-Id: Id8328e95771e2ca8503bc8df35248b1c39cabc8e
2021-02-05 12:32:47 -05:00
Ivan Lozano
729d5cf097 Merge "rust: Pass cc static libs to rustc." 2021-02-05 15:53:33 +00:00
Ivan Lozano
3dfa12db6c rust: Pass cc static libs to rustc.
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-02-04 16:29:02 -05:00
Liz Kammer
356f7d45c1 bp2build: convert paths/module refs to Bazel label
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
2021-02-04 13:45:56 -05:00
Treehugger Robot
2a3094c70f Merge "Migrate Rust to LLVM coverage." 2021-01-26 15:28:36 +00:00
Ivan Lozano
6cd99e6ab4 Add Rust fuzzing support.
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-25 11:11:10 -05:00
Ivan Lozano
ec6e9910e6 rust: Depend on CC a shared library's TOC, not .so
CC libraries generate TOC files which contain the list of exported
symbols. By depending on the TOC file instead of the .so, changes to
shared library dependencies will not result in rebuilding Rust
dependencies as long as the exported symbols remain unchanged. This
should improve incremental build times during development.

This also includes a minor fix where exported linkObjects should be
deduplicated to avoid the same object being included many times.

Bug: 173619911
Test: m libkeystore2; modify a bionic file; m libkeystore2
      doesn't rebuild the rust target.
Change-Id: I6383217c125bf8dd7125a5e013a78754cac4edf2
2021-01-22 11:41:33 -05:00
Joel Galenson
fa049385b8 Migrate Rust to LLVM coverage.
Bug: 177675913
Test: Manually compile, run, and see output with llvm-cov.
Change-Id: I66729cff87a848782e9fa1b95cbbc06318c5761a
2021-01-15 19:44:07 +00:00
Ivan Lozano
3968d8f678 Refactor CC to prep for Rust sanitizable modules.
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
2021-01-08 08:53:46 -05:00
Jaewoong Jung
e794b1e302 Merge "Remove unnecessary snake case variables." 2020-12-23 01:21:28 +00:00