# Assembling structured configuration

[Structured configuration](https://fuchsia.dev/fuchsia-src/development/components/configuration/structured_config) allows developers to package components with
different values in different contexts. Product assembly allows developers to
define structured configuration values based on high-level platform and product
configuration.

To vary your component's configuration by product or build type you must declare
a schema, identify how values will be derived from a product's configuration,
and generate your component's config.

## Define a configuration schema

Your component must have a declared configuration schema in its manifest. For
example:

        ...
        config: {
            enable_foo: { type: "bool" },
        },

For more information see the [documentation for structured config](https://fuchsia.dev/fuchsia-src/development/components/configuration/structured_config).

## Identify product assembly configuration

Many configuration options can be represented as the difference between
[`eng` builds and non-`eng` builds](https://fuchsia.dev/docs/contribute/governance/rfcs/0115_build_types).

If the configuration of your component can't be deduced solely from build type,
email the [Software Assembly list](mailto:software-assembly@fuchsia.dev) to discuss the schema which should
be used (note that this list is publicly viewable, please use Google-internal
lists to discuss internal-only configuration). Once a schema has been decided,
add it to the [product configuration library](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/lib/assembly/config_schema/src/product_config.rs).

## Configure the package

Determine your package's name and your component's manifest resource path.
Define logic to populate configuration for it in the [product assembly
tool](https://cs.opensource.google/fuchsia/fuchsia/+/main:/src/lib/assembly/platform_configuration/src/lib.rs). For example, to configure a value based on the build
type:

    use crate::subsystems::prelude::*;
    use assembly_config_schema::platform_settings::example_config::ExampleConfig;

    pub(crate) struct ExampleSubsystemConfig;
    impl DefineSubsystemConfiguration<ExampleConfig> for ExampleSubsystemConfig {
        fn define_configuration(
            context: &ConfigurationContext<'_>,
            example_config: &ExampleConfig,
            builder: &mut dyn ConfigurationBuilder,
        ) -> anyhow::Result<()> {
            // If the build-type is eng, enabled "foo" for the example component.
            builder
                .package("configured_by_assembly")
                .component("meta/to_configure.cm")?
                .field("enable_foo", matches!(context.build_type, BuildType::Eng))?;

            if example_config.include_example_aib {
                builder.platform_bundle("example_assembly_bundle")?;

                // Set structured config for a component in the example AIB
                let mut component_config = builder.package("for-test").component("meta/bar.cm")?;
                component_config.field("asserted_by_scrutiny_test", "check this string!")?;
                component_config.field("mutable_by_parent_config", "don't check this string!")?;
            }

            Ok(())
        }
    }

> [!NOTE]
> **Note:** A given component cannot mix [configuration values produced by GN](https://fuchsia.dev/fuchsia-src/development/components/configuration/structured_config#define--package-configuration-values-using-gn) and values produced by software assembly.

## Update size limits configuration (if any)

When producing configuration values for a package, product assembly must write
its outputs to a different location in the build directory than the path
normally produced by the build system. There are binary size checks that rely on
paths to package manifests that exist in the build directory, so it is important
that you update the package's output path in the build configuration rules.

For example, before having its configuration generated by product assembly,
the `session_manager` package was listed in [the core product's size
limits](https://cs.opensource.google/fuchsia/fuchsia/+/main:/products/common/core_size_limits.gni) as:

    {
      component = "Component Framework"
      src = [
        # ...

        "packages/base/session_manager",
      ]

      # ...
    },

When using product assembly for its config, `session_manager` must now be
specified in size limits as:

    {
      component = "Component Framework"
      pkgs = [
        # ...

        "session_manager",
      ]

      # ...
    },

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/components/configuration/assembling_structured_config.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/components/configuration/assembling_structured_config.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/components/configuration/assembling_structured_config.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/components/configuration/assembling_structured_config.md "Edit the source code of this page")