Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a04c74c5 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Add support for running cargo-bloat

In order to track how binary space is being used, add support for
calling cargo bloat via build.py. See
https://crates.io/crates/cargo-bloat for more informatio about the crate
which needs to be installed on the host in order to run.

Bug: 356808668
Test: mmm packages/modules/Bluetooth
Change-Id: I637e7e3f48b38ad9982a43ecbe56e51afcf5431b
parent 2b095079
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ USE_DEFAULTS = {

VALID_TARGETS = [
    'all',  # All targets except test and clean
    'bloat',  # Check bloat of crates
    'clean',  # Clean up output directory
    'docs',  # Build Rust docs
    'hosttools',  # Build the host tools (i.e. packetgen)
@@ -148,7 +149,7 @@ REQUIRED_APT_PACKAGES = [
]

# List of cargo packages required for linux build
REQUIRED_CARGO_PACKAGES = ['cxxbridge-cmd', 'pdl-compiler']
REQUIRED_CARGO_PACKAGES = ['cxxbridge-cmd', 'pdl-compiler', 'grpcio-compiler', 'cargo-bloat']

APT_PKG_LIST = ['apt', '-qq', 'list']
CARGO_PKG_LIST = ['cargo', 'install', '--list']
@@ -249,6 +250,8 @@ class HostBuild():
            'link-arg=-Wl,--allow-multiple-definition',
            # exclude uninteresting warnings
            '-A improper_ctypes_definitions -A improper_ctypes -A unknown_lints',
            '-Cstrip=debuginfo',
            '-Copt-level=z',
        ]

        return ' '.join(rust_flags)
@@ -570,6 +573,17 @@ class HostBuild():

        print('Tarball created at {}'.format(tar_location))

    def _target_bloat(self):
        """Run cargo bloat on workspace.
        """
        crate_paths = [
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'mgmt'),
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'service'),
            os.path.join(self.platform_dir, 'bt', 'system', 'gd', 'rust', 'linux', 'client')
        ]
        for crate in crate_paths:
            self.run_command('bloat', ['cargo', 'bloat', '--release', '--crates', '--wide'], cwd=crate, env=self.env)

    def _target_clean(self):
        """ Delete the output directory entirely.
        """
@@ -624,6 +638,8 @@ class HostBuild():
            self._target_install()
        elif self.target == 'utils':
            self._target_utils()
        elif self.target == 'bloat':
            self._target_bloat()
        elif self.target == 'all':
            self._target_all()

+5 −1
Original line number Diff line number Diff line
@@ -67,7 +67,11 @@ RUN /tmp/rustup.sh -y --default-toolchain 1.77.1
ENV PATH="/root/.cargo/bin:${PATH}"

# Install cargo packages required on build image.
RUN cargo install --locked cxxbridge-cmd@1.0.94 pdl-compiler@0.1.1 grpcio-compiler@0.13.0
RUN cargo install --locked \
    cxxbridge-cmd@1.0.94 \
    pdl-compiler@0.1.1 \
    grpcio-compiler@0.13.0 \
    cargo-bloat@0.12.1
RUN cargo install --git https://android.googlesource.com/platform/build#8f9ca807 aconfig

# Rename llvm packages. By default, they are named 11vm-ar-13, etc. which won't