From a7221ef4e902e63e72524559a067afcf6c1dfd17 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 6 May 2021 22:30:44 -0700 Subject: Sema: implement `@typeInfo` for functions The goal is to get start code to be able to inspect the calling convention of `main` in order to determine whether to export a main for libc to call, or to allow the root source file to do it. --- lib/std/start.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/std') diff --git a/lib/std/start.zig b/lib/std/start.zig index d34c7365a9..d9ec173bbc 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -28,8 +28,10 @@ comptime { // self-hosted is capable enough to handle all of the real start.zig logic. if (builtin.zig_is_stage2) { if (builtin.output_mode == .Exe) { - if (builtin.link_libc or builtin.object_format == .c) { - @export(main2, .{ .name = "main" }); + if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) { + if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) { + @export(main2, .{ .name = "main" }); + } } else { if (!@hasDecl(root, "_start")) { @export(_start2, .{ .name = "_start" }); -- cgit v1.2.3