mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-10-28 19:00:52 +08:00
test/link: add .ctor / .dtor tests for mingw test/link: include optimize_mode in the target, and only enable .Debug targets for now
49 lines
1.3 KiB
Zig
49 lines
1.3 KiB
Zig
pub fn addCases(ctx: *LinkContext) void {
|
|
if (ctx.includeTest("ctor-dtor")) |case| {
|
|
if (!ctx.link_libc) return;
|
|
|
|
const obj = case.addObject(.{
|
|
.name = "obj",
|
|
.use_llvm = true,
|
|
.use_lld = true,
|
|
.c_source_bytes =
|
|
\\#include <stdlib.h>
|
|
\\int foo;
|
|
\\__attribute__((constructor))
|
|
\\static void init_foo() {
|
|
\\ foo = 42;
|
|
\\}
|
|
\\__attribute__((destructor))
|
|
\\static void deinit_foo() {
|
|
\\ exit(42);
|
|
\\}
|
|
,
|
|
});
|
|
|
|
const lib = case.addLibrary(.static, .{
|
|
.name = "lib",
|
|
.name_prefix = false,
|
|
.name_target = false,
|
|
});
|
|
lib.root_module.addObject(obj);
|
|
|
|
const exe = case.addExecutable(.{
|
|
.name = "test",
|
|
.zig_source_bytes =
|
|
\\extern var foo: u32;
|
|
\\pub fn main() !u8 {
|
|
\\ if (foo != 42) return 1;
|
|
\\ return 2;
|
|
\\}
|
|
,
|
|
});
|
|
exe.root_module.addObject(obj);
|
|
|
|
const run = case.addRunArtifact(exe);
|
|
run.addCheck(.{ .expect_term = .{ .exited = 42 } });
|
|
}
|
|
}
|
|
|
|
const LinkContext = @import("../tests.zig").LinkContext;
|
|
const std = @import("std");
|