mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 19:53:06 +00:00
Introduce the concept of "target query" and "resolved target". A target query is what the user specifies, with some things left to default. A resolved target has the default things discovered and populated. In the future, std.zig.CrossTarget will be rename to std.Target.Query. Introduces `std.Build.resolveTargetQuery` to get from one to the other. The concept of `main_mod_path` is gone, no longer supported. You have to put the root source file at the module root now. * remove deprecated API * update build.zig for the breaking API changes in this branch * move std.Build.Step.Compile.BuildId to std.zig.BuildId * add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions, std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and std.Build.TestOptions. * remove `std.Build.constructCMacro`. There is no use for this API. * deprecate `std.Build.Step.Compile.defineCMacro`. Instead, `std.Build.Module.addCMacro` is provided. - remove `std.Build.Step.Compile.defineCMacroRaw`. * deprecate `std.Build.Step.Compile.linkFrameworkNeeded` - use `std.Build.Module.linkFramework` * deprecate `std.Build.Step.Compile.linkFrameworkWeak` - use `std.Build.Module.linkFramework` * move more logic into `std.Build.Module` * allow `target` and `optimize` to be `null` when creating a Module. Along with other fields, those unspecified options will be inherited from parent `Module` when inserted into an import table. * the `target` field of `addExecutable` is now required. pass `b.host` to get the host target.
90 lines
3.4 KiB
Zig
90 lines
3.4 KiB
Zig
const std = @import("std");
|
|
|
|
pub const requires_stage2 = true;
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
add(b, test_step, .Debug);
|
|
add(b, test_step, .ReleaseFast);
|
|
add(b, test_step, .ReleaseSmall);
|
|
add(b, test_step, .ReleaseSafe);
|
|
}
|
|
|
|
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
|
const import_table = b.addExecutable(.{
|
|
.name = "import_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
.optimize = optimize,
|
|
});
|
|
import_table.entry = .disabled;
|
|
import_table.use_llvm = false;
|
|
import_table.use_lld = false;
|
|
import_table.import_table = true;
|
|
import_table.link_gc_sections = false;
|
|
|
|
const export_table = b.addExecutable(.{
|
|
.name = "export_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
.optimize = optimize,
|
|
});
|
|
export_table.entry = .disabled;
|
|
export_table.use_llvm = false;
|
|
export_table.use_lld = false;
|
|
export_table.export_table = true;
|
|
export_table.link_gc_sections = false;
|
|
|
|
const regular_table = b.addExecutable(.{
|
|
.name = "regular_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
.optimize = optimize,
|
|
});
|
|
regular_table.entry = .disabled;
|
|
regular_table.use_llvm = false;
|
|
regular_table.use_lld = false;
|
|
regular_table.link_gc_sections = false; // Ensure function table is not empty
|
|
|
|
const check_import = import_table.checkObject();
|
|
const check_export = export_table.checkObject();
|
|
const check_regular = regular_table.checkObject();
|
|
|
|
check_import.checkInHeaders();
|
|
check_import.checkExact("Section import");
|
|
check_import.checkExact("entries 1");
|
|
check_import.checkExact("module env");
|
|
check_import.checkExact("name __indirect_function_table");
|
|
check_import.checkExact("kind table");
|
|
check_import.checkExact("type funcref");
|
|
check_import.checkExact("min 1"); // 1 function pointer
|
|
check_import.checkNotPresent("max"); // when importing, we do not provide a max
|
|
check_import.checkNotPresent("Section table"); // we're importing it
|
|
|
|
check_export.checkInHeaders();
|
|
check_export.checkExact("Section export");
|
|
check_export.checkExact("entries 2");
|
|
check_export.checkExact("name __indirect_function_table"); // as per linker specification
|
|
check_export.checkExact("kind table");
|
|
|
|
check_regular.checkInHeaders();
|
|
check_regular.checkExact("Section table");
|
|
check_regular.checkExact("entries 1");
|
|
check_regular.checkExact("type funcref");
|
|
check_regular.checkExact("min 2"); // index starts at 1 & 1 function pointer = 2.
|
|
check_regular.checkExact("max 2");
|
|
|
|
check_regular.checkInHeaders();
|
|
check_regular.checkExact("Section element");
|
|
check_regular.checkExact("entries 1");
|
|
check_regular.checkExact("table index 0");
|
|
check_regular.checkExact("i32.const 1"); // we want to start function indexes at 1
|
|
check_regular.checkExact("indexes 1"); // 1 function pointer
|
|
|
|
test_step.dependOn(&check_import.step);
|
|
test_step.dependOn(&check_export.step);
|
|
test_step.dependOn(&check_regular.step);
|
|
}
|