Skip to content

Commit c93ddb5

Browse files
committed
Add BatteryLevel ABI export shims
1 parent 241e700 commit c93ddb5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

  • PluginSDK/Examples/BatteryLevel/Sources/BatteryLevel
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Exports.swift
3+
// BatteryLevel
4+
//
5+
// ABI export shims. These live in the plugin's own module on purpose: `@_expose(wasm)` symbols
6+
// are dropped when they come from a dependency module (swiftlang/swift#77812), so the SDK ships
7+
// this file as template boilerplate rather than library code. Authors copy it unchanged and
8+
// delete the capability shims their plugin does not implement.
9+
//
10+
11+
import BLEPluginSDK
12+
13+
@_expose(wasm, "bleplug_abi_1")
14+
@_cdecl("bleplug_abi_1")
15+
func bleplugABIMarker() {}
16+
17+
@_expose(wasm, "bleplug_alloc")
18+
@_cdecl("bleplug_alloc")
19+
func bleplugAlloc(_ size: UInt32) -> UInt32 {
20+
PluginRuntime.allocate(size)
21+
}
22+
23+
@_expose(wasm, "bleplug_free")
24+
@_cdecl("bleplug_free")
25+
func bleplugFree(_ pointer: UInt32, _ size: UInt32) {
26+
PluginRuntime.deallocate(pointer)
27+
}
28+
29+
@_expose(wasm, "bleplug_parse_characteristic")
30+
@_cdecl("bleplug_parse_characteristic")
31+
func bleplugParseCharacteristic(_ pointer: UInt32, _ length: UInt32) -> UInt64 {
32+
PluginRuntime.handle(pointer: pointer, length: length, parse: parseCharacteristic)
33+
}

0 commit comments

Comments
 (0)