Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Struct

Options

Public Struct
std.Options
pub const Options = struct

Fields

enable_segfault_handler: bool = debug.default_enable_segfault_handler
signal_stack_size: ?u64 = 1 << 18

If set, std.start and std.Thread will configure an per-thread alternative signal stack of this size. Importantly, if enable_segfault_handler is set, the segfault handler will use this alternative stack, meaning it can still print stack traces even if a segmentation fault is caused by a stack overflow.

On POSIX targets, the signal stack is configured using 'sigaltstack(2)'.

On Windows, this value is currently ignored.

log_level: log.Level = log.default_level

The current log level.

log_scope_levels: []const log.ScopeLevel = &.{}
logFn: fn ( comptime message_level: log.Level, comptime scope: @EnumLiteral(), comptime format: []const u8, args: anytype, ) void = log.defaultLog
page_size_min: ?usize = null

Overrides std.heap.page_size_min.

page_size_max: ?usize = null

Overrides std.heap.page_size_max.

queryPageSize: fn () usize = heap.defaultQueryPageSize

Overrides default implementation for determining OS page size at runtime.

fmt_max_depth: usize = fmt.default_max_depth
http_disable_tls: bool = false

By default, std.http.Client will support HTTPS connections. Set this option to true to disable TLS support.

This will likely reduce the size of the binary, but it will also make it impossible to make a HTTPS connection.

http_enable_ssl_key_log_file: bool = @import("builtin").mode == .debug

This enables std.http.Client to log ssl secrets to the file specified by the SSLKEYLOGFILE env var. Creating such a log file allows other programs with access to that file to decrypt all std.http.Client traffic made by this program.

side_channels_mitigations: crypto.SideChannelsMitigations = crypto.default_side_channels_mitigations
allow_stack_tracing: bool = !@import("builtin").strip_debug_info

Whether to allow capturing and writing stack traces. This affects the following functions:

  • debug.captureCurrentStackTrace
  • debug.writeCurrentStackTrace
  • debug.dumpCurrentStackTrace
  • debug.writeStackTrace
  • debug.dumpStackTrace
  • debug.writeErrorReturnTrace
  • debug.dumpErrorReturnTrace

Stack traces can generally be collected and printed when debug info is stripped, but are often less useful since they usually cannot be mapped to source locations and/or have bad source locations. The stack tracing logic can also be quite large, which may be undesirable, particularly in ReleaseSmall.

If this is false, then captured stack traces will always be empty, and attempts to write stack traces will just print an error to the relevant Io.Writer and return.

networking: bool = true

Allows disabling networking in std.Io implementations.

unexpected_error_tracing: bool = @import("builtin").mode == .debug and switch (@import("builtin").zig_backend) { .stage2_llvm, .stage2_x86_64 => true, else => false, }

Whether or not error.Unexpected will print its value and a stack trace.

If this happens the fix is to add the error code to the corresponding switch expression, possibly introduce a new error in the error set, and send a patch to Zig.

Values

  • pub const elf_debug_info_search_paths

    TODO This is a separate decl instead of a field as a workaround around compilation errors due to zig not being lazy enough.

  • pub const debug_threaded_io
  • pub const debug_io

    The Io instance that std.debug uses for std.debug.print, capturing stack traces, loading debug info, finding the executable's own path, and environment variables that affect terminal mode detection. The default is to use statically initialized singleton that is independent from the application's Io instance in order to make debugging more straightforward. For example, while debugging an Io implementation based on coroutines, one likely wants std.debug.print to directly write to stderr without trying to interact with the code being debugged.

  • pub const FilePermissions

    Overrides std.Io.File.Permissions.

  • pub const cwd

    Overrides std.Io.Dir.cwd.

Functions

File

