test-link: migrate from deprecated std.Build APIs

This commit is contained in:
mlugg 2024-12-16 16:47:17 +00:00 committed by Eric Joldasov
parent 6179d9ef55
commit 82659c4594
No known key found for this signature in database
GPG Key ID: 5C9C69060686B588
21 changed files with 290 additions and 206 deletions

View File

@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "bss", .name = "bss",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = .Debug, .optimize = .Debug,
}),
}); });
const run = b.addRunArtifact(exe); const run = b.addRunArtifact(exe);

View File

@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib_a = b.addStaticLibrary(.{ const lib_a = b.addStaticLibrary(.{
.name = "a", .name = "a",
.root_module = b.createModule(.{
.root_source_file = null,
.optimize = optimize, .optimize = optimize,
.target = b.graph.host, .target = b.graph.host,
}),
}); });
lib_a.addCSourceFiles(.{ lib_a.root_module.addCSourceFiles(.{
.files = &.{ "c.c", "a.c", "b.c" }, .files = &.{ "c.c", "a.c", "b.c" },
.flags = &.{"-fcommon"}, .flags = &.{"-fcommon"},
}); });
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
}),
}); });
test_exe.linkLibrary(lib_a); test_exe.root_module.linkLibrary(lib_a);
test_step.dependOn(&b.addRunArtifact(test_exe).step); test_step.dependOn(&b.addRunArtifact(test_exe).step);
} }

View File

@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib_a = b.addStaticLibrary(.{ const lib_a = b.addStaticLibrary(.{
.name = "a", .name = "a",
.root_module = b.createModule(.{
.root_source_file = null,
.optimize = optimize, .optimize = optimize,
.target = b.graph.host, .target = b.graph.host,
}),
}); });
lib_a.addCSourceFiles(.{ lib_a.root_module.addCSourceFiles(.{
.files = &.{"a.c"}, .files = &.{"a.c"},
.flags = &.{"-fcommon"}, .flags = &.{"-fcommon"},
}); });
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}),
}); });
test_exe.linkLibrary(lib_a); test_exe.root_module.linkLibrary(lib_a);
test_step.dependOn(&b.addRunArtifact(test_exe).step); test_step.dependOn(&b.addRunArtifact(test_exe).step);
} }

View File

@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void {
for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = t, .name = t,
.root_module = b.createModule(.{
.root_source_file = null,
.target = b.resolveTargetQuery(std.Target.Query.parse( .target = b.resolveTargetQuery(std.Target.Query.parse(
.{ .arch_os_abi = t }, .{ .arch_os_abi = t },
) catch unreachable), ) catch unreachable),
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ .file = b.path("main.c") }); exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
exe.linkLibC();
// TODO: actually test the output // TODO: actually test the output
_ = exe.getEmittedBin(); _ = exe.getEmittedBin();
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = t, .name = t,
.root_module = b.createModule(.{
.root_source_file = null,
.target = target, .target = target,
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
exe.linkLibC();
// Only try running the test if the host glibc is known to be good enough. Ideally, the Zig // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
// test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453
@ -149,10 +155,12 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = t, .name = t,
.root_module = b.createModule(.{
.root_source_file = b.path("glibc_runtime_check.zig"), .root_source_file = b.path("glibc_runtime_check.zig"),
.target = target, .target = target,
.link_libc = true,
}),
}); });
exe.linkLibC();
// Only try running the test if the host glibc is known to be good enough. Ideally, the Zig // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
// test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453

View File

@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib_a = b.addStaticLibrary(.{ const lib_a = b.addStaticLibrary(.{
.name = "a", .name = "a",
.root_module = b.createModule(.{
.root_source_file = null,
.optimize = optimize, .optimize = optimize,
.target = b.graph.host, .target = b.graph.host,
}),
}); });
lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
lib_a.addIncludePath(b.path(".")); lib_a.root_module.addIncludePath(b.path("."));
const lib_b = b.addStaticLibrary(.{ const lib_b = b.addStaticLibrary(.{
.name = "b", .name = "b",
.root_module = b.createModule(.{
.root_source_file = null,
.optimize = optimize, .optimize = optimize,
.target = b.graph.host, .target = b.graph.host,
}),
}); });
lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
lib_b.addIncludePath(b.path(".")); lib_b.root_module.addIncludePath(b.path("."));
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}),
}); });
test_exe.linkLibrary(lib_a); test_exe.root_module.linkLibrary(lib_a);
test_exe.linkLibrary(lib_b); test_exe.root_module.linkLibrary(lib_b);
test_exe.addIncludePath(b.path(".")); test_exe.root_module.addIncludePath(b.path("."));
test_step.dependOn(&b.addRunArtifact(test_exe).step); test_step.dependOn(&b.addRunArtifact(test_exe).step);
} }

