authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-04 10:22:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-06 23:42:14-07:00
loga59d18779fe71ea0a13899e794ce1de8b526a8a9
tree2480f1f3583d547ef1e654c146ea87893c74c62e
parent5986bdf868a58cdef2adf58ff27b6526eafd99fe

langref: global assembly test depends on llvm

see #24046

2 files changed, 45 insertions(+), 1 deletions(-)

doc/langref/test_global_assembly.zig+1
......@@ -19,3 +19,4 @@ test "global assembly" {
1919
2020// test
2121// target=x86_64-linux
22// llvm=true
tools/doctest.zig+44-1
......@@ -168,6 +168,15 @@ fn printOutput(
168168 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
169169 try shell_out.print("-target {s} ", .{triple});
170170 }
171 if (code.use_llvm) |use_llvm| {
172 if (use_llvm) {
173 try build_args.append("-fllvm");
174 try shell_out.print("-fllvm", .{});
175 } else {
176 try build_args.append("-fno-llvm");
177 try shell_out.print("-fno-llvm", .{});
178 }
179 }
171180 if (code.verbose_cimport) {
172181 try build_args.append("--verbose-cimport");
173182 try shell_out.print("--verbose-cimport ", .{});
......@@ -224,7 +233,6 @@ fn printOutput(
224233 break :code_block;
225234 }
226235 }
227
228236 const target_query = try std.Target.Query.parse(.{
229237 .arch_os_abi = code.target_str orelse "native",
230238 });
......@@ -319,6 +327,16 @@ fn printOutput(
319327 },
320328 }
321329 }
330 if (code.use_llvm) |use_llvm| {
331 if (use_llvm) {
332 try test_args.append("-fllvm");
333 try shell_out.print("-fllvm", .{});
334 } else {
335 try test_args.append("-fno-llvm");
336 try shell_out.print("-fno-llvm", .{});
337 }
338 }
339
322340 const result = run(arena, &env_map, tmp_dir_path, test_args.items) catch
323341 fatal("test failed", .{});
324342 const escaped_stderr = try escapeHtml(arena, result.stderr);
......@@ -469,6 +487,15 @@ fn printOutput(
469487 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
470488 try shell_out.print("-target {s} ", .{triple});
471489 }
490 if (code.use_llvm) |use_llvm| {
491 if (use_llvm) {
492 try build_args.append("-fllvm");
493 try shell_out.print("-fllvm", .{});
494 } else {
495 try build_args.append("-fno-llvm");
496 try shell_out.print("-fno-llvm", .{});
497 }
498 }
472499 for (code.additional_options) |option| {
473500 try build_args.append(option);
474501 try shell_out.print("{s} ", .{option});
......@@ -538,6 +565,15 @@ fn printOutput(
538565 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
539566 try shell_out.print("-target {s} ", .{triple});
540567 }
568 if (code.use_llvm) |use_llvm| {
569 if (use_llvm) {
570 try test_args.append("-fllvm");
571 try shell_out.print("-fllvm", .{});
572 } else {
573 try test_args.append("-fno-llvm");
574 try shell_out.print("-fno-llvm", .{});
575 }
576 }
541577 if (code.link_mode) |link_mode| {
542578 switch (link_mode) {
543579 .static => {
......@@ -827,6 +863,7 @@ const Code = struct {
827863 verbose_cimport: bool,
828864 just_check_syntax: bool,
829865 additional_options: []const []const u8,
866 use_llvm: ?bool,
830867
831868 const Id = union(enum) {
832869 @"test",
......@@ -886,6 +923,7 @@ fn parseManifest(arena: Allocator, source_bytes: []const u8) !Code {
886923 var link_libc = false;
887924 var disable_cache = false;
888925 var verbose_cimport = false;
926 var use_llvm: ?bool = null;
889927
890928 while (it.next()) |prefixed_line| {
891929 const line = skipPrefix(prefixed_line);
......@@ -901,6 +939,10 @@ fn parseManifest(arena: Allocator, source_bytes: []const u8) !Code {
901939 try additional_options.append(arena, line["additional_option=".len..]);
902940 } else if (mem.startsWith(u8, line, "target=")) {
903941 target_str = line["target=".len..];
942 } else if (mem.eql(u8, line, "llvm=true")) {
943 use_llvm = true;
944 } else if (mem.eql(u8, line, "llvm=false")) {
945 use_llvm = false;
904946 } else if (mem.eql(u8, line, "link_libc")) {
905947 link_libc = true;
906948 } else if (mem.eql(u8, line, "disable_cache")) {
......@@ -923,6 +965,7 @@ fn parseManifest(arena: Allocator, source_bytes: []const u8) !Code {
923965 .disable_cache = disable_cache,
924966 .verbose_cimport = verbose_cimport,
925967 .just_check_syntax = just_check_syntax,
968 .use_llvm = use_llvm,
926969 };
927970}
928971