std.zig:121
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
pub const Options = struct {
    enable_segfault_handler: bool = debug.default_enable_segfault_handler,

    /// If set, `std.start` and `std.Thread` will configure an per-thread alternative signal stack
    /// of this size. Importantly, if `enable_segfault_handler` is set, the segfault handler will
    /// use this alternative stack, meaning it can still print stack traces even if a segmentation
    /// fault is caused by a stack overflow.
    ///
    /// On POSIX targets, the signal stack is configured using 'sigaltstack(2)'.
    ///
    /// On Windows, this value is currently ignored.
    signal_stack_size: ?u64 = 1 << 18, // 1<<17 observed to be sufficient for stack tracing with self-hosted x86_64 backend

    /// The current log level.
    log_level: log.Level = log.default_level,

    log_scope_levels: []const log.ScopeLevel = &.{},

    logFn: fn (
        comptime message_level: log.Level,
        comptime scope: @EnumLiteral(),
        comptime format: []const u8,
        args: anytype,
    ) void = log.defaultLog,

    /// Overrides `std.heap.page_size_min`.
    page_size_min: ?usize = null,
    /// Overrides `std.heap.page_size_max`.
    page_size_max: ?usize = null,
    /// Overrides default implementation for determining OS page size at runtime.
    queryPageSize: fn () usize = heap.defaultQueryPageSize,

    fmt_max_depth: usize = fmt.default_max_depth,

    /// By default, std.http.Client will support HTTPS connections.  Set this option to `true` to
    /// disable TLS support.
    ///
    /// This will likely reduce the size of the binary, but it will also make it impossible to
    /// make a HTTPS connection.
    http_disable_tls: bool = false,

    /// This enables `std.http.Client` to log ssl secrets to the file specified by the SSLKEYLOGFILE
    /// env var.  Creating such a log file allows other programs with access to that file to decrypt
    /// all `std.http.Client` traffic made by this program.
    http_enable_ssl_key_log_file: bool = @import("builtin").mode == .debug,

    side_channels_mitigations: crypto.SideChannelsMitigations = crypto.default_side_channels_mitigations,

    /// Whether to allow capturing and writing stack traces. This affects the following functions:
    /// * `debug.captureCurrentStackTrace`
    /// * `debug.writeCurrentStackTrace`
    /// * `debug.dumpCurrentStackTrace`
    /// * `debug.writeStackTrace`
    /// * `debug.dumpStackTrace`
    /// * `debug.writeErrorReturnTrace`
    /// * `debug.dumpErrorReturnTrace`
    ///
    /// Stack traces can generally be collected and printed when debug info is stripped, but are
    /// often less useful since they usually cannot be mapped to source locations and/or have bad
    /// source locations. The stack tracing logic can also be quite large, which may be undesirable,
    /// particularly in ReleaseSmall.
    ///
    /// If this is `false`, then captured stack traces will always be empty, and attempts to write
    /// stack traces will just print an error to the relevant `Io.Writer` and return.
    allow_stack_tracing: bool = !@import("builtin").strip_debug_info,

    /// Allows disabling networking in std.Io implementations.
    networking: bool = true,

    /// Whether or not `error.Unexpected` will print its value and a stack trace.
    ///
    /// If this happens the fix is to add the error code to the corresponding
    /// switch expression, possibly introduce a new error in the error set, and
    /// send a patch to Zig.
    unexpected_error_tracing: bool = @import("builtin").mode == .debug and switch (@import("builtin").zig_backend) {
        .stage2_llvm, .stage2_x86_64 => true,
        else => false,
    },

    /// TODO This is a separate decl instead of a field as a workaround around
    /// compilation errors due to zig not being lazy enough.
    pub const logTerminalMode: fn () Io.Terminal.Mode = log.defaultTerminalMode;

    /// TODO This is a separate decl instead of a field as a workaround around
    /// compilation errors due to zig not being lazy enough.
    pub const elf_debug_info_search_paths: ?fn (exe_path: []const u8) switch (@import("builtin").object_format) {
        .elf => debug.ElfFile.DebugInfoSearchPaths,
        else => void,
    } = if (@hasDecl(root, "std_options_elf_debug_info_search_paths"))
        root.std_options_elf_debug_info_search_paths
    else
        null;

    pub const debug_threaded_io: ?*Io.Threaded = if (@hasDecl(root, "std_options_debug_threaded_io"))
        root.std_options_debug_threaded_io
    else
        Io.Threaded.global_single_threaded;

    /// The `Io` instance that `std.debug` uses for `std.debug.print`,
    /// capturing stack traces, loading debug info, finding the executable's
    /// own path, and environment variables that affect terminal mode
    /// detection. The default is to use statically initialized singleton that
    /// is independent from the application's `Io` instance in order to make
    /// debugging more straightforward. For example, while debugging an `Io`
    /// implementation based on coroutines, one likely wants `std.debug.print`
    /// to directly write to stderr without trying to interact with the code
    /// being debugged.
    pub const debug_io: Io = if (@hasDecl(root, "std_options_debug_io")) root.std_options_debug_io else debug_threaded_io.?.io();

    /// Overrides `std.Io.File.Permissions`.
    pub const FilePermissions: ?type = if (@hasDecl(root, "std_options_FilePermissions")) root.std_options_FilePermissions else null;

    /// Overrides `std.Io.Dir.cwd`.
    pub const cwd: ?fn () Io.Dir = if (@hasDecl(root, "std_options_cwd")) root.std_options_cwd else null;
}