exported main must be pub

master
Vexu 2019-12-01 11:31:18 +02:00 committed by Andrew Kelley
parent 20bcdab462
commit 621c08e692
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 8 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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