master
1const builtin = @import("builtin");
2const std = @import("std");
3const expect = std.testing.expect;
4
5test "exporting enum value" {
6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7
8 if (builtin.cpu.arch.isWasm()) {
9 // https://github.com/ziglang/zig/issues/4866
10 return error.SkipZigTest;
11 }
12
13 const S = struct {
14 const E = enum(c_int) { one, two };
15 const e: E = .two;
16 comptime {
17 @export(&e, .{ .name = "e" });
18 }
19 };
20 try expect(S.e == .two);
21}
22
23test "exporting with internal linkage" {
24 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
25
26 const S = struct {
27 fn foo() callconv(.c) void {}
28 comptime {
29 @export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal });
30 }
31 };
32 S.foo();
33}
34
35test "exporting using namespace access" {
36 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
37
38 if (builtin.cpu.arch.isWasm()) {
39 // https://github.com/ziglang/zig/issues/4866
40 return error.SkipZigTest;
41 }
42
43 const S = struct {
44 const Inner = struct {
45 const x: u32 = 5;
46 };
47 comptime {
48 @export(&Inner.x, .{ .name = "foo", .linkage = .internal });
49 }
50 };
51
52 _ = S.Inner.x;
53}
54
55test "exporting comptime-known value" {
56 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
57 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
58 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
59
60 if (builtin.cpu.arch.isWasm()) {
61 // https://github.com/ziglang/zig/issues/4866
62 return error.SkipZigTest;
63 }
64
65 const x: u32 = 10;
66 @export(&x, .{ .name = "exporting_comptime_known_value_foo" });
67 const S = struct {
68 extern const exporting_comptime_known_value_foo: u32;
69 };
70 try expect(S.exporting_comptime_known_value_foo == 10);
71}