Even better test parameters

This commit is contained in:
David Gonzalez Martin 2025-02-20 21:28:41 -06:00
parent 322c2aaa8b
commit 34a3514856
5 changed files with 28 additions and 24 deletions

View File

@ -61,9 +61,6 @@ jobs:
matrix:
os: [ ubuntu-24.04 ]
BIRTH_ZIG_BUILD_TYPE: ${{ fromJSON(needs.generate-config.outputs.BIRTH_ZIG_BUILD_TYPES) }}
SYSTEM_LLVM: [ true, false ]
TEST_BUILD_MODE: [ debug_none, debug_fast, debug_size, soft_optimize, optimize_for_speed, optimize_for_size, aggressively_optimize_for_speed, aggressively_optimize_for_size ]
HAS_DEBUG_INFO: [ true, false ]
runs-on: ${{ matrix.os }}
env:
BIRTH_LINUX_IMAGE: ${{ needs.generate-config.outputs.BIRTH_LINUX_IMAGE }}
@ -77,8 +74,13 @@ jobs:
version: master
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y llvm-dev liblld-dev
- name: Build and test
- name: Build and test (Packaged LLVM)
run: |
zig build test --summary all -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=${{matrix.SYSTEM_LLVM}} -Dtest_build_mode=${{matrix.TEST_BUILD_MODE}} -Dhas_debug_info=${{matrix.HAS_DEBUG_INFO}}
zig build install -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=${{matrix.SYSTEM_LLVM}}
zig build test --summary all -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=false
zig build install -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=false
ldd zig-out/bin/bloat-buster
- name: Build and test (System LLVM)
run: |
zig build test --summary all -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=true
zig build install -Doptimize=${{matrix.BIRTH_ZIG_BUILD_TYPE}} -Dsystem_llvm=true
ldd zig-out/bin/bloat-buster

View File

@ -302,19 +302,11 @@ pub fn build(b: *std.Build) !void {
system_llvm = b.option(bool, "system_llvm", "Link against system LLVM libraries") orelse true;
const path = env.get("PATH") orelse unreachable;
const test_build_mode = b.option(BuildMode, "test_build_mode", "Test build mode") orelse .debug_none;
const has_debug_info = b.option(bool, "has_debug_info", "Has debug information") orelse true;
const configuration = b.addOptions();
configuration.addOption(BuildMode, "test_build_mode", test_build_mode);
configuration.addOption(u1, "has_debug_info", @intFromBool(has_debug_info));
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addOptions("configuration", configuration);
const llvm = try LLVM.setup(b, path);

View File

@ -3,7 +3,6 @@ const builtin = @import("builtin");
const Arena = lib.Arena;
const assert = lib.assert;
const api = @import("llvm_api.zig");
const configuration = @import("configuration");
/// This is a String which ABI-compatible with C++
pub const String = extern struct {

View File

@ -3,7 +3,6 @@ const assert = lib.assert;
const os = lib.os;
const Arena = lib.Arena;
const llvm = @import("LLVM.zig");
const configuration = @import("configuration");
const LexerResult = struct {
token: Token,
@ -307,7 +306,9 @@ const ConvertOptions = struct {
executable: [:0]const u8,
build_mode: BuildMode,
name: []const u8,
has_debug_info: u1,
};
pub noinline fn convert(options: ConvertOptions) void {
var converter = Converter{
.content = options.content,
@ -478,7 +479,7 @@ pub noinline fn convert(options: ConvertOptions) void {
const object_generate_result = llvm.object_generate(module_builder.module, target_machine, .{
.optimize_when_possible = @intFromBool(@intFromEnum(options.build_mode) > @intFromEnum(BuildMode.soft_optimize)),
.debug_info = configuration.has_debug_info,
.debug_info = options.has_debug_info,
.optimization_level = if (options.build_mode != .debug_none) options.build_mode.to_llvm_ir() else null,
.path = options.object,
});
@ -499,15 +500,25 @@ pub noinline fn convert(options: ConvertOptions) void {
}
}
fn get_test_build_mode() BuildMode {
return @enumFromInt(@intFromEnum(configuration.test_build_mode));
}
test "minimal" {
invoke("minimal", get_test_build_mode());
invoke("minimal");
}
pub fn invoke(name: []const u8, build_mode: BuildMode) void {
fn invoke(name: []const u8) void {
inline for (@typeInfo(BuildMode).@"enum".fields) |f| {
const build_mode = @field(BuildMode, f.name);
inline for ([2]u1{ 0, 1 }) |has_debug_info| {
invoke_wrapper(name, build_mode, has_debug_info);
}
}
}
// We invoke a function with comptime parameters so it's easily visible in CI stack traces
fn invoke_wrapper(name: []const u8, comptime build_mode: BuildMode, comptime has_debug_info: u1) void {
return invoke_single(name, build_mode, has_debug_info);
}
fn invoke_single(name: []const u8, build_mode: BuildMode, has_debug_info: u1) void {
const std = @import("std");
if (!lib.GlobalState.initialized) {
lib.GlobalState.initialize();
@ -531,5 +542,6 @@ pub fn invoke(name: []const u8, build_mode: BuildMode) void {
.executable = executable_path,
.build_mode = build_mode,
.name = name,
.has_debug_info = has_debug_info,
});
}

View File

@ -1,5 +1,4 @@
const lib = @import("lib.zig");
const configuration = @import("configuration");
const llvm = @import("LLVM.zig");
const converter = @import("converter.zig");
const Arena = lib.Arena;