This is a sample project that demonstrates Pkl <> Swift integration.
This is a basic HTTP server that is configured via Pkl in the pkl/ directory.
Directory |
Description |
|
Pkl configuration sources |
|
Generated Swift sources from Pkl |
|
Swift files for runtime evaluation example |
|
Swift files for build-time evaluation example |
Generated sources are already checked into git for learning purposes.
To generate new Pkl sources, first install the Swift code generator:
curl -L https://github.com/apple/pkl-swift/releases/download/0.7.0/pkl-gen-swift-macos.bin -o pkl-gen-swift
chmod +x pkl-gen-swiftWith that installed, generate Swift sources via:
pkl-gen-swift pkl/**.pkl -o Sources/GenThe example in Sources/BuildTimeEval/ shows how the pkl-binary encoding can be used to configure applications.
This mechanism separates evaluation of Pkl code from application runtime by encoding the configuration data as pkl-binary, storing it in a file, and loading it later during application startup.
This example works identically to the runtime evaluation example, but does not require the application to spawn the Pkl CLI as a subprocess.
The configuration module is rendered as pkl-binary by running:
pkl eval pkl/dev/config.pkl -f pkl-binary -o pkl/dev/config.msgpack