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 const S = struct {
9 const E = enum(c_int) { one, two };
10 const e: E = .two;
11 comptime {
12 @export(&e, .{ .name = "e" });
13 }
14 };
15 try expect(S.e == .two);
16}
17
18test "exporting with internal linkage" {
19 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
20
21 const S = struct {
22 fn foo() callconv(.c) void {}
23 comptime {
24 @export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal });
25 }
26 };
27 S.foo();
28}
29
30test "exporting using namespace access" {
31 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
32
33 const S = struct {
34 const Inner = struct {
35 const x: u32 = 5;
36 };
37 comptime {
38 @export(&Inner.x, .{ .name = "foo", .linkage = .internal });
39 }
40 };
41
42 _ = S.Inner.x;
43}
44
45test "exporting comptime-known value" {
46 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
47 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
48 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
49
50 const x: u32 = 10;
51 @export(&x, .{ .name = "exporting_comptime_known_value_foo" });
52 const S = struct {
53 extern const exporting_comptime_known_value_foo: u32;
54 };
55 try expect(S.exporting_comptime_known_value_foo == 10);
56}