aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-09-24 03:54:59 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-09-24 03:55:45 -0400
commitba41be67f02158df964543d21b30c83f1b17550d (patch)
tree79532b92c9309e669fc7c96420e1efe9b7dd1f44 /src
parent41b588547cd49673ff632ed0fc3210c76ff48b42 (diff)
downloadzig-ba41be67f02158df964543d21b30c83f1b17550d.tar.gz
zig-ba41be67f02158df964543d21b30c83f1b17550d.zip
windows gui hello world
Diffstat (limited to 'src')
-rw-r--r--src/all_types.hpp1
-rw-r--r--src/analyze.cpp6
-rw-r--r--src/codegen.cpp2
-rw-r--r--src/link.cpp45
4 files changed, 31 insertions, 23 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index bf315cd610..d40df52df4 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1451,6 +1451,7 @@ struct CodeGen {
bool want_h_file;
bool have_pub_main;
bool have_c_main;
+ bool have_winmain;
bool have_pub_panic;
Buf *libc_lib_dir;
Buf *libc_static_lib_dir;
diff --git a/src/analyze.cpp b/src/analyze.cpp
index b20b7b3bd7..fbe96fb91f 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3200,6 +3200,12 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
g->have_c_main = true;
g->windows_subsystem_windows = false;
g->windows_subsystem_console = true;
+ } else if (proto_node->data.fn_proto.visib_mod == VisibModExport && buf_eql_str(proto_name, "WinMain") &&
+ g->zig_target.os == ZigLLVM_Win32)
+ {
+ g->have_winmain = true;
+ g->windows_subsystem_windows = true;
+ g->windows_subsystem_console = false;
}
}
diff --git a/src/codegen.cpp b/src/codegen.cpp
index ab4bf4ebf4..842b0205eb 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5157,7 +5157,7 @@ static void gen_root_source(CodeGen *g) {
assert(g->root_out_name);
assert(g->out_type != OutTypeUnknown);
- if (!g->is_test_build && g->zig_target.os != ZigLLVM_UnknownOS && !g->have_c_main &&
+ if (!g->is_test_build && g->zig_target.os != ZigLLVM_UnknownOS && !g->have_c_main && !g->have_winmain &&
((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
{
g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");
diff --git a/src/link.cpp b/src/link.cpp
index 39cadaea0f..ecf980ab4a 100644
--- a/src/link.cpp
+++ b/src/link.cpp
@@ -398,7 +398,11 @@ static void construct_linker_job_coff(LinkJob *lj) {
//lj->args.append(get_libc_static_file(g, "crtbegin.o"));
} else {
lj->args.append("-NODEFAULTLIB");
- lj->args.append("-ENTRY:_start");
+ if (g->have_winmain) {
+ lj->args.append("-ENTRY:WinMain");
+ } else {
+ lj->args.append("-ENTRY:_start");
+ }
}
for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
@@ -424,6 +428,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
}
Buf *def_contents = buf_alloc();
+ ZigList<const char *> gen_lib_args = {0};
for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) {
LinkLib *link_lib = g->link_libs_list.at(lib_i);
if (buf_eql_str(link_lib->name, "c")) {
@@ -433,38 +438,34 @@ static void construct_linker_job_coff(LinkJob *lj) {
Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name));
lj->args.append(buf_ptr(arg));
} else {
+ buf_resize(def_contents, 0);
buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name));
for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) {
Buf *symbol_name = link_lib->symbols.at(exp_i);
buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name));
}
buf_appendf(def_contents, "\n");
- }
- }
- if (buf_len(def_contents) != 0) {
- Buf *def_path = buf_alloc();
- os_path_join(g->cache_dir, buf_create_from_str("all.def"), def_path);
- os_write_file(def_path, def_contents);
- Buf *all_lib_path = buf_alloc();
- os_path_join(g->cache_dir, buf_create_from_str("all.lib"), all_lib_path);
+ Buf *def_path = buf_alloc();
+ os_path_join(g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
+ os_write_file(def_path, def_contents);
- //Buf *dll_path = buf_alloc();
- //os_path_join(g->cache_dir, buf_create_from_str("all.dll"), dll_path);
+ Buf *generated_lib_path = buf_alloc();
+ os_path_join(g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
- ZigList<const char *> args = {0};
- args.append("link");
+ gen_lib_args.resize(0);
+ gen_lib_args.append("link");
- coff_append_machine_arg(g, &args);
- args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path))));
- args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(all_lib_path))));
- Buf diag = BUF_INIT;
- if (!ZigLLDLink(g->zig_target.oformat, args.items, args.length, &diag)) {
- fprintf(stderr, "%s\n", buf_ptr(&diag));
- exit(1);
+ coff_append_machine_arg(g, &gen_lib_args);
+ gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path))));
+ gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path))));
+ Buf diag = BUF_INIT;
+ if (!ZigLLDLink(g->zig_target.oformat, gen_lib_args.items, gen_lib_args.length, &diag)) {
+ fprintf(stderr, "%s\n", buf_ptr(&diag));
+ exit(1);
+ }
+ lj->args.append(buf_ptr(generated_lib_path));
}
-
- lj->args.append(buf_ptr(all_lib_path));
}
if (g->libc_link_lib != nullptr) {