Demonstrates how to write portable code using abstract extern declarations with platform-specific implementations.
Declare an interface with kind="extern-abstract":
snippet id="console.println" kind="extern-abstract"
effects
effect console
end
signature
fn name="println"
param name="msg" type="String"
returns type="Unit"
end
end
end
Provide platform-specific implementations with kind="extern-impl":
snippet id="console.println.browser" kind="extern-impl"
implements="console.println" platform="browser"
metadata
contract="@browser/console.log"
end
end
Supported platforms: browser, node, wasi
User code calls the abstract ID - the compiler selects the appropriate implementation based on the compilation target:
step id="s1" kind="call"
fn="console.println" // Always use abstract ID
arg name="msg" from="name"
as="_"
end
Compile with: covenant compile --target=browser ...
- Console/logging across platforms
- File system access (Node.js vs WASI)
- HTTP clients (fetch vs Node http)
- Any capability that differs by runtime
using-bindings/- Basic extern usage patternsextern-bindings/- Extern declaration syntax