Merge pull request #5003 from emekoi/fix-mingw

fix compilation under mingw
This commit is contained in:
Andrew Kelley
2020-04-11 16:43:38 -04:00
committed by GitHub
3 changed files with 24 additions and 5 deletions

View File

@@ -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}

View File

@@ -8167,7 +8167,7 @@ test "vector @splat" {
{#header_open|@tagName#}
<pre>{#syntax#}@tagName(value: var) []const u8{#endsyntax#}</pre>
<p>
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.</p><p>If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked {#link|Undefined Behavior#}.
</p>
{#header_close#}

View File

@@ -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");