bpm

simple-inih-cpp

v1.0.0 Native plugin

INI parser via inih — native plugin example using vcpkg.

@mamun MIT Published

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-cpp

Use

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"]);   // 3000

API

  • 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)

  1. vcpkg — clone and bootstrap from https://github.com/microsoft/vcpkg, then set VCPKG_ROOT to its path.
  2. CMake 3.20+ and Ninja on PATH.
  3. A C/C++ compiler:
    • Windows: MSVC — install Visual Studio (Community is fine) with the Desktop development with C++ workload. build.ps1 auto-imports the VS dev environment via vswhere, so you can run it from a plain PowerShell window.
    • macOS: Xcode command line tools (xcode-select --install).
    • Linux: gcc or clang. For the 32-bit linux-x86 target, also install multilib: sudo apt install gcc-multilib g++-multilib.

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:

  1. 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, run bpm publish.
  2. CI matrix — GitHub Actions / similar with a windows-latest / ubuntu-latest / macos-14 matrix that runs the build script and uploads the artifact, then a publish job collects them and runs bpm 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-x64

Publish (for the maintainer)

bpm publish

bpm 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.json declares deps; CMake's find_package pulls them in.
  • CMakePresets: one preset per target platform, each with the right VCPKG_TARGET_TRIPLET.
  • CMake → bnl integration: artifact named after the package (no lib prefix) lands directly in build/<platform>/, matching bnl.json targets.
  • 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.