pub const Compile = struct {
flags: @This().Flags,
flags2: Flags2,
flags3: Flags3,
flags4: Flags4,
root_module: Module.Index,
root_name: String,
filters: Storage.FlagLengthPrefixedList(.flags, .filters_len, String),
installed_headers: Storage.FlagLengthPrefixedList(.flags, .installed_headers_len, Storage.Extended(InstalledHeader.Flags, InstalledHeader)),
force_undefined_symbols: Storage.FlagLengthPrefixedList(.flags, .force_undefined_symbols_len, String),
expect_errors: Storage.FlagUnion(.flags4, .expect_errors, ExpectErrors),
linker_script: Storage.FlagOptional(.flags4, .linker_script, LazyPath.Index),
version_script: Storage.FlagOptional(.flags4, .version_script, LazyPath.Index),
zig_lib_dir: Storage.FlagOptional(.flags3, .zig_lib_dir, LazyPath.Index),
libc_file: Storage.FlagOptional(.flags4, .libc_file, LazyPath.Index),
win32_manifest: Storage.FlagOptional(.flags3, .win32_manifest, LazyPath.Index),
win32_module_definition: Storage.FlagOptional(.flags3, .win32_module_definition, LazyPath.Index),
entitlements: Storage.FlagOptional(.flags4, .entitlements, LazyPath.Index),
version: Storage.FlagOptional(.flags3, .version, String), // semantic version string
entry: Storage.EnumOptional(.flags3, .entry, .symbol_name, String),
install_name: Storage.FlagOptional(.flags4, .install_name, String),
initial_memory: Storage.FlagOptional(.flags3, .initial_memory, u64),
max_memory: Storage.FlagOptional(.flags3, .max_memory, u64),
global_base: Storage.FlagOptional(.flags3, .global_base, u64),
image_base: Storage.FlagOptional(.flags3, .image_base, u64),
link_z_common_page_size: Storage.FlagOptional(.flags4, .link_z_common_page_size, u64),
link_z_max_page_size: Storage.FlagOptional(.flags4, .link_z_max_page_size, u64),
pagezero_size: Storage.FlagOptional(.flags4, .pagezero_size, u64),
stack_size: Storage.FlagOptional(.flags4, .stack_size, u64),
headerpad_size: Storage.FlagOptional(.flags4, .headerpad_size, u32),
error_limit: Storage.FlagOptional(.flags4, .error_limit, u32),
build_id: Storage.EnumOptional(.flags3, .build_id, .hexstring, String),
test_runner: Storage.FlagUnion(.flags3, .test_runner, TestRunner),
emit_directory: Storage.FlagOptional(.flags4, .emit_directory, GeneratedFileIndex),
generated_docs: Storage.FlagOptional(.flags4, .generated_docs, GeneratedFileIndex),
generated_asm: Storage.FlagOptional(.flags4, .generated_asm, GeneratedFileIndex),
generated_bin: Storage.FlagOptional(.flags4, .generated_bin, GeneratedFileIndex),
generated_pdb: Storage.FlagOptional(.flags4, .generated_pdb, GeneratedFileIndex),
generated_implib: Storage.FlagOptional(.flags4, .generated_implib, GeneratedFileIndex),
generated_llvm_bc: Storage.FlagOptional(.flags4, .generated_llvm_bc, GeneratedFileIndex),
generated_llvm_ir: Storage.FlagOptional(.flags4, .generated_llvm_ir, GeneratedFileIndex),
generated_h: Storage.FlagOptional(.flags4, .generated_h, GeneratedFileIndex),
pub const InstalledHeader = union(@This().Tag) {
file: File,
directory: Directory,
pub const Flags = packed struct(u32) {
tag: InstalledHeader.Tag,
_: u24 = 0,
};
pub const Tag = enum(u8) {
file,
directory,
};
pub const File = struct {
flags: @This().Flags = .{},
source: LazyPath.Index,
dest_sub_path: String,
pub const Flags = packed struct(u32) {
tag: InstalledHeader.Tag = .file,
_: u24 = 0,
};
};
pub const Directory = struct {
flags: @This().Flags,
source: LazyPath.Index,
dest_sub_path: String,
exclude_extensions: Storage.FlagLengthPrefixedList(.flags, .exclude_extensions, String),
include_extensions: Storage.FlagLengthPrefixedList(.flags, .include_extensions, String),
pub const Flags = packed struct(u32) {
tag: InstalledHeader.Tag = .directory,
exclude_extensions: bool,
include_extensions: bool,
_: u22 = 0,
};
};
};
pub const ExpectErrors = union(@This().Tag) {
pub const Tag = enum(u3) { contains, exact, starts_with, stderr_contains, none };
contains: String,
exact: Storage.LengthPrefixedList(String),
starts_with: String,
stderr_contains: String,
none: void,
};
pub const TestRunner = union(@This().Tag) {
pub const Tag = enum(u2) { default, simple, server };
default: void,
simple: LazyPath.Index,
server: LazyPath.Index,
};
pub const Entry = enum(u2) { default, disabled, enabled, symbol_name };
pub const Lto = enum(u2) {
none,
full,
thin,
default,
pub fn init(lto: ?std.zig.LtoMode) Lto {
return switch (lto orelse return .default) {
.none => .none,
.full => .full,
.thin => .thin,
};
}
};
pub const BuildId = enum(u3) {
none,
fast,
uuid,
sha1,
md5,
hexstring,
default,
pub fn init(build_id: ?std.zig.BuildId) BuildId {
return switch (build_id orelse return .default) {
.none => .none,
.fast => .fast,
.uuid => .uuid,
.sha1 => .sha1,
.md5 => .md5,
.hexstring => .hexstring,
};
}
pub fn unwrap(this: @This(), hexstring: ?String, c: *const Configuration) ?std.zig.BuildId {
if (hexstring) |h| {
assert(this == .hexstring);
return .initHexString(h.slice(c));
}
return switch (this) {
.none => .none,
.fast => .fast,
.uuid => .uuid,
.sha1 => .sha1,
.md5 => .md5,
.hexstring => unreachable,
.default => null,
};
}
};
pub const WasiExecModel = enum(u2) {
default,
command,
reactor,
pub fn init(wasi_exec_model: ?std.builtin.WasiExecModel) WasiExecModel {
return switch (wasi_exec_model orelse return .default) {
.command => .command,
.reactor => .reactor,
};
}
};
pub const Linkage = enum(u2) {
static,
dynamic,
default,
pub fn init(link_mode: ?std.builtin.LinkMode) Linkage {
return switch (link_mode orelse return .default) {
.static => .static,
.dynamic => .dynamic,
};
}
pub fn unwrap(this: @This()) ?std.builtin.LinkMode {
return switch (this) {
.static => .static,
.dynamic => .dynamic,
.default => null,
};
}
};
pub const Kind = enum(u3) {
exe,
lib,
obj,
@"test",
test_obj,
pub fn isTest(kind: Kind) bool {
return switch (kind) {
.exe, .lib, .obj => false,
.@"test", .test_obj => true,
};
}
pub fn toOutputMode(kind: Kind) std.builtin.OutputMode {
return switch (kind) {
.exe, .@"test" => .Exe,
.lib => .Lib,
.obj, .test_obj => .Obj,
};
}
};
pub const Subsystem = enum(u4) {
console,
windows,
posix,
native,
efi_application,
efi_boot_service_driver,
efi_rom,
efi_runtime_driver,
default,
pub fn init(subsystem: ?std.zig.Subsystem) Subsystem {
return switch (subsystem orelse return .default) {
.console => .console,
.windows => .windows,
.posix => .posix,
.native => .native,
.efi_application => .efi_application,
.efi_boot_service_driver => .efi_boot_service_driver,
.efi_rom => .efi_rom,
.efi_runtime_driver => .efi_runtime_driver,
};
}
};
pub const Flags = packed struct(u32) {
tag: Tag = .compile,
filters_len: bool,
installed_headers_len: bool,
force_undefined_symbols_len: bool,
verbose_link: bool,
verbose_cc: bool,
rdynamic: bool,
import_memory: bool,
export_memory: bool,
import_symbols: bool,
import_table: bool,
export_table: bool,
growable_table: bool,
shared_memory: bool,
link_eh_frame_hdr: bool,
link_emit_relocs: bool,
link_function_sections: bool,
link_data_sections: bool,
linker_dynamicbase: bool,
link_z_notext: bool,
link_z_relro: bool,
link_z_lazy: bool,
link_z_defs: bool,
headerpad_max_install_names: bool,
dead_strip_dylibs: bool,
force_load_objc: bool,
discard_local_symbols: bool,
mingw_unicode_entry_point: bool,
};
pub const Flags2 = packed struct(u32) {
pie: DefaultingBool,
formatted_panics: DefaultingBool,
bundle_compiler_rt: DefaultingBool,
bundle_ubsan_rt: DefaultingBool,
each_lib_rpath: DefaultingBool,
link_gc_sections: DefaultingBool,
linker_allow_shlib_undefined: DefaultingBool,
linker_allow_undefined_version: DefaultingBool,
linker_enable_new_dtags: DefaultingBool,
dll_export_fns: DefaultingBool,
use_llvm: DefaultingBool,
use_lld: DefaultingBool,
use_new_linker: DefaultingBool,
allow_so_scripts: DefaultingBool,
sanitize_coverage_trace_pc_guard: DefaultingBool,
linkage: Linkage,
};
pub const Flags3 = packed struct(u32) {
version: bool,
initial_memory: bool,
max_memory: bool,
kind: Kind,
compress_debug_sections: std.zig.CompressDebugSections,
global_base: bool,
test_runner: TestRunner.Tag,
wasi_exec_model: WasiExecModel,
win32_manifest: bool,
win32_module_definition: bool,
zig_lib_dir: bool,
rc_includes: std.zig.RcIncludes,
image_base: bool,
build_id: BuildId,
entry: Entry,
lto: Lto,
subsystem: Subsystem,
_: u2 = 0,
};
pub const Flags4 = packed struct(u32) {
libc_file: bool,
link_z_common_page_size: bool,
link_z_max_page_size: bool,
pagezero_size: bool,
stack_size: bool,
headerpad_size: bool,
error_limit: bool,
install_name: bool,
entitlements: bool,
expect_errors: ExpectErrors.Tag,
linker_script: bool,
version_script: bool,
emit_directory: bool,
generated_docs: bool,
generated_asm: bool,
generated_bin: bool,
generated_pdb: bool,
generated_implib: bool,
generated_llvm_bc: bool,
generated_llvm_ir: bool,
generated_h: bool,
incremental: DefaultingBool,
_: u7 = 0,
};
pub fn isDynamicLibrary(compile: *const Compile) bool {
return compile.flags3.kind == .lib and compile.flags2.linkage == .dynamic;
}
pub fn isStaticLibrary(compile: *const Compile) bool {
return compile.flags3.kind == .lib and compile.flags2.linkage != .dynamic;
}
pub fn producesImplib(compile: *const Compile, c: *const Configuration) bool {
return isDll(compile, c);
}
pub fn isDll(compile: *const Compile, c: *const Configuration) bool {
return isDynamicLibrary(compile) and rootModuleTarget(compile, c).flags.os_tag == .windows;
}
pub fn rootModuleTarget(compile: *const Compile, c: *const Configuration) TargetQuery {
return compile.root_module.get(c).resolved_target.get(c).?.result.get(c);
}
}