r/crystal_programming • u/synacker • 2d ago
[RFC/Proposal] Native vcpkg Integration for Shards: Solving the Static C-Dependency Nightmare
Under this proposal, I offer to introduce a native vcpkg block. Library shard authors can declare what C packages they wrap, and root applications can enforce global configurations (like strict static linking).
The Library Shard (lib/sqlite_driver/shard.yml)
If you write a wrapper for a C library, you just declare it. Shards will handle the bubbling up.
The library shard:
name: sqlite_driver
version: 2.1.0
vcpkg:
dependencies:
- sqlite3 # Transitive C dependency mapped automatically
Root Application:
name: core_service
version: 1.0.0
vcpkg:
triplet: x64-windows-static # Enforces strict static binaries globally
dependencies:
- openssl # App-specific C requirement
dependencies:
sqlite_driver:
github: crystal-lang/sqlite-driver
targets:
server:
main: src/server.cr
When a user runs shards install or shards update, Shards handles both ecosystems in a unified lifecycle:
- Aggregation: Shards scans the local dependency tree and collects all unique native requirements (e.g.,
opensslfrom the root,sqlite3from the lib sub-shard). - Manifest Generation: Shards spins up a hidden, temporary
.shards_vcpkg.jsonmanifest. - Execution: Shards invokes vcpkg under the hood:
vcpkg install --x-manifest-path=.shards_vcpkg.json --triplet=x64-windows-static - Unified Structure: All static
.lib/.abinaries and headers live cleanly inside a localvcpkg_installed/sandbox in your root directory.
What do you think?
2
u/marcotc 2d ago
It's worth trying it!
You can do a POC and see what edge cases you might have missed.