Files

43 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the C sensor provider and write provider/build/provider.json (schema v2)
# with the host target triple and the real artifact SHA-256.
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
out="$here/build"
mkdir -p "$out"
host="$("$here/../scripts/host-target.sh")"
case "$host" in
*windows*) echo "unsupported: Windows C ABI provider is not implemented in this fixture" >&2; exit 3 ;;
*apple-darwin*) ext="dylib"; flags=(-dynamiclib -fPIC) ;;
*) ext="so"; flags=(-shared -fPIC) ;;
esac
artifact="libsensor.$ext"
cc -std=c11 -O2 "${flags[@]}" -o "$out/$artifact" "$here/src/sensor.c"
if command -v sha256sum >/dev/null 2>&1; then
hash="$(sha256sum "$out/$artifact" | cut -d' ' -f1)"
else
hash="$(shasum -a 256 "$out/$artifact" | cut -d' ' -f1)"
fi
cat > "$out/provider.json" <<JSON
{
"schema": "marqdo.provider",
"schema_version": 2,
"name": "demo.sensor",
"version": "0.1.0",
"abi": "c-abi-1",
"transport": "worker",
"kinds": ["demo.sensor"],
"artifacts": [
{
"target": "$host",
"path": "lib/$artifact",
"sha256": "$hash"
}
],
"permissions_requested": []
}
JSON
mkdir -p "$out/lib"
mv "$out/$artifact" "$out/lib/$artifact"
echo "built $out/lib/$artifact for $host (sha256 $hash)"