View File

@ -47,81 +47,85 @@ const OverlayOptions = struct {
}; };
pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile { pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile {
return addCompileStep(b, base, overlay, .exe); return b.addExecutable(.{
.name = overlay.name,
.root_module = createModule(b, base, overlay),
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,
});
} }
pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile { pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
return addCompileStep(b, base, overlay, .obj); return b.addObject(.{
.name = overlay.name,
.root_module = createModule(b, base, overlay),
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,
});
} }
pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
return addCompileStep(b, base, overlay, .static_lib); return b.addStaticLibrary(.{
.name = overlay.name,
.root_module = createModule(b, base, overlay),
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,
});
} }
pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
return addCompileStep(b, base, overlay, .shared_lib); return b.addSharedLibrary(.{
.name = overlay.name,
.root_module = createModule(b, base, overlay),
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,
});
} }
fn addCompileStep( fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module {
b: *Build, const write_files = b.addWriteFiles();
base: Options,
overlay: OverlayOptions, const mod = b.createModule(.{
kind: enum { exe, obj, shared_lib, static_lib },
) *Compile {
const compile_step = Compile.create(b, .{
.name = overlay.name,
.root_module = b.createModule(.{
.target = base.target, .target = base.target,
.optimize = base.optimize, .optimize = base.optimize,
.root_source_file = rsf: { .root_source_file = rsf: {
const bytes = overlay.zig_source_bytes orelse break :rsf null; const bytes = overlay.zig_source_bytes orelse break :rsf null;
const name = b.fmt("{s}.zig", .{overlay.name}); const name = b.fmt("{s}.zig", .{overlay.name});
break :rsf b.addWriteFiles().add(name, bytes); break :rsf write_files.add(name, bytes);
}, },
.pic = overlay.pic, .pic = overlay.pic,
.strip = if (base.strip) |s| s else overlay.strip, .strip = if (base.strip) |s| s else overlay.strip,
}),
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,
.kind = switch (kind) {
.exe => .exe,
.obj => .obj,
.shared_lib, .static_lib => .lib,
},
.linkage = switch (kind) {
.exe, .obj => null,
.shared_lib => .dynamic,
.static_lib => .static,
},
}); });
if (overlay.objcpp_source_bytes) |bytes| { if (overlay.objcpp_source_bytes) |bytes| {
compile_step.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.addWriteFiles().add("a.mm", bytes), .file = write_files.add("a.mm", bytes),
.flags = overlay.objcpp_source_flags, .flags = overlay.objcpp_source_flags,
}); });
} }
if (overlay.objc_source_bytes) |bytes| { if (overlay.objc_source_bytes) |bytes| {
compile_step.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.addWriteFiles().add("a.m", bytes), .file = write_files.add("a.m", bytes),
.flags = overlay.objc_source_flags, .flags = overlay.objc_source_flags,
}); });
} }
if (overlay.cpp_source_bytes) |bytes| { if (overlay.cpp_source_bytes) |bytes| {
compile_step.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.addWriteFiles().add("a.cpp", bytes), .file = write_files.add("a.cpp", bytes),
.flags = overlay.cpp_source_flags, .flags = overlay.cpp_source_flags,
}); });
} }
if (overlay.c_source_bytes) |bytes| { if (overlay.c_source_bytes) |bytes| {
compile_step.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.addWriteFiles().add("a.c", bytes), .file = write_files.add("a.c", bytes),
.flags = overlay.c_source_flags, .flags = overlay.c_source_flags,
}); });
} }
if (overlay.asm_source_bytes) |bytes| { if (overlay.asm_source_bytes) |bytes| {
compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); mod.addAssemblyFile(write_files.add("a.s", bytes));
} }
return compile_step;
return mod;
} }
pub fn addRunArtifact(comp: *Compile) *Run { pub fn addRunArtifact(comp: *Compile) *Run {

View File

@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test1", .name = "test1",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.graph.host, .target = b.graph.host,
}),
}); });
for (files) |file| { for (files) |file| {
exe.addCSourceFile(.{ .file = file, .flags = &flags }); exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags });
} }
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
// using static librairies // using static librairies
{ {
const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
for (files, 1..) |file, i| {
const mod = if (i & 1 == 0) mod_a else mod_b;
mod.addCSourceFile(.{ .file = file, .flags = &flags });
}
const lib_a = b.addStaticLibrary(.{ const lib_a = b.addStaticLibrary(.{
.name = "test2_a", .name = "test2_a",
.target = b.graph.host, .root_module = mod_a,
.optimize = optimize,
}); });
const lib_b = b.addStaticLibrary(.{ const lib_b = b.addStaticLibrary(.{
.name = "test2_b", .name = "test2_b",
.target = b.graph.host, .root_module = mod_b,
.optimize = optimize,
}); });
for (files, 1..) |file, i| {
const lib = if (i & 1 == 0) lib_a else lib_b;
lib.addCSourceFile(.{ .file = file, .flags = &flags });
}
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test2", .name = "test2",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}),
}); });
exe.linkLibrary(lib_a); exe.root_module.linkLibrary(lib_a);
exe.linkLibrary(lib_b); exe.root_module.linkLibrary(lib_b);
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.skip_foreign_checks = true; run_cmd.skip_foreign_checks = true;
@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
// using static librairies and object files // using static librairies and object files
{ {
const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
for (files, 1..) |file, i| {
const obj_mod = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
obj_mod.addCSourceFile(.{ .file = file, .flags = &flags });
const obj = b.addObject(.{
.name = b.fmt("obj_{}", .{i}),
.root_module = obj_mod,
});
const lib_mod = if (i & 1 == 0) mod_a else mod_b;
lib_mod.addObject(obj);
}
const lib_a = b.addStaticLibrary(.{ const lib_a = b.addStaticLibrary(.{
.name = "test3_a", .name = "test3_a",
.target = b.graph.host, .root_module = mod_a,
.optimize = optimize,
}); });
const lib_b = b.addStaticLibrary(.{ const lib_b = b.addStaticLibrary(.{
.name = "test3_b", .name = "test3_b",
.target = b.graph.host, .root_module = mod_b,
.optimize = optimize,
}); });
for (files, 1..) |file, i| {
const obj = b.addObject(.{
.name = b.fmt("obj_{}", .{i}),
.target = b.graph.host,
.optimize = optimize,
});
obj.addCSourceFile(.{ .file = file, .flags = &flags });
const lib = if (i & 1 == 0) lib_a else lib_b;
lib.addObject(obj);
}
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test3", .name = "test3",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}),
}); });
exe.linkLibrary(lib_a); exe.root_module.linkLibrary(lib_a);
exe.linkLibrary(lib_b); exe.root_module.linkLibrary(lib_b);
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.skip_foreign_checks = true; run_cmd.skip_foreign_checks = true;

View File

@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
// and therefore link with its archive file. // and therefore link with its archive file.
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "main", .name = "main",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -6,6 +6,7 @@ pub fn build(b: *std.Build) void {
// Library with explicitly set cpu features // Library with explicitly set cpu features
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = .Debug, .optimize = .Debug,
.target = b.resolveTargetQuery(.{ .target = b.resolveTargetQuery(.{
@ -14,6 +15,7 @@ pub fn build(b: *std.Build) void {
.cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
.os_tag = .freestanding, .os_tag = .freestanding,
}), }),
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
{ {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize_mode, .optimize = optimize_mode,
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;
@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
{ {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib2.zig"), .root_source_file = b.path("lib2.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize_mode, .optimize = optimize_mode,
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.optimize = .ReleaseSafe, // to make the output deterministic in address positions .optimize = .ReleaseSafe, // to make the output deterministic in address positions
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_lld = false; lib.use_lld = false;

View File

@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const no_export = b.addExecutable(.{ const no_export = b.addExecutable(.{
.name = "no-export", .name = "no-export",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
}),
}); });
no_export.entry = .disabled; no_export.entry = .disabled;
no_export.use_llvm = false; no_export.use_llvm = false;
@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
const dynamic_export = b.addExecutable(.{ const dynamic_export = b.addExecutable(.{
.name = "dynamic", .name = "dynamic",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
}),
}); });
dynamic_export.entry = .disabled; dynamic_export.entry = .disabled;
dynamic_export.rdynamic = true; dynamic_export.rdynamic = true;
@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
const force_export = b.addExecutable(.{ const force_export = b.addExecutable(.{
.name = "force", .name = "force",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
}),
}); });
force_export.entry = .disabled; force_export.entry = .disabled;
force_export.root_module.export_symbol_names = &.{"foo"}; force_export.root_module.export_symbol_names = &.{"foo"};

