|
| 1 | +const builtin = @import("builtin"); |
| 2 | +const std = @import("std"); |
| 3 | +const expect = std.testing.expect; |
| 4 | + |
| 5 | +test "exporting enum type and value" { |
| 6 | + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 7 | + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 8 | + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 9 | + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 10 | + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 11 | + |
| 12 | + const S = struct { |
| 13 | + const E = enum(c_int) { one, two }; |
| 14 | + const e: E = .two; |
| 15 | + comptime { |
| 16 | + @export(e, .{ .name = "e" }); |
| 17 | + } |
| 18 | + }; |
| 19 | + try expect(S.e == .two); |
| 20 | +} |
| 21 | + |
| 22 | +test "exporting with internal linkage" { |
| 23 | + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 24 | + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 25 | + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 26 | + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 27 | + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 28 | + |
| 29 | + const S = struct { |
| 30 | + fn foo() callconv(.C) void {} |
| 31 | + comptime { |
| 32 | + @export(foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .Internal }); |
| 33 | + } |
| 34 | + }; |
| 35 | + S.foo(); |
| 36 | +} |
| 37 | + |
| 38 | +test "exporting using field access" { |
| 39 | + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 40 | + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 41 | + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 42 | + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 43 | + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 44 | + |
| 45 | + const S = struct { |
| 46 | + const Inner = struct { |
| 47 | + const x: u32 = 5; |
| 48 | + }; |
| 49 | + comptime { |
| 50 | + @export(Inner.x, .{ .name = "foo", .linkage = .Internal }); |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + _ = S.Inner.x; |
| 55 | +} |
| 56 | + |
| 57 | +test "exporting comptime-known value" { |
| 58 | + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 59 | + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 60 | + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 61 | + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 62 | + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 63 | + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 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 | +} |
| 72 | + |
| 73 | +test "exporting comptime var" { |
| 74 | + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 75 | + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 76 | + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 77 | + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 78 | + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 79 | + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 80 | + |
| 81 | + comptime var x: u32 = 5; |
| 82 | + @export(x, .{ .name = "exporting_comptime_var_foo" }); |
| 83 | + x = 7; // modifying this now shouldn't change anything |
| 84 | + const S = struct { |
| 85 | + extern const exporting_comptime_var_foo: u32; |
| 86 | + }; |
| 87 | + try expect(S.exporting_comptime_var_foo == 5); |
| 88 | +} |
0 commit comments