---
title: Swift Build and Signing
description: Swift build, bundle, and code-signing helpers, so macOS app work happens
  in Python instead of one-off shell calls.
order: 2
---
Wraps `swift`, `codesign`, `ditto`, `pkgbuild`, `productbuild`, `notarytool`, and `swift-symbolgraph-extract` via `fastcore.utils.run`, which raises on non-zero exit codes.

## Building app bundles

Use [`build_app()`](swifttool.md#build_app) for the full release pipeline (compile, assemble `.app`, sign, and zip to `dist/<Name>.app.zip`), or call [`swift_build()`](swifttool.md#swift_build) and [`mk_app()`](swifttool.md#mk_app) separately.

### build\_app

```python
def build_app(
    path, # Swift package directory
    bundle_id:str, # CFBundleIdentifier, which TCC grants attach to
    identity:str=None, # Signing identity; the sole Developer ID one if None
    hardened:bool=True, # Enable the hardened runtime, which requires an entitlement per protected resource
    app_icon=None, # Optional Icon Composer `.icon` document
    deployment_target:str=None, # Minimum macOS version; required with `app_icon`
    **plist
)->tuple[pathlib._local.Path, pathlib._local.Path]: # `(app_path, zip_path)`
```

*Build, sign, and archive a Swift package, always as `build/<Name>.app` and `dist/<Name>.app.zip`, so the two cannot drift from the source or each other*

### swift\_build

```python
def swift_build(
    path, # Package directory
    config:str='release', # Build configuration
)->pathlib._local.Path: # Built executable path
```

*Build the Swift package at `path`, returning the built executable*

### mk\_app

```python
def mk_app(
    exe, # Built executable to install as the bundle's binary
    dest, # Path of the `.app` to create, replacing any existing one
    bundle_id:str, # CFBundleIdentifier, which TCC grants attach to
    app_icon=None, # Optional Icon Composer `.icon` document
    deployment_target:str=None, # Minimum macOS version; required with `app_icon`
    **plist
)->pathlib._local.Path: # Path to the assembled `.app` bundle
```

*Assemble a macOS app bundle around `exe`, optionally compiling an Icon Composer document*

## Signing and archiving

Always archive signed macOS bundles with [`zip_app()`](swifttool.md#zip_app) (`ditto`) rather than `zipfile` or `tar` so code signatures remain valid after extraction.

### sign

```python
def sign(
    path, # Bundle or binary to sign
    identity:str=None, # Signing identity; the sole Developer ID one if None
    hardened:bool=True, # Enable the hardened runtime, which requires an entitlement per protected resource
)->str: # Signing identity used
```

*Code-sign `path`, replacing any existing signature*

### verify\_sig

```python
def verify_sig(
    path, # Bundle or binary to check
)->bool: # `True` when `codesign --verify --strict` exits 0
```

*Whether `path`'s signature is intact, checked strictly*

### codesign\_req

```python
def codesign_req(
    path, # Bundle or binary to inspect
)->str: # Designated requirement output from `codesign`
```

*The designated requirement `path`'s signature is keyed to, which is what TCC grants match against*

### signing\_ids

```python
def signing_ids()->dict[str, str]:
```

*Code-signing identities in the keychain, as `{name: sha1}`*

### installer\_ids

```python
def installer_ids()->dict[str, str]:
```

*Developer ID Installer identities in the keychain, as `{name: sha1}`*

### zip\_app

```python
def zip_app(
    app, # `.app` bundle to archive
    dest, # Zip file to write
)->pathlib._local.Path: # Written `.zip` archive path
```

*Archive `app` with `ditto`, the only archiver that keeps a bundle's signature intact*

### unzip\_app

```python
def unzip_app(
    src, # Zip file made by `zip_app`
    dest, # Directory to extract into
)->pathlib._local.Path: # Extracted `.app` bundle path
```

*Extract a [`zip_app`](swifttool.md#zip_app) archive, preserving the signature*

## Packages and notarization

### mk\_pkg

```python
def mk_pkg(
    dest, # Path of the `.pkg` to write
    bundle_id:str, # Reverse-DNS package identifier
    version:str='1.0', # Package version
    root=None, # Payload directory (`--nopayload` when None)
    scripts=None, # Scripts directory, or a single script path installed as `postinstall`
    install_location:str=None, # Optional `--install-location` for payload packages
    title:str=None, # Installer window title (defaults to `dest.stem`)
    welcome:str=None, # Optional HTML or text shown on the welcome screen
    conclusion:str=None, # Optional HTML or text shown on the final screen
    user_home:bool=True, # Install into `$HOME` without an admin password (`enable_currentUserHome`)
    identity:str=None, # Developer ID Installer identity; auto-detected if None (False to skip signing)
)->pathlib._local.Path: # Written `.pkg` path
```

*Build and sign a macOS installer `.pkg` via `pkgbuild` and `productbuild`*

### notarize

```python
def notarize(
    path, # `.pkg`, `.dmg`, or `.zip` to submit to Apple's notary service
    profile:str=None, # Keychain profile saved with `xcrun notarytool store-credentials`; defaults to `$NOTARY_PROFILE`
    staple:bool=None, # Staple the ticket onto `path`; defaults to True except for `.zip`
)->pathlib._local.Path: # Notarized `path`
```

*Submit `path` to `xcrun notarytool` and optionally staple the notarization ticket*

## SDK symbol graphs and toolchain

### symbolgraph

```python
def symbolgraph(
    module, # Framework/module name, e.g. 'EventKit'
    out=None, # Directory for the JSON files; a per-SDK cache dir if None
    min_access:str='public', # Minimum symbol access level to include
    refresh:bool=False, # Re-extract even if the cached JSON exists
)->dict: # Parsed main-module symbol graph JSON
```

*Extract `module`'s Swift symbol graph (Apple's own ObjC-\>Swift importer output), returning the parsed main-module JSON*

### sdk\_path

```python
def sdk_path()->pathlib._local.Path:
```

*The active macOS SDK root*

### swift\_version

```python
def swift_version()->str:
```

*The active Swift toolchain's version banner*
