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