diff --git a/CMakeLists.txt b/CMakeLists.txt index 279156c93c..092cdb7a70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,6 +454,9 @@ if("${ZIG_TARGET_TRIPLE}" STREQUAL "native") WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig") + if (WIN32) + set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe") + endif() else() add_custom_target(zig_build_libstage2 ALL COMMAND "${ZIG_EXECUTABLE}" ${BUILD_LIBSTAGE2_ARGS} diff --git a/doc/langref.html.in b/doc/langref.html.in index cd1905ebfb..bb824076d6 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -8167,7 +8167,7 @@ test "vector @splat" { {#header_open|@tagName#}
{#syntax#}@tagName(value: var) []const u8{#endsyntax#}

- Converts an enum value or union value to a slice of bytes representing the name. + Converts an enum value or union value to a slice of bytes representing the name.

If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked {#link|Undefined Behavior#}.

{#header_close#} diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index 9d8c8446d5..aba4706f09 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -897,6 +897,22 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file: return .None; } +fn enumToString(value: var, type_name: []const u8) ![]const u8 { + switch (@typeInfo(@TypeOf(value))) { + .Enum => |e| { + if (e.is_exhaustive) { + return std.fmt.allocPrint(std.heap.c_allocator, ".{}", .{@tagName(value)}); + } else { + return std.fmt.allocPrint(std.heap.c_allocator, + "@intToEnum({}, {})", + .{type_name, @enumToInt(value)} + ); + } + }, + else => unreachable + } +} + // ABI warning const Stage2Target = extern struct { arch: c_int, @@ -1114,13 +1130,13 @@ const Stage2Target = extern struct { .windows => try os_builtin_str_buffer.outStream().print( \\ .windows = .{{ - \\ .min = .{}, - \\ .max = .{}, + \\ .min = {}, + \\ .max = {}, \\ }}}}, \\ , .{ - @tagName(target.os.version_range.windows.min), - @tagName(target.os.version_range.windows.max), + try enumToString(target.os.version_range.windows.min, "Target.Os.WindowsVersion"), + try enumToString(target.os.version_range.windows.max, "Target.Os.WindowsVersion") }), } try os_builtin_str_buffer.appendSlice("};\n");