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>
123 lines
4.4 KiB
Zig
123 lines
4.4 KiB
Zig
const std = @import("std");
|
|
pub fn build(b: *std.Build) void {
|
|
const test_filters = b.option(
|
|
[]const []const u8,
|
|
"test-filter",
|
|
"Skip tests that do not match any filter",
|
|
) orelse &[0][]const u8{};
|
|
|
|
const compiler_rt_lib = b.addLibrary(.{
|
|
.linkage = .static,
|
|
.name = "compiler_rt",
|
|
.use_llvm = false,
|
|
.use_lld = false,
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.addWriteFiles().add("compiler_rt.zig", ""),
|
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64 }),
|
|
}),
|
|
});
|
|
compiler_rt_lib.bundle_compiler_rt = true;
|
|
|
|
for ([_]std.Target.Query{
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.bsf_bsr_0_clobbers_result}),
|
|
//.cpu_features_sub = std.Target.x86.featureSet(&.{.sse}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.bsf_bsr_0_clobbers_result}),
|
|
.cpu_features_sub = std.Target.x86.featureSet(&.{
|
|
.cmov,
|
|
//.sse,
|
|
}),
|
|
},
|
|
//.{
|
|
// .cpu_arch = .x86_64,
|
|
// .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
// .cpu_features_sub = std.Target.x86.featureSet(&.{.sse}),
|
|
//},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_sub = std.Target.x86.featureSet(&.{.sse2}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.sse3}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.ssse3}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.sse4_1}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.sse4_2}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
|
|
.cpu_features_add = std.Target.x86.featureSet(&.{.avx}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
|
|
.cpu_features_sub = std.Target.x86.featureSet(&.{.avx2}),
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
|
|
},
|
|
.{
|
|
.cpu_arch = .x86_64,
|
|
.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v4 },
|
|
},
|
|
}) |query| {
|
|
const target = b.resolveTargetQuery(query);
|
|
const cpu = query.serializeCpuAlloc(b.allocator) catch @panic("OOM");
|
|
for ([_][]const u8{
|
|
"math.zig",
|
|
"mem.zig",
|
|
}) |path| {
|
|
const test_mod = b.createModule(.{
|
|
.root_source_file = b.path(path),
|
|
.target = target,
|
|
});
|
|
const test_exe = b.addTest(.{
|
|
.name = std.fs.path.stem(path),
|
|
.filters = test_filters,
|
|
.use_llvm = false,
|
|
.use_lld = false,
|
|
.root_module = test_mod,
|
|
});
|
|
if (!std.Target.x86.featureSetHas(target.result.cpu.features, .sse2)) {
|
|
test_exe.bundle_compiler_rt = false;
|
|
test_mod.linkLibrary(compiler_rt_lib);
|
|
}
|
|
const test_run = b.addRunArtifact(test_exe);
|
|
b.default_step.dependOn(&test_run.step);
|
|
for ([_]*std.Build.Step{
|
|
&test_exe.step,
|
|
&test_run.step,
|
|
}) |step| step.name = b.fmt("{s} {s}", .{ step.name, cpu });
|
|
}
|
|
}
|
|
}
|