# Contribute SDK packages

This page serves as a playbook for contributing [Fuchsia packages](https://fuchsia.dev/docs/concepts/packages/package)
(from here on simply "packages") to the [Fuchsia API surface](https://fuchsia.dev/docs/glossary/README#fuchsia-api-surface)
and the [Fuchsia IDK](https://fuchsia.dev/docs/development/idk/README).

The steps are:

1. [Prerequisites](https://fuchsia.dev/fuchsia-src/contribute/sdk/packages#prerequisites).
2. [Create a package API surface](https://fuchsia.dev/fuchsia-src/contribute/sdk/packages#create-a-package-api-surface).
3. [Explore package contents](https://fuchsia.dev/fuchsia-src/contribute/sdk/packages#explore-package-contents).
4. [Contribute to an API in the SDK](https://fuchsia.dev/fuchsia-src/contribute/sdk/packages#contribute-to-an-api-in-the-sdk).

## Prerequisites

For a package to be included in the Fuchsia SDK, the package must be created
in the category of `partner` or `public`. (For more information, see
[Promoting an API to the partner category](https://fuchsia.dev/docs/contribute/sdk/README#promoting_an_api_to_the_partner_category).)

## Create a package API surface

The package API surface is created by populating two parameters in the
[`sdk_fuchsia_package()`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/build/packages/sdk_fuchsia_package.gni) target: `expected_files_present`
and `expected_files_exact`.

You can use these two parameters to enforce the following:

- `expected_files_present`: A package file is present in the SDK package's manifest.
- `expected_files_exact`: A package file is present in the SDK package's manifest and its content hash matches the content hash checked in source.

A package file can consist of any items in the package's [contents](https://fuchsia.dev/docs/concepts/packages/package#structure-of-a-package),
which include:

- Files inside `meta/`
- Files in the base package

> [!NOTE]
> **Note:** For components, it's recommended to track the output component manifest (that is, `meta/<component_name>.cm`) at the `expected_files_exact` level for an API surface. This ensures that anything that changes the package's functionality (which in turn changes its component manifest content hash) will be surfaced.

## Explore package contents

Provide a list of the items that make up a package in the package's manifest file
(commonly named `package_manifest.json`)

See an example manifest file below:

    {
      "version": "1",
      "repository": "fuchsia.com",
      "package": {
        "name": "example_package",
        "version": "0"
      },
      "blobs": [
        {
          "source_path": "path/to/meta.far",
          "path": "meta/",
          "merkle": "CONTENT_HASH",
          "size": 0
        },
        {
          "source_path": "path/to/bin/example",
          "path": "bin/example",
          "merkle": "CONTENT_HASH",
          "size": 0
        },
        {
          "source_path": "path/to/shared/bar.so",
          "path": "lib/bar.so",
          "merkle": "CONTENT_HASH",
          "size": 0
        }
      ]
    }

In the example above, possible API surface items (besides the `meta.far`) are in the
`blobs/path` entities, which include:

- `bin/example`
- `lib/far.so`

The `ffx package far list` command allows you to explore the contents of the `meta.far`,
for example:

    $ ffx package far list path/to/meta.far
    +---+
    | path                          |
    +===============================+
    | meta/contents                 |
    +---+
    | meta/fuchsia.abi/abi-revision |
    +---+
    | meta/component_name.cm        |
    +---+

In total, the possible API surface items (including `meta.far`) from this example now include:

- `bin/example`
- `lib/far.so`
- `meta/contents`
- `meta/fuchsia.abi/abi-revision`
- `meta/component_name.cm`

## Contribute to an API in the SDK

> [!TIP]
> **Tip:** See this [example Gerrit change](http://fxrev.dev/c/fuchsia/+/895023) for the steps described in this section.

To contribute a package to the Fuchsia API surface, follow the guidelines below:

1. Prepare to [request a code review](https://fuchsia.dev/docs/development/source_code/contribute_changes#request-a-code-review) from an API council member.

   This member may ask for adjustments to your API surface (see this
   [example code review](http://fxrev.dev/c/fuchsia/+/895023) of an SDK package).
2. Create a `sdk_fuchsia_package` target for your SDK package
   ([example](http://fxrev.dev/c/fuchsia/+/895023/39/src/lib/fuchsia-component-test/realm_builder_server/BUILD.gn)).

   This will likely live next to the `fuchsia_package` target that is being
   exported.
3. Pay attention to the declared API surface, represented by the
   `expected_files_exact`and `expected_files_present` parameters of the
   `sdk_fuchsia_package` target.

   (see [Create a package API surface](https://fuchsia.dev/fuchsia-src/contribute/sdk/packages#create-a-package-api-surface).)
4. Add the `sdk_fuchsia_package` target to the dependencies of the
   `sdk_molecule` ("core_packages") target in the `//sdk/BUILD.gn` file
   ([example](https://cs.opensource.google/fuchsia/fuchsia/+/9796254028425f4d948ca5976976dabba5c40f58:src/lib/fuchsia-component-test/realm_builder_server/BUILD.gn;l=89-94?q=src/lib/fuchsia-component-test/realm_builder_server/BUILD.gn&ss=fuchsia)).

   To build the IDK target (which is expected to fail its golden file check),
   run the following command:

       fx build final_fuchsia_idk

5. Follow the printed instructions for copying the generated `content_checklist.json`
   file to its golden file location.

6. Confirm that the generated `content_checklist.json` file covers the desired
   API surface ([example](https://cs.opensource.google/fuchsia/fuchsia/+/9796254028425f4d948ca5976976dabba5c40f58:sdk/packages/realm_builder_server/release/content_checklist.api)).

   If not, adjust the `expected_files_exact` and `expected_files_present` parameters
   and repeat the previous build step.
7. Build the IDK target after fixing any other SDK manifest-related changes (including updating
   the `//sdk/manifests/fuchsia_idk.manifest` files).

       fx build final_fuchsia_idk

8. **(Optional)** Enter the SDK build directory and preview your SDK package manifest.

   From your build directory (for example, `out/default`), do the following:
   1. Change the directory to `sdk/archive`, for example:

          cd sdk/archive

   2. Run the following command:

          mkdir output && tar zxvf fuchsia_idk.tar.gz -C output && cd output

      The package manifest of your package targeting x64 will be found at
      `packages/{PACKAGE_DISTRIBUTION_NAME}/x64/release/package_manifest.json`

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