Swift Package Manager plugins for generating build-time code from environment variables and Git metadata.
This package provides two Swift Package Manager build tool plugins:
Generates Swift code from environment variables at build time. Useful for injecting configuration values, build numbers, or API endpoints into your app without hardcoding them.
Generated code example:
enum BuildEnvironment {
static let buildNumber = "123"
static let apiURL = "https://api.example.com"
// Could not find environment variable for MISSING_VAR
}
Configuration: Create a .build-env-to-swift.json
file in your project root:
{
"generated_type_name": "BuildEnvironment",
"environment_keys": ["BUILD_NUMBER", "API_URL"],
"acronyms": ["API", "URL", "ID"]
}
Features:
- Converts environment variable names to camelCase Swift properties
- Preserves acronyms in uppercase (configurable whitelist)
Generates Swift code containing Git metadata including tags and commit counts. No configuration required.
Generated code example:
public enum GitInfo {
public static let tag = "v1.2.3"
public static let revision = 142
}
Features:
- Automatically extracts Git tag and revision count
- Simplifies complex Git tag formats for cleaner version strings
- Swift 6.1+
Add this package as a dependency in your Package.swift
:
dependencies: [
.package(url: "https://github.com/tonyarnold/swift-build-environment-tools.git", from: "1.0.0")
]
Then add the plugins to your target:
.target(
name: "YourTarget",
plugins: [
.plugin(name: "BuildEnvironmentExtractorPlugin", package: "swift-build-environment-tools"),
.plugin(name: "GitInfoPlugin", package: "swift-build-environment-tools")
]
)
- Create
.build-env-to-swift.json
in your project root - Set environment variables before building
- The generated
BuildEnvironment.swift
file will be available in your target
Simply add the plugin to your target. The generated GitInfo.swift
file will automatically include current Git information.
MIT License - see LICENSE file for details.