mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Merge branch 'master' into refs_fix
This commit is contained in:
commit
d0cc496c02
7 changed files with 101 additions and 8 deletions
|
|
@ -61,6 +61,10 @@ comptime {
|
|||
} else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
|
||||
@export(&main, .{ .name = "main" });
|
||||
}
|
||||
} else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "wWinMain")) {
|
||||
if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".calling_convention.eql(.c)) {
|
||||
@export(&wWinMain, .{ .name = "wWinMain" });
|
||||
}
|
||||
} else if (native_os == .windows) {
|
||||
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
|
||||
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
|
||||
|
|
@ -527,6 +531,10 @@ fn wWinMainCRTStartup() callconv(.withStackAlign(.c, 1)) noreturn {
|
|||
std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result)));
|
||||
}
|
||||
|
||||
fn wWinMain(hInstance: *anyopaque, hPrevInstance: ?*anyopaque, pCmdLine: [*:0]u16, nCmdShow: c_int) callconv(.c) c_int {
|
||||
return root.wWinMain(@ptrCast(hInstance), @ptrCast(hPrevInstance), pCmdLine, @intCast(nCmdShow));
|
||||
}
|
||||
|
||||
fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
|
||||
// We're not ready to panic until thread local storage is initialized.
|
||||
@setRuntimeSafety(false);
|
||||
|
|
|
|||
|
|
@ -2142,13 +2142,10 @@ pub const Inst = struct {
|
|||
/// ZIR is structured so that the outermost "main" struct of any file
|
||||
/// is always at index 0.
|
||||
main_struct_inst = 0,
|
||||
ref_start_index = static_len,
|
||||
_,
|
||||
|
||||
pub const static_len = 124;
|
||||
|
||||
pub fn toRef(i: Index) Inst.Ref {
|
||||
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
|
||||
return @enumFromInt(Ref.static_len + @intFromEnum(i));
|
||||
}
|
||||
|
||||
pub fn toOptional(i: Index) OptionalIndex {
|
||||
|
|
@ -2160,7 +2157,6 @@ pub const Inst = struct {
|
|||
/// ZIR is structured so that the outermost "main" struct of any file
|
||||
/// is always at index 0.
|
||||
main_struct_inst = 0,
|
||||
ref_start_index = Index.static_len,
|
||||
none = std.math.maxInt(u32),
|
||||
_,
|
||||
|
||||
|
|
@ -2309,11 +2305,13 @@ pub const Inst = struct {
|
|||
|
||||
_,
|
||||
|
||||
pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1;
|
||||
|
||||
pub fn toIndex(inst: Ref) ?Index {
|
||||
assert(inst != .none);
|
||||
const ref_int = @intFromEnum(inst);
|
||||
if (ref_int >= @intFromEnum(Index.ref_start_index)) {
|
||||
return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));
|
||||
if (ref_int >= static_len) {
|
||||
return @enumFromInt(ref_int - static_len);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5386,7 +5386,7 @@ pub const static_keys: [static_len]Key = .{
|
|||
/// This is specified with an integer literal and a corresponding comptime
|
||||
/// assert below to break an unfortunate and arguably incorrect dependency loop
|
||||
/// when compiling.
|
||||
pub const static_len = Zir.Inst.Index.static_len;
|
||||
pub const static_len = Zir.Inst.Ref.static_len;
|
||||
|
||||
pub const Tag = enum(u8) {
|
||||
/// This special tag represents a value which was removed from this pool via
|
||||
|
|
|
|||
|
|
@ -77,4 +77,66 @@ pub fn build(b: *std.Build) void {
|
|||
_ = exe.getEmittedBin();
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig_main",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("main.zig"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
}),
|
||||
});
|
||||
|
||||
_ = exe.getEmittedBin();
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig_main_link_libc",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("main.zig"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
|
||||
_ = exe.getEmittedBin();
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig_wwinmain",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("wwinmain.zig"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
}),
|
||||
});
|
||||
exe.mingw_unicode_entry_point = true;
|
||||
// Note: `exe.subsystem = .windows;` is not necessary
|
||||
|
||||
_ = exe.getEmittedBin();
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig_wwinmain_link_libc",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("wwinmain.zig"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
exe.mingw_unicode_entry_point = true;
|
||||
// Note: `exe.subsystem = .windows;` is not necessary
|
||||
|
||||
_ = exe.getEmittedBin();
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
test/standalone/windows_entry_points/main.zig
Normal file
5
test/standalone/windows_entry_points/main.zig
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
std.debug.print("hello from Zig main\n", .{});
|
||||
}
|
||||
15
test/standalone/windows_entry_points/wwinmain.zig
Normal file
15
test/standalone/windows_entry_points/wwinmain.zig
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn wWinMain(
|
||||
inst: std.os.windows.HINSTANCE,
|
||||
prev: ?std.os.windows.HINSTANCE,
|
||||
cmd_line: std.os.windows.LPWSTR,
|
||||
cmd_show: c_int,
|
||||
) std.os.windows.INT {
|
||||
_ = inst;
|
||||
_ = prev;
|
||||
_ = cmd_line;
|
||||
_ = cmd_show;
|
||||
std.debug.print("hello from Zig wWinMain\n", .{});
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -197,6 +197,9 @@ pub fn main() !void {
|
|||
};
|
||||
|
||||
try child.spawn();
|
||||
errdefer {
|
||||
_ = child.kill() catch {};
|
||||
}
|
||||
|
||||
var poller = Io.poll(arena, Eval.StreamEnum, .{
|
||||
.stdout = child.stdout.?,
|
||||
|
|
@ -585,6 +588,8 @@ const Eval = struct {
|
|||
fn fatal(eval: *Eval, comptime fmt: []const u8, args: anytype) noreturn {
|
||||
eval.tmp_dir.close();
|
||||
if (!eval.preserve_tmp_on_fatal) {
|
||||
// Kill the child since it holds an open handle to its CWD which is the tmp dir path
|
||||
_ = eval.child.kill() catch {};
|
||||
std.fs.cwd().deleteTree(eval.tmp_dir_path) catch |err| {
|
||||
std.log.warn("failed to delete tree '{s}': {s}", .{ eval.tmp_dir_path, @errorName(err) });
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue