| author | |
| committer | |
| log | 82659c4594d12e5b80d2684320e15ce93eedb966 |
| tree | cbef43f220baf1e0ee70e7b550074629807321a5 |
| parent | 6179d9ef55b071677100af27eeb18582c15c149f |
| signature |
21 files changed, 288 insertions(+), 204 deletions(-)
test/link/bss/build.zig+5-3| ... | ... | @@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | |
| 7 | 7 | const exe = b.addExecutable(.{ |
| 8 | 8 | .name = "bss", |
| 9 | .root_source_file = b.path("main.zig"), | |
| 10 | .target = b.graph.host, | |
| 11 | .optimize = .Debug, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = b.path("main.zig"), | |
| 11 | .target = b.graph.host, | |
| 12 | .optimize = .Debug, | |
| 13 | }), | |
| 12 | 14 | }); |
| 13 | 15 | |
| 14 | 16 | const run = b.addRunArtifact(exe); |
test/link/common_symbols/build.zig+11-6| ... | ... | @@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = null, | |
| 18 | .optimize = optimize, | |
| 19 | .target = b.graph.host, | |
| 20 | }), | |
| 18 | 21 | }); |
| 19 | lib_a.addCSourceFiles(.{ | |
| 22 | lib_a.root_module.addCSourceFiles(.{ | |
| 20 | 23 | .files = &.{ "c.c", "a.c", "b.c" }, |
| 21 | 24 | .flags = &.{"-fcommon"}, |
| 22 | 25 | }); |
| 23 | 26 | |
| 24 | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 28 | .root_module = b.createModule(.{ | |
| 29 | .root_source_file = b.path("main.zig"), | |
| 30 | .optimize = optimize, | |
| 31 | }), | |
| 27 | 32 | }); |
| 28 | test_exe.linkLibrary(lib_a); | |
| 33 | test_exe.root_module.linkLibrary(lib_a); | |
| 29 | 34 | |
| 30 | 35 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 31 | 36 | } |
test/link/common_symbols_alignment/build.zig+12-6| ... | ... | @@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = null, | |
| 18 | .optimize = optimize, | |
| 19 | .target = b.graph.host, | |
| 20 | }), | |
| 18 | 21 | }); |
| 19 | lib_a.addCSourceFiles(.{ | |
| 22 | lib_a.root_module.addCSourceFiles(.{ | |
| 20 | 23 | .files = &.{"a.c"}, |
| 21 | 24 | .flags = &.{"-fcommon"}, |
| 22 | 25 | }); |
| 23 | 26 | |
| 24 | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 28 | .root_module = b.createModule(.{ | |
| 29 | .root_source_file = b.path("main.zig"), | |
| 30 | .target = b.graph.host, | |
| 31 | .optimize = optimize, | |
| 32 | }), | |
| 27 | 33 | }); |
| 28 | test_exe.linkLibrary(lib_a); | |
| 34 | test_exe.root_module.linkLibrary(lib_a); | |
| 29 | 35 | |
| 30 | 36 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 31 | 37 | } |
test/link/glibc_compat/build.zig+19-11| ... | ... | @@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { |
| 15 | 15 | const exe = b.addExecutable(.{ |
| 16 | 16 | .name = t, |
| 17 | .target = b.resolveTargetQuery(std.Target.Query.parse( | |
| 18 | .{ .arch_os_abi = t }, | |
| 19 | ) catch unreachable), | |
| 17 | .root_module = b.createModule(.{ | |
| 18 | .root_source_file = null, | |
| 19 | .target = b.resolveTargetQuery(std.Target.Query.parse( | |
| 20 | .{ .arch_os_abi = t }, | |
| 21 | ) catch unreachable), | |
| 22 | .link_libc = true, | |
| 23 | }), | |
| 20 | 24 | }); |
| 21 | exe.addCSourceFile(.{ .file = b.path("main.c") }); | |
| 22 | exe.linkLibC(); | |
| 25 | exe.root_module.addCSourceFile(.{ .file = b.path("main.c") }); | |
| 23 | 26 | // TODO: actually test the output |
| 24 | 27 | _ = exe.getEmittedBin(); |
| 25 | 28 | test_step.dependOn(&exe.step); |
| ... | ... | @@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void { |
| 53 | 56 | |
| 54 | 57 | const exe = b.addExecutable(.{ |
| 55 | 58 | .name = t, |
| 56 | .target = target, | |
| 59 | .root_module = b.createModule(.{ | |
| 60 | .root_source_file = null, | |
| 61 | .target = target, | |
| 62 | .link_libc = true, | |
| 63 | }), | |
| 57 | 64 | }); |
| 58 | exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); | |
| 59 | exe.linkLibC(); | |
| 65 | exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); | |
| 60 | 66 | |
| 61 | 67 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 62 | 68 | // 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 { |
| 149 | 155 | |
| 150 | 156 | const exe = b.addExecutable(.{ |
| 151 | 157 | .name = t, |
| 152 | .root_source_file = b.path("glibc_runtime_check.zig"), | |
| 153 | .target = target, | |
| 158 | .root_module = b.createModule(.{ | |
| 159 | .root_source_file = b.path("glibc_runtime_check.zig"), | |
| 160 | .target = target, | |
| 161 | .link_libc = true, | |
| 162 | }), | |
| 154 | 163 | }); |
| 155 | exe.linkLibC(); | |
| 156 | 164 | |
| 157 | 165 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 158 | 166 | // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 |
test/link/interdependent_static_c_libs/build.zig+22-13| ... | ... | @@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = null, | |
| 18 | .optimize = optimize, | |
| 19 | .target = b.graph.host, | |
| 20 | }), | |
| 18 | 21 | }); |
| 19 | lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); | |
| 20 | lib_a.addIncludePath(b.path(".")); | |
| 22 | lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); | |
| 23 | lib_a.root_module.addIncludePath(b.path(".")); | |
| 21 | 24 | |
| 22 | 25 | const lib_b = b.addStaticLibrary(.{ |
| 23 | 26 | .name = "b", |
| 24 | .optimize = optimize, | |
| 25 | .target = b.graph.host, | |
| 27 | .root_module = b.createModule(.{ | |
| 28 | .root_source_file = null, | |
| 29 | .optimize = optimize, | |
| 30 | .target = b.graph.host, | |
| 31 | }), | |
| 26 | 32 | }); |
| 27 | lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); | |
| 28 | lib_b.addIncludePath(b.path(".")); | |
| 33 | lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); | |
| 34 | lib_b.root_module.addIncludePath(b.path(".")); | |
| 29 | 35 | |
| 30 | 36 | const test_exe = b.addTest(.{ |
| 31 | .root_source_file = b.path("main.zig"), | |
| 32 | .optimize = optimize, | |
| 37 | .root_module = b.createModule(.{ | |
| 38 | .root_source_file = b.path("main.zig"), | |
| 39 | .target = b.graph.host, | |
| 40 | .optimize = optimize, | |
| 41 | }), | |
| 33 | 42 | }); |
| 34 | test_exe.linkLibrary(lib_a); | |
| 35 | test_exe.linkLibrary(lib_b); | |
| 36 | test_exe.addIncludePath(b.path(".")); | |
| 43 | test_exe.root_module.linkLibrary(lib_a); | |
| 44 | test_exe.root_module.linkLibrary(lib_b); | |
| 45 | test_exe.root_module.addIncludePath(b.path(".")); | |
| 37 | 46 | |
| 38 | 47 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 39 | 48 | } |
test/link/link.zig+47-43| ... | ... | @@ -47,81 +47,85 @@ const OverlayOptions = struct { |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 49 | pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile { |
| 50 | return addCompileStep(b, base, overlay, .exe); | |
| 50 | return b.addExecutable(.{ | |
| 51 | .name = overlay.name, | |
| 52 | .root_module = createModule(b, base, overlay), | |
| 53 | .use_llvm = base.use_llvm, | |
| 54 | .use_lld = base.use_lld, | |
| 55 | }); | |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 54 | return addCompileStep(b, base, overlay, .obj); | |
| 59 | return b.addObject(.{ | |
| 60 | .name = overlay.name, | |
| 61 | .root_module = createModule(b, base, overlay), | |
| 62 | .use_llvm = base.use_llvm, | |
| 63 | .use_lld = base.use_lld, | |
| 64 | }); | |
| 55 | 65 | } |
| 56 | 66 | |
| 57 | 67 | pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 58 | return addCompileStep(b, base, overlay, .static_lib); | |
| 68 | return b.addStaticLibrary(.{ | |
| 69 | .name = overlay.name, | |
| 70 | .root_module = createModule(b, base, overlay), | |
| 71 | .use_llvm = base.use_llvm, | |
| 72 | .use_lld = base.use_lld, | |
| 73 | }); | |
| 59 | 74 | } |
| 60 | 75 | |
| 61 | 76 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 62 | return addCompileStep(b, base, overlay, .shared_lib); | |
| 63 | } | |
| 64 | ||
| 65 | fn addCompileStep( | |
| 66 | b: *Build, | |
| 67 | base: Options, | |
| 68 | overlay: OverlayOptions, | |
| 69 | kind: enum { exe, obj, shared_lib, static_lib }, | |
| 70 | ) *Compile { | |
| 71 | const compile_step = Compile.create(b, .{ | |
| 77 | return b.addSharedLibrary(.{ | |
| 72 | 78 | .name = overlay.name, |
| 73 | .root_module = b.createModule(.{ | |
| 74 | .target = base.target, | |
| 75 | .optimize = base.optimize, | |
| 76 | .root_source_file = rsf: { | |
| 77 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 78 | const name = b.fmt("{s}.zig", .{overlay.name}); | |
| 79 | break :rsf b.addWriteFiles().add(name, bytes); | |
| 80 | }, | |
| 81 | .pic = overlay.pic, | |
| 82 | .strip = if (base.strip) |s| s else overlay.strip, | |
| 83 | }), | |
| 79 | .root_module = createModule(b, base, overlay), | |
| 84 | 80 | .use_llvm = base.use_llvm, |
| 85 | 81 | .use_lld = base.use_lld, |
| 86 | .kind = switch (kind) { | |
| 87 | .exe => .exe, | |
| 88 | .obj => .obj, | |
| 89 | .shared_lib, .static_lib => .lib, | |
| 90 | }, | |
| 91 | .linkage = switch (kind) { | |
| 92 | .exe, .obj => null, | |
| 93 | .shared_lib => .dynamic, | |
| 94 | .static_lib => .static, | |
| 82 | }); | |
| 83 | } | |
| 84 | ||
| 85 | fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module { | |
| 86 | const write_files = b.addWriteFiles(); | |
| 87 | ||
| 88 | const mod = b.createModule(.{ | |
| 89 | .target = base.target, | |
| 90 | .optimize = base.optimize, | |
| 91 | .root_source_file = rsf: { | |
| 92 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 93 | const name = b.fmt("{s}.zig", .{overlay.name}); | |
| 94 | break :rsf write_files.add(name, bytes); | |
| 95 | 95 | }, |
| 96 | .pic = overlay.pic, | |
| 97 | .strip = if (base.strip) |s| s else overlay.strip, | |
| 96 | 98 | }); |
| 99 | ||
| 97 | 100 | if (overlay.objcpp_source_bytes) |bytes| { |
| 98 | compile_step.addCSourceFile(.{ | |
| 99 | .file = b.addWriteFiles().add("a.mm", bytes), | |
| 101 | mod.addCSourceFile(.{ | |
| 102 | .file = write_files.add("a.mm", bytes), | |
| 100 | 103 | .flags = overlay.objcpp_source_flags, |
| 101 | 104 | }); |
| 102 | 105 | } |
| 103 | 106 | if (overlay.objc_source_bytes) |bytes| { |
| 104 | compile_step.addCSourceFile(.{ | |
| 105 | .file = b.addWriteFiles().add("a.m", bytes), | |
| 107 | mod.addCSourceFile(.{ | |
| 108 | .file = write_files.add("a.m", bytes), | |
| 106 | 109 | .flags = overlay.objc_source_flags, |
| 107 | 110 | }); |
| 108 | 111 | } |
| 109 | 112 | if (overlay.cpp_source_bytes) |bytes| { |
| 110 | compile_step.addCSourceFile(.{ | |
| 111 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 113 | mod.addCSourceFile(.{ | |
| 114 | .file = write_files.add("a.cpp", bytes), | |
| 112 | 115 | .flags = overlay.cpp_source_flags, |
| 113 | 116 | }); |
| 114 | 117 | } |
| 115 | 118 | if (overlay.c_source_bytes) |bytes| { |
| 116 | compile_step.addCSourceFile(.{ | |
| 117 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 119 | mod.addCSourceFile(.{ | |
| 120 | .file = write_files.add("a.c", bytes), | |
| 118 | 121 | .flags = overlay.c_source_flags, |
| 119 | 122 | }); |
| 120 | 123 | } |
| 121 | 124 | if (overlay.asm_source_bytes) |bytes| { |
| 122 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | |
| 125 | mod.addAssemblyFile(write_files.add("a.s", bytes)); | |
| 123 | 126 | } |
| 124 | return compile_step; | |
| 127 | ||
| 128 | return mod; | |
| 125 | 129 | } |
| 126 | 130 | |
| 127 | 131 | pub fn addRunArtifact(comp: *Compile) *Run { |
test/link/static_libs_from_object_files/build.zig+47-38| ... | ... | @@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 57 | 57 | { |
| 58 | 58 | const exe = b.addExecutable(.{ |
| 59 | 59 | .name = "test1", |
| 60 | .root_source_file = b.path("main.zig"), | |
| 61 | .optimize = optimize, | |
| 62 | .target = b.graph.host, | |
| 60 | .root_module = b.createModule(.{ | |
| 61 | .root_source_file = b.path("main.zig"), | |
| 62 | .optimize = optimize, | |
| 63 | .target = b.graph.host, | |
| 64 | }), | |
| 63 | 65 | }); |
| 64 | 66 | |
| 65 | 67 | for (files) |file| { |
| 66 | exe.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 68 | exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | 71 | const run_cmd = b.addRunArtifact(exe); |
| ... | ... | @@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 75 | 77 | |
| 76 | 78 | // using static librairies |
| 77 | 79 | { |
| 80 | const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 81 | const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 82 | ||
| 83 | for (files, 1..) |file, i| { | |
| 84 | const mod = if (i & 1 == 0) mod_a else mod_b; | |
| 85 | mod.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 86 | } | |
| 87 | ||
| 78 | 88 | const lib_a = b.addStaticLibrary(.{ |
| 79 | 89 | .name = "test2_a", |
| 80 | .target = b.graph.host, | |
| 81 | .optimize = optimize, | |
| 90 | .root_module = mod_a, | |
| 82 | 91 | }); |
| 83 | 92 | const lib_b = b.addStaticLibrary(.{ |
| 84 | 93 | .name = "test2_b", |
| 85 | .target = b.graph.host, | |
| 86 | .optimize = optimize, | |
| 94 | .root_module = mod_b, | |
| 87 | 95 | }); |
| 88 | 96 | |
| 89 | for (files, 1..) |file, i| { | |
| 90 | const lib = if (i & 1 == 0) lib_a else lib_b; | |
| 91 | lib.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 92 | } | |
| 93 | ||
| 94 | 97 | const exe = b.addExecutable(.{ |
| 95 | 98 | .name = "test2", |
| 96 | .root_source_file = b.path("main.zig"), | |
| 97 | .target = b.graph.host, | |
| 98 | .optimize = optimize, | |
| 99 | .root_module = b.createModule(.{ | |
| 100 | .root_source_file = b.path("main.zig"), | |
| 101 | .target = b.graph.host, | |
| 102 | .optimize = optimize, | |
| 103 | }), | |
| 99 | 104 | }); |
| 100 | exe.linkLibrary(lib_a); | |
| 101 | exe.linkLibrary(lib_b); | |
| 105 | exe.root_module.linkLibrary(lib_a); | |
| 106 | exe.root_module.linkLibrary(lib_b); | |
| 102 | 107 | |
| 103 | 108 | const run_cmd = b.addRunArtifact(exe); |
| 104 | 109 | run_cmd.skip_foreign_checks = true; |
| ... | ... | @@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 109 | 114 | |
| 110 | 115 | // using static librairies and object files |
| 111 | 116 | { |
| 112 | const lib_a = b.addStaticLibrary(.{ | |
| 113 | .name = "test3_a", | |
| 114 | .target = b.graph.host, | |
| 115 | .optimize = optimize, | |
| 116 | }); | |
| 117 | const lib_b = b.addStaticLibrary(.{ | |
| 118 | .name = "test3_b", | |
| 119 | .target = b.graph.host, | |
| 120 | .optimize = optimize, | |
| 121 | }); | |
| 117 | const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 118 | const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 122 | 119 | |
| 123 | 120 | for (files, 1..) |file, i| { |
| 121 | const obj_mod = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 122 | obj_mod.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 123 | ||
| 124 | 124 | const obj = b.addObject(.{ |
| 125 | 125 | .name = b.fmt("obj_{}", .{i}), |
| 126 | .target = b.graph.host, | |
| 127 | .optimize = optimize, | |
| 126 | .root_module = obj_mod, | |
| 128 | 127 | }); |
| 129 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 130 | 128 | |
| 131 | const lib = if (i & 1 == 0) lib_a else lib_b; | |
| 132 | lib.addObject(obj); | |
| 129 | const lib_mod = if (i & 1 == 0) mod_a else mod_b; | |
| 130 | lib_mod.addObject(obj); | |
| 133 | 131 | } |
| 134 | 132 | |
| 133 | const lib_a = b.addStaticLibrary(.{ | |
| 134 | .name = "test3_a", | |
| 135 | .root_module = mod_a, | |
| 136 | }); | |
| 137 | const lib_b = b.addStaticLibrary(.{ | |
| 138 | .name = "test3_b", | |
| 139 | .root_module = mod_b, | |
| 140 | }); | |
| 141 | ||
| 135 | 142 | const exe = b.addExecutable(.{ |
| 136 | 143 | .name = "test3", |
| 137 | .root_source_file = b.path("main.zig"), | |
| 138 | .target = b.graph.host, | |
| 139 | .optimize = optimize, | |
| 144 | .root_module = b.createModule(.{ | |
| 145 | .root_source_file = b.path("main.zig"), | |
| 146 | .target = b.graph.host, | |
| 147 | .optimize = optimize, | |
| 148 | }), | |
| 140 | 149 | }); |
| 141 | exe.linkLibrary(lib_a); | |
| 142 | exe.linkLibrary(lib_b); | |
| 150 | exe.root_module.linkLibrary(lib_a); | |
| 151 | exe.root_module.linkLibrary(lib_b); | |
| 143 | 152 | |
| 144 | 153 | const run_cmd = b.addRunArtifact(exe); |
| 145 | 154 | run_cmd.skip_foreign_checks = true; |
test/link/wasm/archive/build.zig+6-4| ... | ... | @@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | // and therefore link with its archive file. |
| 18 | 18 | const lib = b.addExecutable(.{ |
| 19 | 19 | .name = "main", |
| 20 | .root_source_file = b.path("main.zig"), | |
| 21 | .optimize = optimize, | |
| 22 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 23 | .strip = false, | |
| 20 | .root_module = b.createModule(.{ | |
| 21 | .root_source_file = b.path("main.zig"), | |
| 22 | .optimize = optimize, | |
| 23 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 24 | .strip = false, | |
| 25 | }), | |
| 24 | 26 | }); |
| 25 | 27 | lib.entry = .disabled; |
| 26 | 28 | lib.use_llvm = false; |
test/link/wasm/basic-features/build.zig+9-7| ... | ... | @@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | // Library with explicitly set cpu features |
| 7 | 7 | const lib = b.addExecutable(.{ |
| 8 | 8 | .name = "lib", |
| 9 | .root_source_file = b.path("main.zig"), | |
| 10 | .optimize = .Debug, | |
| 11 | .target = b.resolveTargetQuery(.{ | |
| 12 | .cpu_arch = .wasm32, | |
| 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | |
| 15 | .os_tag = .freestanding, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = b.path("main.zig"), | |
| 11 | .optimize = .Debug, | |
| 12 | .target = b.resolveTargetQuery(.{ | |
| 13 | .cpu_arch = .wasm32, | |
| 14 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 15 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | |
| 16 | .os_tag = .freestanding, | |
| 17 | }), | |
| 16 | 18 | }), |
| 17 | 19 | }); |
| 18 | 20 | lib.entry = .disabled; |
test/link/wasm/bss/build.zig+12-8| ... | ... | @@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 16 | 16 | { |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize_mode, | |
| 22 | .strip = false, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("lib.zig"), | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | .optimize = optimize_mode, | |
| 23 | .strip = false, | |
| 24 | }), | |
| 23 | 25 | }); |
| 24 | 26 | lib.entry = .disabled; |
| 25 | 27 | lib.use_llvm = false; |
| ... | ... | @@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 64 | 66 | { |
| 65 | 67 | const lib = b.addExecutable(.{ |
| 66 | 68 | .name = "lib", |
| 67 | .root_source_file = b.path("lib2.zig"), | |
| 68 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 69 | .optimize = optimize_mode, | |
| 70 | .strip = false, | |
| 69 | .root_module = b.createModule(.{ | |
| 70 | .root_source_file = b.path("lib2.zig"), | |
| 71 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 72 | .optimize = optimize_mode, | |
| 73 | .strip = false, | |
| 74 | }), | |
| 71 | 75 | }); |
| 72 | 76 | lib.entry = .disabled; |
| 73 | 77 | lib.use_llvm = false; |
test/link/wasm/export-data/build.zig+5-3| ... | ... | @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { |
| 11 | 11 | |
| 12 | 12 | const lib = b.addExecutable(.{ |
| 13 | 13 | .name = "lib", |
| 14 | .root_source_file = b.path("lib.zig"), | |
| 15 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions | |
| 16 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 14 | .root_module = b.createModule(.{ | |
| 15 | .root_source_file = b.path("lib.zig"), | |
| 16 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions | |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | }), | |
| 17 | 19 | }); |
| 18 | 20 | lib.entry = .disabled; |
| 19 | 21 | lib.use_lld = false; |
test/link/wasm/export/build.zig+15-9| ... | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const no_export = b.addExecutable(.{ |
| 17 | 17 | .name = "no-export", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | no_export.entry = .disabled; |
| 23 | 25 | no_export.use_llvm = false; |
| ... | ... | @@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 25 | 27 | |
| 26 | 28 | const dynamic_export = b.addExecutable(.{ |
| 27 | 29 | .name = "dynamic", |
| 28 | .root_source_file = b.path("main.zig"), | |
| 29 | .optimize = optimize, | |
| 30 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 30 | .root_module = b.createModule(.{ | |
| 31 | .root_source_file = b.path("main.zig"), | |
| 32 | .optimize = optimize, | |
| 33 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 34 | }), | |
| 31 | 35 | }); |
| 32 | 36 | dynamic_export.entry = .disabled; |
| 33 | 37 | dynamic_export.rdynamic = true; |
| ... | ... | @@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 36 | 40 | |
| 37 | 41 | const force_export = b.addExecutable(.{ |
| 38 | 42 | .name = "force", |
| 39 | .root_source_file = b.path("main.zig"), | |
| 40 | .optimize = optimize, | |
| 41 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 43 | .root_module = b.createModule(.{ | |
| 44 | .root_source_file = b.path("main.zig"), | |
| 45 | .optimize = optimize, | |
| 46 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 47 | }), | |
| 42 | 48 | }); |
| 43 | 49 | force_export.entry = .disabled; |
| 44 | 50 | force_export.root_module.export_symbol_names = &.{"foo"}; |
test/link/wasm/extern-mangle/build.zig+5-3| ... | ... | @@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib = b.addExecutable(.{ |
| 15 | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | .optimize = optimize, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = b.path("lib.zig"), | |
| 18 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 19 | .optimize = optimize, | |
| 20 | }), | |
| 19 | 21 | }); |
| 20 | 22 | lib.entry = .disabled; |
| 21 | 23 | lib.import_symbols = true; // import `a` and `b` |
test/link/wasm/extern/build.zig+5-3| ... | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "extern", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); |
| 23 | 25 | exe.use_llvm = false; |
test/link/wasm/function-table/build.zig+15-9| ... | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const import_table = b.addExecutable(.{ |
| 17 | 17 | .name = "import_table", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | import_table.entry = .disabled; |
| 23 | 25 | import_table.use_llvm = false; |
| ... | ... | @@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 27 | 29 | |
| 28 | 30 | const export_table = b.addExecutable(.{ |
| 29 | 31 | .name = "export_table", |
| 30 | .root_source_file = b.path("lib.zig"), | |
| 31 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 32 | .optimize = optimize, | |
| 32 | .root_module = b.createModule(.{ | |
| 33 | .root_source_file = b.path("lib.zig"), | |
| 34 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 35 | .optimize = optimize, | |
| 36 | }), | |
| 33 | 37 | }); |
| 34 | 38 | export_table.entry = .disabled; |
| 35 | 39 | export_table.use_llvm = false; |
| ... | ... | @@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 39 | 43 | |
| 40 | 44 | const regular_table = b.addExecutable(.{ |
| 41 | 45 | .name = "regular_table", |
| 42 | .root_source_file = b.path("lib.zig"), | |
| 43 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 44 | .optimize = optimize, | |
| 46 | .root_module = b.createModule(.{ | |
| 47 | .root_source_file = b.path("lib.zig"), | |
| 48 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 49 | .optimize = optimize, | |
| 50 | }), | |
| 45 | 51 | }); |
| 46 | 52 | regular_table.entry = .disabled; |
| 47 | 53 | regular_table.use_llvm = false; |
test/link/wasm/infer-features/build.zig+18-13| ... | ... | @@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | // Wasm Object file which we will use to infer the features from |
| 7 | 7 | const c_obj = b.addObject(.{ |
| 8 | 8 | .name = "c_obj", |
| 9 | .optimize = .Debug, | |
| 10 | .target = b.resolveTargetQuery(.{ | |
| 11 | .cpu_arch = .wasm32, | |
| 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | |
| 13 | .os_tag = .freestanding, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = null, | |
| 11 | .optimize = .Debug, | |
| 12 | .target = b.resolveTargetQuery(.{ | |
| 13 | .cpu_arch = .wasm32, | |
| 14 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | |
| 15 | .os_tag = .freestanding, | |
| 16 | }), | |
| 14 | 17 | }), |
| 15 | 18 | }); |
| 16 | c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); | |
| 19 | c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); | |
| 17 | 20 | |
| 18 | 21 | // Wasm library that doesn't have any features specified. This will |
| 19 | 22 | // infer its featureset from other linked object files. |
| 20 | 23 | const lib = b.addExecutable(.{ |
| 21 | 24 | .name = "lib", |
| 22 | .root_source_file = b.path("main.zig"), | |
| 23 | .optimize = .Debug, | |
| 24 | .target = b.resolveTargetQuery(.{ | |
| 25 | .cpu_arch = .wasm32, | |
| 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 27 | .os_tag = .freestanding, | |
| 25 | .root_module = b.createModule(.{ | |
| 26 | .root_source_file = b.path("main.zig"), | |
| 27 | .optimize = .Debug, | |
| 28 | .target = b.resolveTargetQuery(.{ | |
| 29 | .cpu_arch = .wasm32, | |
| 30 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 31 | .os_tag = .freestanding, | |
| 32 | }), | |
| 28 | 33 | }), |
| 29 | 34 | }); |
| 30 | 35 | lib.entry = .disabled; |
| 31 | 36 | lib.use_llvm = false; |
| 32 | 37 | lib.use_lld = false; |
| 33 | lib.addObject(c_obj); | |
| 38 | lib.root_module.addObject(c_obj); | |
| 34 | 39 | |
| 35 | 40 | // Verify the result contains the features from the C Object file. |
| 36 | 41 | const check = lib.checkObject(); |
test/link/wasm/producers/build.zig+6-4| ... | ... | @@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void { |
| 16 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("lib.zig"), | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | .optimize = optimize, | |
| 23 | .strip = false, | |
| 24 | }), | |
| 23 | 25 | }); |
| 24 | 26 | lib.entry = .disabled; |
| 25 | 27 | lib.use_llvm = false; |
test/link/wasm/segments/build.zig+6-4| ... | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | lib.entry = .disabled; |
| 24 | 26 | lib.use_llvm = false; |
test/link/wasm/shared-memory/build.zig+11-9| ... | ... | @@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { |
| 14 | 14 | const exe = b.addExecutable(.{ |
| 15 | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | |
| 17 | .target = b.resolveTargetQuery(.{ | |
| 18 | .cpu_arch = .wasm32, | |
| 19 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 20 | .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }), | |
| 21 | .os_tag = .freestanding, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = b.path("lib.zig"), | |
| 18 | .target = b.resolveTargetQuery(.{ | |
| 19 | .cpu_arch = .wasm32, | |
| 20 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 21 | .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }), | |
| 22 | .os_tag = .freestanding, | |
| 23 | }), | |
| 24 | .optimize = optimize_mode, | |
| 25 | .strip = false, | |
| 26 | .single_threaded = false, | |
| 22 | 27 | }), |
| 23 | .optimize = optimize_mode, | |
| 24 | .strip = false, | |
| 25 | .single_threaded = false, | |
| 26 | 28 | }); |
| 27 | 29 | exe.entry = .disabled; |
| 28 | 30 | exe.use_lld = false; |
test/link/wasm/stack_pointer/build.zig+6-4| ... | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | lib.entry = .disabled; |
| 24 | 26 | lib.use_llvm = false; |
test/link/wasm/type/build.zig+6-4| ... | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | exe.entry = .disabled; |
| 24 | 26 | exe.use_llvm = false; |