Readme
simple-inih-cpp
INI file parser. Native plugin example using vcpkg — wraps the popular inih C library and exposes a parse(text) function that returns a flat map of "section.key" → value.
Install
bpm install simple-inih-cppUse
import "simple-inih-cpp" as ini;
var m = ini.parse("
name = bpm
[server]
host = 127.0.0.1
port = 3000
");
print(m["name"]); // bpm
print(m["server.host"]); // 127.0.0.1
print(m["server.port"]); // 3000API
parse(text)— parse an INI document. Returns a map keyed"section.key"; keys outside any section appear as just"key". Throws on syntax errors with the failing line number.version— package version string.
Build (for the maintainer)
Unlike the zig-built examples in this directory, this package links a real C library (inih) that vcpkg fetches, builds, and exposes via CMake. Vcpkg builds per-host, so cross-compiling all platforms from one machine doesn't work the same way zig does.
Prerequisites (one-time)
- vcpkg — clone and bootstrap from https://github.com/microsoft/vcpkg, then set
VCPKG_ROOTto its path. - CMake 3.20+ and Ninja on PATH.
- A C/C++ compiler:
- Windows: MSVC — install Visual Studio (Community is fine) with the Desktop development with C++ workload.
build.ps1auto-imports the VS dev environment viavswhere, so you can run it from a plain PowerShell window. - macOS: Xcode command line tools (
xcode-select --install). - Linux:
gccorclang. For the 32-bitlinux-x86target, also install multilib:sudo apt install gcc-multilib g++-multilib.
- Windows: MSVC — install Visual Studio (Community is fine) with the Desktop development with C++ workload.
Build for the current host
Each host script builds both of its natural arch pairs in one invocation (x64 + x86 on Windows / Linux, arm64 + x64 on Apple Silicon Macs):
# Windows (any PowerShell window — build.ps1 imports the MSVC env itself)
.\build.ps1
# → build\windows-x64\simple-inih-cpp.dll
# → build\windows-x86\simple-inih-cpp.dll
# macOS (Apple Silicon)
./build.sh
# → build/darwin-arm64/simple-inih-cpp.dylib
# → build/darwin-x64/simple-inih-cpp.dylib
# Linux x86_64
./build.sh
# → build/linux-x64/simple-inih-cpp.so
# → build/linux-x86/simple-inih-cpp.so (needs gcc-multilib, see prereqs above)Each new target builds its own vcpkg deps the first time (~30 s for inih), then cached afterwards. The compile of this plugin itself is instant.
Building for all targets in bnl.json
There are two realistic workflows:
- Local per-host — run
./build.sh(or.\build.ps1) on a Windows box, a Linux box, and a Mac. After all three artifacts exist on this filesystem, runbpm publish. - CI matrix — GitHub Actions / similar with a
windows-latest/ubuntu-latest/macos-14matrix that runs the build script and uploads the artifact, then a publish job collects them and runsbpm publish.
If you only have one host available right now, publish one platform at a time and consumers on the other platforms can install once the corresponding asset is up:
bpm publish --platform windows-x64Publish (for the maintainer)
bpm publishbpm reads the targets map in bnl.json, pre-flights that every binary exists on disk, uploads one tarball per platform, and prints a summary. Re-runs are idempotent — already-published platforms are skipped.
What this example teaches
- vcpkg manifest mode:
vcpkg.jsondeclares deps; CMake'sfind_packagepulls them in. - CMakePresets: one preset per target platform, each with the right
VCPKG_TARGET_TRIPLET. - CMake → bnl integration: artifact named after the package (no
libprefix) lands directly inbuild/<platform>/, matchingbnl.jsontargets. - The cross-compile trade-off: when your plugin depends on a C library that vcpkg has to build, you give up zig's "all targets from one host" and accept per-host builds in exchange.
MIT licensed.