Skip to content

Commit c0909f5

Browse files
committed
[WIP] Examples
1 parent 675a6a3 commit c0909f5

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
2-
/.build
2+
.build
33
/Packages
44
/*.xcodeproj
55
xcuserdata/

Examples/API/Package.swift

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version: 5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "api",
8+
products: [
9+
.executable(name: "API", targets: ["API"])
10+
],
11+
dependencies: [
12+
.package(name: "CDK", path: "../../")
13+
],
14+
targets: [
15+
.executableTarget(name: "API", dependencies: ["CDK"])
16+
]
17+
)

Examples/API/Sources/API/main.swift

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import CDK
2+
3+
@_cdecl("ic_init")
4+
func `init`() {
5+
CDK.print("Hello Swift!")
6+
}

Sources/CDK/CDK.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import IC
22

3-
@_cdecl("time")
3+
public func print(_ message: String) {
4+
withUnsafePointer(to: message) { src in
5+
let size = Int32(MemoryLayout.size(ofValue: message))
6+
IC.debug_print(src, size)
7+
}
8+
}
9+
410
public func time() -> Int64 {
511
IC.time()
612
}

Sources/IC/include/IC.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#if __wasm32__
77

8+
__attribute__((__import_module__("ic0"),__import_name__("debug_print")))
9+
extern void debug_print(const void *src, int32_t size);
10+
811
__attribute__((__import_module__("ic0"),__import_name__("time")))
912
extern int64_t time(void);
1013

11-
__attribute__((__import_module__("ic0"),__import_name__("debug_print")))
12-
extern void debug_print(int32_t src, int32_t size);
13-
1414
#endif
1515
#endif /* ic_h */

0 commit comments

Comments
 (0)