diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index 478876c689..33ecc6f1f0 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -23,7 +23,7 @@ comptime { .Unknown => unreachable, .Exe => { if (builtin.link_libc) { - if (!@hasDecl(root, "main") or + if (@hasDecl(root, "main") and @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) { @export("main", main, .Weak); diff --git a/test/compare_output.zig b/test/compare_output.zig index 03f71d380e..35687b6a6c 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -6,7 +6,7 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompareOutputContext) void { cases.addC("hello world with libc", \\const c = @cImport(@cInclude("stdio.h")); - \\export fn main(argc: c_int, argv: [*][*]u8) c_int { + \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { \\ _ = c.puts("Hello, world!"); \\ return 0; \\} @@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ @cInclude("stdio.h"); \\}); \\ - \\export fn main(argc: c_int, argv: [*][*]u8) c_int { + \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { \\ if (is_windows) { \\ // we want actual \n, not \r\n \\ _ = c._setmode(1, c._O_BINARY); @@ -286,7 +286,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ } \\} \\ - \\export fn main() c_int { + \\pub export fn main() c_int { \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; \\ \\ c.qsort(@ptrCast(?*c_void, array[0..].ptr), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); @@ -314,7 +314,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ @cInclude("stdio.h"); \\}); \\ - \\export fn main(argc: c_int, argv: [*][*]u8) c_int { + \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { \\ if (is_windows) { \\ // we want actual \n, not \r\n \\ _ = c._setmode(1, c._O_BINARY); diff --git a/test/stage2/compare_output.zig b/test/stage2/compare_output.zig index a86811b27b..443ed7a0ee 100644 --- a/test/stage2/compare_output.zig +++ b/test/stage2/compare_output.zig @@ -5,7 +5,7 @@ pub fn addCases(ctx: *TestContext) !void { // hello world try ctx.testCompareOutputLibC( \\extern fn puts([*]const u8) void; - \\export fn main() c_int { + \\pub export fn main() c_int { \\ puts("Hello, world!"); \\ return 0; \\} @@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void { // function calling another function try ctx.testCompareOutputLibC( \\extern fn puts(s: [*]const u8) void; - \\export fn main() c_int { + \\pub export fn main() c_int { \\ return foo("OK"); \\} \\fn foo(s: [*]const u8) c_int { diff --git a/test/standalone/hello_world/hello_libc.zig b/test/standalone/hello_world/hello_libc.zig index c6f290f70e..5c0a233f1c 100644 --- a/test/standalone/hello_world/hello_libc.zig +++ b/test/standalone/hello_world/hello_libc.zig @@ -7,7 +7,7 @@ const c = @cImport({ const msg = "Hello, world!\n"; -export fn main(argc: c_int, argv: **u8) c_int { +pub export fn main(argc: c_int, argv: **u8) c_int { if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; return 0; }