mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:
In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default
const lib = b.addLibrary(.{
.linkage = linkage,
.name = "foo_bar",
.root_module = mod,
});
```
In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
.target = target,
.optimize = optimize,
.linkage = .static // or dynamic
});
mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```
It also matches nicely with `linkLibrary` name.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
42 lines
1.2 KiB
Zig
42 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
|
|
/// This tests the path where DWARF information is embedded in a COFF binary
|
|
pub fn build(b: *std.Build) void {
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
const optimize: std.builtin.OptimizeMode = .Debug;
|
|
const target = if (builtin.os.tag == .windows)
|
|
b.standardTargetOptions(.{})
|
|
else
|
|
b.resolveTargetQuery(.{ .os_tag = .windows });
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "main",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("main.zig"),
|
|
.optimize = optimize,
|
|
.target = target,
|
|
}),
|
|
});
|
|
|
|
const lib = b.addLibrary(.{
|
|
.linkage = .dynamic,
|
|
.name = "shared_lib",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = null,
|
|
.optimize = optimize,
|
|
.target = target,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} });
|
|
exe.root_module.linkLibrary(lib);
|
|
|
|
const run = b.addRunArtifact(exe);
|
|
run.expectExitCode(0);
|
|
run.skip_foreign_checks = true;
|
|
|
|
test_step.dependOn(&run.step);
|
|
}
|