zig
zig copied to clipboard
__attribute__ import_module() import_name() not working correctly.
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
wasmexports.h:
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void test_function() __attribute__((import_module("test_module"))) __attribute__((import_name("test_function")));
#ifdef __cplusplus
}
#endif
main.zig:
const std = @import("std");
const c = @cImport({
@cInclude("wasmexports.h");
});
pub fn main() !void {
c.test_function();
}
inside build.zig:
const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
const optimize = std.builtin.OptimizeMode.ReleaseSmall;
wasm module generated:
(module
(type $type0 (func (param i32)))
(type $type1 (func))
(func $import0 (import "env" "test_function") (param i32))
(memory $memory0 2 2)
(global $global0 (mut i32) (i32.const 72096))
(export "memory" (memory $memory0))
(export "_start" (func $func1))
(func $func1
i32.const 0
call $import0
)
)
Expected Behavior
We should be seeing "test_module" instead of "env"
(func $import0 (import "test_module" "test_function") (param i32))
(module
(type $type0 (func (param i32)))
(type $type1 (func))
(func $import0 (import "test_module" "test_function") (param i32))
(memory $memory0 2 2)
(global $global0 (mut i32) (i32.const 72096))
(export "memory" (memory $memory0))
(export "_start" (func $func1))
(func $func1
i32.const 0
call $import0
)
)