| ... | ... | @@ -44,7 +44,7 @@ const test_targets = blk: { |
| 44 | 44 | break :blk [_]TestTarget{ |
| 45 | 45 | // Native Targets |
| 46 | 46 | |
| 47 | | .{}, |
| 47 | .{}, // 0 index must be all defaults |
| 48 | 48 | .{ |
| 49 | 49 | .link_libc = true, |
| 50 | 50 | }, |
| ... | ... | @@ -2224,6 +2224,7 @@ const ModuleTestOptions = struct { |
| 2224 | 2224 | desc: []const u8, |
| 2225 | 2225 | optimize_modes: []const OptimizeMode, |
| 2226 | 2226 | include_paths: []const []const u8, |
| 2227 | test_default_only: bool, |
| 2227 | 2228 | skip_single_threaded: bool, |
| 2228 | 2229 | skip_non_native: bool, |
| 2229 | 2230 | skip_freebsd: bool, |
| ... | ... | @@ -2235,13 +2236,21 @@ const ModuleTestOptions = struct { |
| 2235 | 2236 | skip_libc: bool, |
| 2236 | 2237 | max_rss: usize = 0, |
| 2237 | 2238 | no_builtin: bool = false, |
| 2238 | | build_options: ?*std.Build.Step.Options = null, |
| 2239 | build_options: ?*Step.Options = null, |
| 2239 | 2240 | }; |
| 2240 | 2241 | |
| 2241 | 2242 | pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 2242 | 2243 | const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc); |
| 2243 | 2244 | |
| 2244 | | for_targets: for (test_targets) |test_target| { |
| 2245 | if (options.test_default_only) { |
| 2246 | const test_target = &test_targets[0]; |
| 2247 | const resolved_target = b.resolveTargetQuery(test_target.target); |
| 2248 | const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); |
| 2249 | addOneModuleTest(b, step, test_target, &resolved_target, triple_txt, options); |
| 2250 | return step; |
| 2251 | } |
| 2252 | |
| 2253 | for_targets: for (&test_targets) |*test_target| { |
| 2245 | 2254 | if (test_target.skip_modules.len > 0) { |
| 2246 | 2255 | for (test_target.skip_modules) |skip_mod| { |
| 2247 | 2256 | if (std.mem.eql(u8, options.name, skip_mod)) continue :for_targets; |
| ... | ... | @@ -2306,167 +2315,180 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 2306 | 2315 | } else false; |
| 2307 | 2316 | if (!want_this_mode) continue; |
| 2308 | 2317 | |
| 2309 | | const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; |
| 2310 | | const model_txt = target.cpu.model.name; |
| 2318 | addOneModuleTest(b, step, test_target, &resolved_target, triple_txt, options); |
| 2319 | } |
| 2320 | return step; |
| 2321 | } |
| 2311 | 2322 | |
| 2312 | | // wasm32-wasi builds need more RAM, idk why |
| 2313 | | const max_rss = if (target.os.tag == .wasi) |
| 2314 | | options.max_rss * 2 |
| 2315 | | else |
| 2316 | | options.max_rss; |
| 2323 | fn addOneModuleTest( |
| 2324 | b: *std.Build, |
| 2325 | step: *Step, |
| 2326 | test_target: *const TestTarget, |
| 2327 | resolved_target: *const std.Build.ResolvedTarget, |
| 2328 | triple_txt: []const u8, |
| 2329 | options: ModuleTestOptions, |
| 2330 | ) void { |
| 2331 | const target = &resolved_target.result; |
| 2332 | const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; |
| 2333 | const model_txt = target.cpu.model.name; |
| 2334 | |
| 2335 | // wasm32-wasi builds need more RAM, idk why |
| 2336 | const max_rss = if (target.os.tag == .wasi) |
| 2337 | options.max_rss * 2 |
| 2338 | else |
| 2339 | options.max_rss; |
| 2340 | |
| 2341 | const these_tests = b.addTest(.{ |
| 2342 | .root_module = b.createModule(.{ |
| 2343 | .root_source_file = b.path(options.root_src), |
| 2344 | .optimize = test_target.optimize_mode, |
| 2345 | .target = resolved_target.*, |
| 2346 | .link_libc = test_target.link_libc, |
| 2347 | .pic = test_target.pic, |
| 2348 | .strip = test_target.strip, |
| 2349 | .single_threaded = test_target.single_threaded, |
| 2350 | }), |
| 2351 | .max_rss = max_rss, |
| 2352 | .filters = options.test_filters, |
| 2353 | .use_llvm = test_target.use_llvm, |
| 2354 | .use_lld = test_target.use_lld, |
| 2355 | .zig_lib_dir = b.path("lib"), |
| 2356 | }); |
| 2357 | these_tests.linkage = test_target.linkage; |
| 2358 | if (options.no_builtin) these_tests.root_module.no_builtin = false; |
| 2359 | if (options.build_options) |build_options| { |
| 2360 | these_tests.root_module.addOptions("build_options", build_options); |
| 2361 | } |
| 2362 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; |
| 2363 | const backend_suffix = if (test_target.use_llvm == true) |
| 2364 | "-llvm" |
| 2365 | else if (target.ofmt == std.Target.ObjectFormat.c) |
| 2366 | "-cbe" |
| 2367 | else if (test_target.use_llvm == false) |
| 2368 | "-selfhosted" |
| 2369 | else |
| 2370 | ""; |
| 2371 | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; |
| 2372 | const linkage_name = if (test_target.linkage) |linkage| switch (linkage) { |
| 2373 | inline else => |t| "-" ++ @tagName(t), |
| 2374 | } else ""; |
| 2375 | const use_pic = if (test_target.pic == true) "-pic" else ""; |
| 2376 | |
| 2377 | for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path)); |
| 2378 | |
| 2379 | const qualified_name = b.fmt("{s}-{s}-{s}-{t}{s}{s}{s}{s}{s}{s}", .{ |
| 2380 | options.name, |
| 2381 | triple_txt, |
| 2382 | model_txt, |
| 2383 | test_target.optimize_mode, |
| 2384 | libc_suffix, |
| 2385 | single_threaded_suffix, |
| 2386 | backend_suffix, |
| 2387 | use_lld, |
| 2388 | linkage_name, |
| 2389 | use_pic, |
| 2390 | }); |
| 2317 | 2391 | |
| 2318 | | const these_tests = b.addTest(.{ |
| 2319 | | .root_module = b.createModule(.{ |
| 2320 | | .root_source_file = b.path(options.root_src), |
| 2321 | | .optimize = test_target.optimize_mode, |
| 2322 | | .target = resolved_target, |
| 2323 | | .link_libc = test_target.link_libc, |
| 2324 | | .pic = test_target.pic, |
| 2325 | | .strip = test_target.strip, |
| 2326 | | .single_threaded = test_target.single_threaded, |
| 2327 | | }), |
| 2328 | | .max_rss = max_rss, |
| 2329 | | .filters = options.test_filters, |
| 2330 | | .use_llvm = test_target.use_llvm, |
| 2331 | | .use_lld = test_target.use_lld, |
| 2332 | | .zig_lib_dir = b.path("lib"), |
| 2392 | if (target.ofmt == std.Target.ObjectFormat.c) { |
| 2393 | var altered_query = test_target.target; |
| 2394 | altered_query.ofmt = null; |
| 2395 | |
| 2396 | const compile_c = b.createModule(.{ |
| 2397 | .root_source_file = null, |
| 2398 | .link_libc = test_target.link_libc, |
| 2399 | .target = b.resolveTargetQuery(altered_query), |
| 2333 | 2400 | }); |
| 2334 | | these_tests.linkage = test_target.linkage; |
| 2335 | | if (options.no_builtin) these_tests.root_module.no_builtin = false; |
| 2336 | | if (options.build_options) |build_options| { |
| 2337 | | these_tests.root_module.addOptions("build_options", build_options); |
| 2338 | | } |
| 2339 | | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; |
| 2340 | | const backend_suffix = if (test_target.use_llvm == true) |
| 2341 | | "-llvm" |
| 2342 | | else if (target.ofmt == std.Target.ObjectFormat.c) |
| 2343 | | "-cbe" |
| 2344 | | else if (test_target.use_llvm == false) |
| 2345 | | "-selfhosted" |
| 2346 | | else |
| 2347 | | ""; |
| 2348 | | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; |
| 2349 | | const linkage_name = if (test_target.linkage) |linkage| switch (linkage) { |
| 2350 | | inline else => |t| "-" ++ @tagName(t), |
| 2351 | | } else ""; |
| 2352 | | const use_pic = if (test_target.pic == true) "-pic" else ""; |
| 2353 | | |
| 2354 | | for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path)); |
| 2355 | | |
| 2356 | | const qualified_name = b.fmt("{s}-{s}-{s}-{s}{s}{s}{s}{s}{s}{s}", .{ |
| 2357 | | options.name, |
| 2358 | | triple_txt, |
| 2359 | | model_txt, |
| 2360 | | @tagName(test_target.optimize_mode), |
| 2361 | | libc_suffix, |
| 2362 | | single_threaded_suffix, |
| 2363 | | backend_suffix, |
| 2364 | | use_lld, |
| 2365 | | linkage_name, |
| 2366 | | use_pic, |
| 2401 | const compile_c_exe = b.addExecutable(.{ |
| 2402 | .name = qualified_name, |
| 2403 | .root_module = compile_c, |
| 2404 | .zig_lib_dir = b.path("lib"), |
| 2367 | 2405 | }); |
| 2368 | 2406 | |
| 2369 | | if (target.ofmt == std.Target.ObjectFormat.c) { |
| 2370 | | var altered_query = test_target.target; |
| 2371 | | altered_query.ofmt = null; |
| 2372 | | |
| 2373 | | const compile_c = b.createModule(.{ |
| 2374 | | .root_source_file = null, |
| 2375 | | .link_libc = test_target.link_libc, |
| 2376 | | .target = b.resolveTargetQuery(altered_query), |
| 2377 | | }); |
| 2378 | | const compile_c_exe = b.addExecutable(.{ |
| 2379 | | .name = qualified_name, |
| 2380 | | .root_module = compile_c, |
| 2381 | | .zig_lib_dir = b.path("lib"), |
| 2382 | | }); |
| 2383 | | |
| 2384 | | compile_c.addCSourceFile(.{ |
| 2385 | | .file = these_tests.getEmittedBin(), |
| 2386 | | .flags = &.{ |
| 2387 | | // Tracking issue for making the C backend generate C89 compatible code: |
| 2388 | | // https://github.com/ziglang/zig/issues/19468 |
| 2389 | | "-std=c99", |
| 2390 | | "-Werror", |
| 2391 | | |
| 2392 | | "-Wall", |
| 2393 | | "-Wembedded-directive", |
| 2394 | | "-Wempty-translation-unit", |
| 2395 | | "-Wextra", |
| 2396 | | "-Wgnu", |
| 2397 | | "-Winvalid-utf8", |
| 2398 | | "-Wkeyword-macro", |
| 2399 | | "-Woverlength-strings", |
| 2400 | | |
| 2401 | | // Tracking issue for making the C backend generate code |
| 2402 | | // that does not trigger warnings: |
| 2403 | | // https://github.com/ziglang/zig/issues/19467 |
| 2404 | | |
| 2405 | | // spotted everywhere |
| 2406 | | "-Wno-builtin-requires-header", |
| 2407 | | |
| 2408 | | // spotted on linux |
| 2409 | | "-Wno-braced-scalar-init", |
| 2410 | | "-Wno-excess-initializers", |
| 2411 | | "-Wno-incompatible-pointer-types-discards-qualifiers", |
| 2412 | | "-Wno-unused", |
| 2413 | | "-Wno-unused-parameter", |
| 2414 | | |
| 2415 | | // spotted on darwin |
| 2416 | | "-Wno-incompatible-pointer-types", |
| 2417 | | |
| 2418 | | // https://github.com/llvm/llvm-project/issues/153314 |
| 2419 | | "-Wno-unterminated-string-initialization", |
| 2420 | | |
| 2421 | | // In both Zig and C it is legal to return a pointer to a |
| 2422 | | // local. The C backend lowers such thing directly, so the |
| 2423 | | // corresponding warning in C must be disabled. |
| 2424 | | "-Wno-return-stack-address", |
| 2425 | | }, |
| 2426 | | }); |
| 2427 | | compile_c.addIncludePath(b.path("lib")); // for zig.h |
| 2428 | | if (target.os.tag == .windows) { |
| 2429 | | if (true) { |
| 2430 | | // Unfortunately this requires about 8G of RAM for clang to compile |
| 2431 | | // and our Windows CI runners do not have this much. |
| 2432 | | step.dependOn(&these_tests.step); |
| 2433 | | continue; |
| 2434 | | } |
| 2407 | compile_c.addCSourceFile(.{ |
| 2408 | .file = these_tests.getEmittedBin(), |
| 2409 | .flags = &.{ |
| 2410 | // Tracking issue for making the C backend generate C89 compatible code: |
| 2411 | // https://github.com/ziglang/zig/issues/19468 |
| 2412 | "-std=c99", |
| 2413 | "-Werror", |
| 2414 | |
| 2415 | "-Wall", |
| 2416 | "-Wembedded-directive", |
| 2417 | "-Wempty-translation-unit", |
| 2418 | "-Wextra", |
| 2419 | "-Wgnu", |
| 2420 | "-Winvalid-utf8", |
| 2421 | "-Wkeyword-macro", |
| 2422 | "-Woverlength-strings", |
| 2423 | |
| 2424 | // Tracking issue for making the C backend generate code |
| 2425 | // that does not trigger warnings: |
| 2426 | // https://github.com/ziglang/zig/issues/19467 |
| 2427 | |
| 2428 | // spotted everywhere |
| 2429 | "-Wno-builtin-requires-header", |
| 2430 | |
| 2431 | // spotted on linux |
| 2432 | "-Wno-braced-scalar-init", |
| 2433 | "-Wno-excess-initializers", |
| 2434 | "-Wno-incompatible-pointer-types-discards-qualifiers", |
| 2435 | "-Wno-unused", |
| 2436 | "-Wno-unused-parameter", |
| 2437 | |
| 2438 | // spotted on darwin |
| 2439 | "-Wno-incompatible-pointer-types", |
| 2440 | |
| 2441 | // https://github.com/llvm/llvm-project/issues/153314 |
| 2442 | "-Wno-unterminated-string-initialization", |
| 2443 | |
| 2444 | // In both Zig and C it is legal to return a pointer to a |
| 2445 | // local. The C backend lowers such thing directly, so the |
| 2446 | // corresponding warning in C must be disabled. |
| 2447 | "-Wno-return-stack-address", |
| 2448 | }, |
| 2449 | }); |
| 2450 | compile_c.addIncludePath(b.path("lib")); // for zig.h |
| 2451 | if (target.os.tag == .windows) { |
| 2452 | if (true) { |
| 2453 | // Unfortunately this requires about 8G of RAM for clang to compile |
| 2454 | // and our Windows CI runners do not have this much. |
| 2455 | // TODO This is not an appropriate way to work around this problem. |
| 2456 | step.dependOn(&these_tests.step); |
| 2457 | return; |
| 2458 | } |
| 2459 | if (test_target.link_libc == false) { |
| 2460 | compile_c_exe.subsystem = .Console; |
| 2461 | compile_c.linkSystemLibrary("kernel32", .{}); |
| 2462 | compile_c.linkSystemLibrary("ntdll", .{}); |
| 2463 | } |
| 2464 | if (mem.eql(u8, options.name, "std")) { |
| 2435 | 2465 | if (test_target.link_libc == false) { |
| 2436 | | compile_c_exe.subsystem = .Console; |
| 2437 | | compile_c.linkSystemLibrary("kernel32", .{}); |
| 2438 | | compile_c.linkSystemLibrary("ntdll", .{}); |
| 2439 | | } |
| 2440 | | if (mem.eql(u8, options.name, "std")) { |
| 2441 | | if (test_target.link_libc == false) { |
| 2442 | | compile_c.linkSystemLibrary("shell32", .{}); |
| 2443 | | compile_c.linkSystemLibrary("advapi32", .{}); |
| 2444 | | } |
| 2445 | | compile_c.linkSystemLibrary("crypt32", .{}); |
| 2446 | | compile_c.linkSystemLibrary("ws2_32", .{}); |
| 2447 | | compile_c.linkSystemLibrary("ole32", .{}); |
| 2466 | compile_c.linkSystemLibrary("shell32", .{}); |
| 2467 | compile_c.linkSystemLibrary("advapi32", .{}); |
| 2448 | 2468 | } |
| 2469 | compile_c.linkSystemLibrary("crypt32", .{}); |
| 2470 | compile_c.linkSystemLibrary("ws2_32", .{}); |
| 2471 | compile_c.linkSystemLibrary("ole32", .{}); |
| 2449 | 2472 | } |
| 2473 | } |
| 2450 | 2474 | |
| 2451 | | const run = b.addRunArtifact(compile_c_exe); |
| 2452 | | run.skip_foreign_checks = true; |
| 2453 | | run.enableTestRunnerMode(); |
| 2454 | | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| 2475 | const run = b.addRunArtifact(compile_c_exe); |
| 2476 | run.skip_foreign_checks = true; |
| 2477 | run.enableTestRunnerMode(); |
| 2478 | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| 2455 | 2479 | |
| 2456 | | step.dependOn(&run.step); |
| 2457 | | } else if (target.cpu.arch.isSpirV()) { |
| 2458 | | // Don't run spirv binaries |
| 2459 | | _ = these_tests.getEmittedBin(); |
| 2460 | | step.dependOn(&these_tests.step); |
| 2461 | | } else { |
| 2462 | | const run = b.addRunArtifact(these_tests); |
| 2463 | | run.skip_foreign_checks = true; |
| 2464 | | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| 2480 | step.dependOn(&run.step); |
| 2481 | } else if (target.cpu.arch.isSpirV()) { |
| 2482 | // Don't run spirv binaries |
| 2483 | _ = these_tests.getEmittedBin(); |
| 2484 | step.dependOn(&these_tests.step); |
| 2485 | } else { |
| 2486 | const run = b.addRunArtifact(these_tests); |
| 2487 | run.skip_foreign_checks = true; |
| 2488 | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| 2465 | 2489 | |
| 2466 | | step.dependOn(&run.step); |
| 2467 | | } |
| 2490 | step.dependOn(&run.step); |
| 2468 | 2491 | } |
| 2469 | | return step; |
| 2470 | 2492 | } |
| 2471 | 2493 | |
| 2472 | 2494 | pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool { |