Skip to content

Commit ef925fc

Browse files
sanityclaude
andcommitted
fix: Add platform guards for WASM import symbols to fix Windows linking
Fixes freenet/river#39 Windows MSVC linker requires all external symbols to be resolved, even for cdylib crates. The WASM import symbols (__frnt__logger__info, __frnt__rand__rand_bytes, __frnt__time__utc_now) are only valid when compiling to wasm32-unknown-unknown target. This change: - Guards WASM imports with #[cfg(target_family = "wasm")] - Provides stub implementations for non-WASM targets - Allows contracts to compile on Windows native target The stub implementations are never used at runtime since contracts only execute in the Freenet WASM runtime. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2733d38 commit ef925fc

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

rust/src/log.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ pub fn info(msg: &str) {
55
}
66
}
77

8+
#[cfg(target_family = "wasm")]
89
#[link(wasm_import_module = "freenet_log")]
910
extern "C" {
1011
#[doc(hidden)]
1112
fn __frnt__logger__info(id: i64, ptr: i64, len: i32);
1213
}
14+
15+
#[cfg(not(target_family = "wasm"))]
16+
#[allow(non_snake_case)]
17+
unsafe fn __frnt__logger__info(_id: i64, _ptr: i64, _len: i32) {
18+
// Stub implementation for non-WASM targets (e.g., Windows native compilation)
19+
// These contracts are meant to run only in WASM runtime
20+
}

rust/src/rand.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ pub fn rand_bytes(number: u32) -> Vec<u8> {
3333
}
3434
}
3535

36+
#[cfg(target_family = "wasm")]
3637
#[link(wasm_import_module = "freenet_rand")]
3738
extern "C" {
3839
#[doc(hidden)]
3940
fn __frnt__rand__rand_bytes(id: i64, ptr: i64, len: u32);
4041
}
42+
43+
#[cfg(not(target_family = "wasm"))]
44+
#[allow(non_snake_case)]
45+
unsafe fn __frnt__rand__rand_bytes(_id: i64, _ptr: i64, _len: u32) {
46+
// Stub implementation for non-WASM targets (e.g., Windows native compilation)
47+
// These contracts are meant to run only in WASM runtime
48+
}

rust/src/time.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ pub fn now() -> DateTime<Utc> {
1414
}
1515
}
1616

17+
#[cfg(target_family = "wasm")]
1718
#[link(wasm_import_module = "freenet_time")]
1819
extern "C" {
1920
#[doc(hidden)]
2021
fn __frnt__time__utc_now(id: i64, ptr: i64);
2122
}
23+
24+
#[cfg(not(target_family = "wasm"))]
25+
#[allow(non_snake_case)]
26+
unsafe fn __frnt__time__utc_now(_id: i64, _ptr: i64) {
27+
// Stub implementation for non-WASM targets (e.g., Windows native compilation)
28+
// These contracts are meant to run only in WASM runtime
29+
}

0 commit comments

Comments
 (0)