This commit replaces the "fuzzer" UI, previously accessed with the `--fuzz` and `--port` flags, with a more interesting web UI which allows more interactions with the Zig build system. Most notably, it allows accessing the data emitted by a new "time report" system, which allows users to see which parts of Zig programs take the longest to compile. The option to expose the web UI is `--webui`. By default, it will listen on `[::1]` on a random port, but any IPv6 or IPv4 address can be specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`. The options `--fuzz` and `--time-report` both imply `--webui` if not given. Currently, `--webui` is incompatible with `--watch`; specifying both will cause `zig build` to exit with a fatal error. When the web UI is enabled, the build runner spawns the web server as soon as the configure phase completes. The frontend code consists of one HTML file, one JavaScript file, two CSS files, and a few Zig source files which are built into a WASM blob on-demand -- this is all very similar to the old fuzzer UI. Also inherited from the fuzzer UI is that the build system communicates with web clients over a WebSocket connection. When the build finishes, if `--webui` was passed (i.e. if the web server is running), the build runner does not terminate; it continues running to serve web requests, allowing interactive control of the build system. In the web interface is an overall "status" indicating whether a build is currently running, and also a list of all steps in this build. There are visual indicators (colors and spinners) for in-progress, succeeded, and failed steps. There is a "Rebuild" button which will cause the build system to reset the state of every step (note that this does not affect caching) and evaluate the step graph again. If `--time-report` is passed to `zig build`, a new section of the interface becomes visible, which associates every build step with a "time report". For most steps, this is just a simple "time taken" value. However, for `Compile` steps, the compiler communicates with the build system to provide it with much more interesting information: time taken for various pipeline phases, with a per-declaration and per-file breakdown, sorted by slowest declarations/files first. This feature is still in its early stages: the data can be a little tricky to understand, and there is no way to, for instance, sort by different properties, or filter to certain files. However, it has already given us some interesting statistics, and can be useful for spotting, for instance, particularly complex and slow compile-time logic. Additionally, if a compilation uses LLVM, its time report includes the "LLVM pass timing" information, which was previously accessible with the (now removed) `-ftime-report` compiler flag. To make time reports more useful, ZIR and compilation caches are ignored by the Zig compiler when they are enabled -- in other words, `Compile` steps *always* run, even if their result should be cached. This means that the flag can be used to analyze a project's compile time without having to repeatedly clear cache directory, for instance. However, when using `-fincremental`, updates other than the first will only show you the statistics for what changed on that particular update. Notably, this gives us a fairly nice way to see exactly which declarations were re-analyzed by an incremental update. If `--fuzz` is passed to `zig build`, another section of the web interface becomes visible, this time exposing the fuzzer. This is quite similar to the fuzzer UI this commit replaces, with only a few cosmetic tweaks. The interface is closer than before to supporting multiple fuzz steps at a time (in line with the overall strategy for this build UI, the goal will be for all of the fuzz steps to be accessible in the same interface), but still doesn't actually support it. The fuzzer UI looks quite different under the hood: as a result, various bugs are fixed, although other bugs remain. For instance, viewing the source code of any file other than the root of the main module is completely broken (as on master) due to some bogus file-to-module assignment logic in the fuzzer UI. Implementation notes: * The `lib/build-web/` directory holds the client side of the web UI. * The general server logic is in `std.Build.WebServer`. * Fuzzing-specific logic is in `std.Build.Fuzz`. * `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now relates to the build system web UI in general. * The build runner now has an **actual** general-purpose allocator, because thanks to `--watch` and `--webui`, the process can be arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the arena remains backed by `std.heap.page_allocator` for efficiency. I fixed several crashes caused by conflation of `gpa` and `arena` in the build runner and `std.Build`, but there may still be some I have missed. * The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a *lot* of threads involved. I anticipate this situation improving significantly once the `std.Io` interface (with concurrency support) is introduced.
354 lines
12 KiB
Zig
354 lines
12 KiB
Zig
//! We do this instead of @cImport because the self-hosted compiler is easier
|
|
//! to bootstrap if it does not depend on translate-c.
|
|
|
|
/// Do not compare directly to .True, use toBool() instead.
|
|
pub const Bool = enum(c_int) {
|
|
False,
|
|
True,
|
|
_,
|
|
|
|
pub fn fromBool(b: bool) Bool {
|
|
return @as(Bool, @enumFromInt(@intFromBool(b)));
|
|
}
|
|
|
|
pub fn toBool(b: Bool) bool {
|
|
return b != .False;
|
|
}
|
|
};
|
|
|
|
pub const MemoryBuffer = opaque {
|
|
pub const createMemoryBufferWithMemoryRange = LLVMCreateMemoryBufferWithMemoryRange;
|
|
pub const dispose = LLVMDisposeMemoryBuffer;
|
|
|
|
extern fn LLVMCreateMemoryBufferWithMemoryRange(InputData: [*]const u8, InputDataLength: usize, BufferName: ?[*:0]const u8, RequiresNullTerminator: Bool) *MemoryBuffer;
|
|
extern fn LLVMDisposeMemoryBuffer(MemBuf: *MemoryBuffer) void;
|
|
};
|
|
|
|
/// Make sure to use the *InContext functions instead of the global ones.
|
|
pub const Context = opaque {
|
|
pub const create = LLVMContextCreate;
|
|
extern fn LLVMContextCreate() *Context;
|
|
|
|
pub const dispose = LLVMContextDispose;
|
|
extern fn LLVMContextDispose(C: *Context) void;
|
|
|
|
pub const parseBitcodeInContext2 = LLVMParseBitcodeInContext2;
|
|
extern fn LLVMParseBitcodeInContext2(C: *Context, MemBuf: *MemoryBuffer, OutModule: **Module) Bool;
|
|
|
|
pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit;
|
|
extern fn ZigLLVMSetOptBisectLimit(C: *Context, limit: c_int) void;
|
|
|
|
pub const enableBrokenDebugInfoCheck = ZigLLVMEnableBrokenDebugInfoCheck;
|
|
extern fn ZigLLVMEnableBrokenDebugInfoCheck(C: *Context) void;
|
|
|
|
pub const getBrokenDebugInfo = ZigLLVMGetBrokenDebugInfo;
|
|
extern fn ZigLLVMGetBrokenDebugInfo(C: *Context) bool;
|
|
|
|
pub const intType = LLVMIntTypeInContext;
|
|
extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) *Type;
|
|
};
|
|
|
|
pub const Module = opaque {
|
|
pub const dispose = LLVMDisposeModule;
|
|
extern fn LLVMDisposeModule(*Module) void;
|
|
};
|
|
|
|
pub const disposeMessage = LLVMDisposeMessage;
|
|
extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;
|
|
|
|
pub const TargetMachine = opaque {
|
|
pub const FloatABI = enum(c_int) {
|
|
/// Target-specific (either soft or hard depending on triple, etc).
|
|
Default,
|
|
/// Soft float.
|
|
Soft,
|
|
// Hard float.
|
|
Hard,
|
|
};
|
|
|
|
pub const create = ZigLLVMCreateTargetMachine;
|
|
extern fn ZigLLVMCreateTargetMachine(
|
|
T: *Target,
|
|
Triple: [*:0]const u8,
|
|
CPU: ?[*:0]const u8,
|
|
Features: ?[*:0]const u8,
|
|
Level: CodeGenOptLevel,
|
|
Reloc: RelocMode,
|
|
CodeModel: CodeModel,
|
|
function_sections: bool,
|
|
data_sections: bool,
|
|
float_abi: FloatABI,
|
|
abi_name: ?[*:0]const u8,
|
|
emulated_tls: bool,
|
|
) *TargetMachine;
|
|
|
|
pub const dispose = LLVMDisposeTargetMachine;
|
|
extern fn LLVMDisposeTargetMachine(T: *TargetMachine) void;
|
|
|
|
pub const EmitOptions = extern struct {
|
|
is_debug: bool,
|
|
is_small: bool,
|
|
time_report_out: ?*[*:0]u8,
|
|
tsan: bool,
|
|
sancov: bool,
|
|
lto: LtoPhase,
|
|
allow_fast_isel: bool,
|
|
allow_machine_outliner: bool,
|
|
asm_filename: ?[*:0]const u8,
|
|
bin_filename: ?[*:0]const u8,
|
|
llvm_ir_filename: ?[*:0]const u8,
|
|
bitcode_filename: ?[*:0]const u8,
|
|
coverage: Coverage,
|
|
|
|
pub const LtoPhase = enum(c_int) {
|
|
None,
|
|
ThinPreLink,
|
|
ThinPostLink,
|
|
FullPreLink,
|
|
FullPostLink,
|
|
};
|
|
|
|
pub const Coverage = extern struct {
|
|
CoverageType: Coverage.Type,
|
|
IndirectCalls: bool,
|
|
TraceBB: bool,
|
|
TraceCmp: bool,
|
|
TraceDiv: bool,
|
|
TraceGep: bool,
|
|
Use8bitCounters: bool,
|
|
TracePC: bool,
|
|
TracePCGuard: bool,
|
|
Inline8bitCounters: bool,
|
|
InlineBoolFlag: bool,
|
|
PCTable: bool,
|
|
NoPrune: bool,
|
|
StackDepth: bool,
|
|
TraceLoads: bool,
|
|
TraceStores: bool,
|
|
CollectControlFlow: bool,
|
|
|
|
pub const Type = enum(c_int) {
|
|
None = 0,
|
|
Function,
|
|
BB,
|
|
Edge,
|
|
};
|
|
};
|
|
};
|
|
|
|
pub const emitToFile = ZigLLVMTargetMachineEmitToFile;
|
|
extern fn ZigLLVMTargetMachineEmitToFile(
|
|
T: *TargetMachine,
|
|
M: *Module,
|
|
ErrorMessage: *[*:0]const u8,
|
|
options: *const EmitOptions,
|
|
) bool;
|
|
|
|
pub const createTargetDataLayout = LLVMCreateTargetDataLayout;
|
|
extern fn LLVMCreateTargetDataLayout(*TargetMachine) *TargetData;
|
|
};
|
|
|
|
pub const TargetData = opaque {
|
|
pub const dispose = LLVMDisposeTargetData;
|
|
extern fn LLVMDisposeTargetData(*TargetData) void;
|
|
|
|
pub const abiAlignmentOfType = LLVMABIAlignmentOfType;
|
|
extern fn LLVMABIAlignmentOfType(TD: *TargetData, Ty: *Type) c_uint;
|
|
};
|
|
|
|
pub const Type = opaque {};
|
|
|
|
pub const CodeModel = enum(c_int) {
|
|
Default,
|
|
JITDefault,
|
|
Tiny,
|
|
Small,
|
|
Kernel,
|
|
Medium,
|
|
Large,
|
|
};
|
|
|
|
pub const CodeGenOptLevel = enum(c_int) {
|
|
None,
|
|
Less,
|
|
Default,
|
|
Aggressive,
|
|
};
|
|
|
|
pub const RelocMode = enum(c_int) {
|
|
Default,
|
|
Static,
|
|
PIC,
|
|
DynamicNoPIC,
|
|
ROPI,
|
|
RWPI,
|
|
ROPI_RWPI,
|
|
};
|
|
|
|
pub const Target = opaque {
|
|
pub const getFromTriple = LLVMGetTargetFromTriple;
|
|
extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: *[*:0]const u8) Bool;
|
|
};
|
|
|
|
pub extern fn LLVMInitializeAArch64TargetInfo() void;
|
|
pub extern fn LLVMInitializeAMDGPUTargetInfo() void;
|
|
pub extern fn LLVMInitializeARMTargetInfo() void;
|
|
pub extern fn LLVMInitializeAVRTargetInfo() void;
|
|
pub extern fn LLVMInitializeBPFTargetInfo() void;
|
|
pub extern fn LLVMInitializeHexagonTargetInfo() void;
|
|
pub extern fn LLVMInitializeLanaiTargetInfo() void;
|
|
pub extern fn LLVMInitializeMipsTargetInfo() void;
|
|
pub extern fn LLVMInitializeMSP430TargetInfo() void;
|
|
pub extern fn LLVMInitializeNVPTXTargetInfo() void;
|
|
pub extern fn LLVMInitializePowerPCTargetInfo() void;
|
|
pub extern fn LLVMInitializeRISCVTargetInfo() void;
|
|
pub extern fn LLVMInitializeSparcTargetInfo() void;
|
|
pub extern fn LLVMInitializeSystemZTargetInfo() void;
|
|
pub extern fn LLVMInitializeWebAssemblyTargetInfo() void;
|
|
pub extern fn LLVMInitializeX86TargetInfo() void;
|
|
pub extern fn LLVMInitializeXCoreTargetInfo() void;
|
|
pub extern fn LLVMInitializeXtensaTargetInfo() void;
|
|
pub extern fn LLVMInitializeM68kTargetInfo() void;
|
|
pub extern fn LLVMInitializeCSKYTargetInfo() void;
|
|
pub extern fn LLVMInitializeVETargetInfo() void;
|
|
pub extern fn LLVMInitializeARCTargetInfo() void;
|
|
pub extern fn LLVMInitializeLoongArchTargetInfo() void;
|
|
pub extern fn LLVMInitializeSPIRVTargetInfo() void;
|
|
|
|
pub extern fn LLVMInitializeAArch64Target() void;
|
|
pub extern fn LLVMInitializeAMDGPUTarget() void;
|
|
pub extern fn LLVMInitializeARMTarget() void;
|
|
pub extern fn LLVMInitializeAVRTarget() void;
|
|
pub extern fn LLVMInitializeBPFTarget() void;
|
|
pub extern fn LLVMInitializeHexagonTarget() void;
|
|
pub extern fn LLVMInitializeLanaiTarget() void;
|
|
pub extern fn LLVMInitializeMipsTarget() void;
|
|
pub extern fn LLVMInitializeMSP430Target() void;
|
|
pub extern fn LLVMInitializeNVPTXTarget() void;
|
|
pub extern fn LLVMInitializePowerPCTarget() void;
|
|
pub extern fn LLVMInitializeRISCVTarget() void;
|
|
pub extern fn LLVMInitializeSparcTarget() void;
|
|
pub extern fn LLVMInitializeSystemZTarget() void;
|
|
pub extern fn LLVMInitializeWebAssemblyTarget() void;
|
|
pub extern fn LLVMInitializeX86Target() void;
|
|
pub extern fn LLVMInitializeXCoreTarget() void;
|
|
pub extern fn LLVMInitializeXtensaTarget() void;
|
|
pub extern fn LLVMInitializeM68kTarget() void;
|
|
pub extern fn LLVMInitializeVETarget() void;
|
|
pub extern fn LLVMInitializeCSKYTarget() void;
|
|
pub extern fn LLVMInitializeARCTarget() void;
|
|
pub extern fn LLVMInitializeLoongArchTarget() void;
|
|
pub extern fn LLVMInitializeSPIRVTarget() void;
|
|
|
|
pub extern fn LLVMInitializeAArch64TargetMC() void;
|
|
pub extern fn LLVMInitializeAMDGPUTargetMC() void;
|
|
pub extern fn LLVMInitializeARMTargetMC() void;
|
|
pub extern fn LLVMInitializeAVRTargetMC() void;
|
|
pub extern fn LLVMInitializeBPFTargetMC() void;
|
|
pub extern fn LLVMInitializeHexagonTargetMC() void;
|
|
pub extern fn LLVMInitializeLanaiTargetMC() void;
|
|
pub extern fn LLVMInitializeMipsTargetMC() void;
|
|
pub extern fn LLVMInitializeMSP430TargetMC() void;
|
|
pub extern fn LLVMInitializeNVPTXTargetMC() void;
|
|
pub extern fn LLVMInitializePowerPCTargetMC() void;
|
|
pub extern fn LLVMInitializeRISCVTargetMC() void;
|
|
pub extern fn LLVMInitializeSparcTargetMC() void;
|
|
pub extern fn LLVMInitializeSystemZTargetMC() void;
|
|
pub extern fn LLVMInitializeWebAssemblyTargetMC() void;
|
|
pub extern fn LLVMInitializeX86TargetMC() void;
|
|
pub extern fn LLVMInitializeXCoreTargetMC() void;
|
|
pub extern fn LLVMInitializeXtensaTargetMC() void;
|
|
pub extern fn LLVMInitializeM68kTargetMC() void;
|
|
pub extern fn LLVMInitializeCSKYTargetMC() void;
|
|
pub extern fn LLVMInitializeVETargetMC() void;
|
|
pub extern fn LLVMInitializeARCTargetMC() void;
|
|
pub extern fn LLVMInitializeLoongArchTargetMC() void;
|
|
pub extern fn LLVMInitializeSPIRVTargetMC() void;
|
|
|
|
pub extern fn LLVMInitializeAArch64AsmPrinter() void;
|
|
pub extern fn LLVMInitializeAMDGPUAsmPrinter() void;
|
|
pub extern fn LLVMInitializeARMAsmPrinter() void;
|
|
pub extern fn LLVMInitializeAVRAsmPrinter() void;
|
|
pub extern fn LLVMInitializeBPFAsmPrinter() void;
|
|
pub extern fn LLVMInitializeHexagonAsmPrinter() void;
|
|
pub extern fn LLVMInitializeLanaiAsmPrinter() void;
|
|
pub extern fn LLVMInitializeMipsAsmPrinter() void;
|
|
pub extern fn LLVMInitializeMSP430AsmPrinter() void;
|
|
pub extern fn LLVMInitializeNVPTXAsmPrinter() void;
|
|
pub extern fn LLVMInitializePowerPCAsmPrinter() void;
|
|
pub extern fn LLVMInitializeRISCVAsmPrinter() void;
|
|
pub extern fn LLVMInitializeSparcAsmPrinter() void;
|
|
pub extern fn LLVMInitializeSystemZAsmPrinter() void;
|
|
pub extern fn LLVMInitializeWebAssemblyAsmPrinter() void;
|
|
pub extern fn LLVMInitializeX86AsmPrinter() void;
|
|
pub extern fn LLVMInitializeXCoreAsmPrinter() void;
|
|
pub extern fn LLVMInitializeM68kAsmPrinter() void;
|
|
pub extern fn LLVMInitializeVEAsmPrinter() void;
|
|
pub extern fn LLVMInitializeARCAsmPrinter() void;
|
|
pub extern fn LLVMInitializeLoongArchAsmPrinter() void;
|
|
pub extern fn LLVMInitializeSPIRVAsmPrinter() void;
|
|
|
|
pub extern fn LLVMInitializeAArch64AsmParser() void;
|
|
pub extern fn LLVMInitializeAMDGPUAsmParser() void;
|
|
pub extern fn LLVMInitializeARMAsmParser() void;
|
|
pub extern fn LLVMInitializeAVRAsmParser() void;
|
|
pub extern fn LLVMInitializeBPFAsmParser() void;
|
|
pub extern fn LLVMInitializeHexagonAsmParser() void;
|
|
pub extern fn LLVMInitializeLanaiAsmParser() void;
|
|
pub extern fn LLVMInitializeMipsAsmParser() void;
|
|
pub extern fn LLVMInitializeMSP430AsmParser() void;
|
|
pub extern fn LLVMInitializePowerPCAsmParser() void;
|
|
pub extern fn LLVMInitializeRISCVAsmParser() void;
|
|
pub extern fn LLVMInitializeSparcAsmParser() void;
|
|
pub extern fn LLVMInitializeSystemZAsmParser() void;
|
|
pub extern fn LLVMInitializeWebAssemblyAsmParser() void;
|
|
pub extern fn LLVMInitializeX86AsmParser() void;
|
|
pub extern fn LLVMInitializeXtensaAsmParser() void;
|
|
pub extern fn LLVMInitializeM68kAsmParser() void;
|
|
pub extern fn LLVMInitializeCSKYAsmParser() void;
|
|
pub extern fn LLVMInitializeVEAsmParser() void;
|
|
pub extern fn LLVMInitializeLoongArchAsmParser() void;
|
|
|
|
extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
|
|
extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
|
|
extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
|
|
|
|
pub const LinkCOFF = ZigLLDLinkCOFF;
|
|
pub const LinkELF = ZigLLDLinkELF;
|
|
pub const LinkWasm = ZigLLDLinkWasm;
|
|
|
|
pub const ArchiveKind = enum(c_int) {
|
|
GNU,
|
|
GNU64,
|
|
BSD,
|
|
DARWIN,
|
|
DARWIN64,
|
|
COFF,
|
|
AIXBIG,
|
|
};
|
|
|
|
pub const WriteArchive = ZigLLVMWriteArchive;
|
|
extern fn ZigLLVMWriteArchive(
|
|
archive_name: [*:0]const u8,
|
|
file_names_ptr: [*]const [*:0]const u8,
|
|
file_names_len: usize,
|
|
archive_kind: ArchiveKind,
|
|
) bool;
|
|
|
|
pub const ParseCommandLineOptions = ZigLLVMParseCommandLineOptions;
|
|
extern fn ZigLLVMParseCommandLineOptions(argc: usize, argv: [*]const [*:0]const u8) void;
|
|
|
|
pub const WriteImportLibrary = ZigLLVMWriteImportLibrary;
|
|
extern fn ZigLLVMWriteImportLibrary(
|
|
def_path: [*:0]const u8,
|
|
coff_machine: c_uint,
|
|
output_lib_path: [*:0]const u8,
|
|
kill_at: bool,
|
|
) bool;
|
|
|
|
pub const GetHostCPUName = LLVMGetHostCPUName;
|
|
extern fn LLVMGetHostCPUName() ?[*:0]u8;
|
|
|
|
pub const GetHostCPUFeatures = LLVMGetHostCPUFeatures;
|
|
extern fn LLVMGetHostCPUFeatures() ?[*:0]u8;
|