View File

@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.import_symbols = true; // import `a` and `b` lib.import_symbols = true; // import `a` and `b`

View File

@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "extern", .name = "extern",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = optimize, .optimize = optimize,
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),
}),
}); });
exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
exe.use_llvm = false; exe.use_llvm = false;

View File

@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const import_table = b.addExecutable(.{ const import_table = b.addExecutable(.{
.name = "import_table", .name = "import_table",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
}),
}); });
import_table.entry = .disabled; import_table.entry = .disabled;
import_table.use_llvm = false; import_table.use_llvm = false;
@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
const export_table = b.addExecutable(.{ const export_table = b.addExecutable(.{
.name = "export_table", .name = "export_table",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
}),
}); });
export_table.entry = .disabled; export_table.entry = .disabled;
export_table.use_llvm = false; export_table.use_llvm = false;
@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
const regular_table = b.addExecutable(.{ const regular_table = b.addExecutable(.{
.name = "regular_table", .name = "regular_table",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
}),
}); });
regular_table.entry = .disabled; regular_table.entry = .disabled;
regular_table.use_llvm = false; regular_table.use_llvm = false;

View File

@ -6,19 +6,23 @@ pub fn build(b: *std.Build) void {
// Wasm Object file which we will use to infer the features from // Wasm Object file which we will use to infer the features from
const c_obj = b.addObject(.{ const c_obj = b.addObject(.{
.name = "c_obj", .name = "c_obj",
.root_module = b.createModule(.{
.root_source_file = null,
.optimize = .Debug, .optimize = .Debug,
.target = b.resolveTargetQuery(.{ .target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32, .cpu_arch = .wasm32,
.cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
.os_tag = .freestanding, .os_tag = .freestanding,
}), }),
}),
}); });
c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
// Wasm library that doesn't have any features specified. This will // Wasm library that doesn't have any features specified. This will
// infer its featureset from other linked object files. // infer its featureset from other linked object files.
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.optimize = .Debug, .optimize = .Debug,
.target = b.resolveTargetQuery(.{ .target = b.resolveTargetQuery(.{
@ -26,11 +30,12 @@ pub fn build(b: *std.Build) void {
.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
.os_tag = .freestanding, .os_tag = .freestanding,
}), }),
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;
lib.use_lld = false; lib.use_lld = false;
lib.addObject(c_obj); lib.root_module.addObject(c_obj);
// Verify the result contains the features from the C Object file. // Verify the result contains the features from the C Object file.
const check = lib.checkObject(); const check = lib.checkObject();

View File

@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -13,6 +13,7 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32, .cpu_arch = .wasm32,
@ -23,6 +24,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
.optimize = optimize_mode, .optimize = optimize_mode,
.strip = false, .strip = false,
.single_threaded = false, .single_threaded = false,
}),
}); });
exe.entry = .disabled; exe.entry = .disabled;
exe.use_lld = false; exe.use_lld = false;

View File

@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const lib = b.addExecutable(.{ const lib = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
.strip = false, .strip = false,
}),
}); });
lib.entry = .disabled; lib.entry = .disabled;
lib.use_llvm = false; lib.use_llvm = false;

View File

@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "lib", .name = "lib",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.optimize = optimize, .optimize = optimize,
.strip = false, .strip = false,
}),
}); });
exe.entry = .disabled; exe.entry = .disabled;
exe.use_llvm = false; exe.use_llvm = false;