Skip to content
Permalink
Browse files

look for another libc libpath at runtime on windows

See #539
  • Loading branch information...
andrewrk committed Oct 16, 2017
1 parent 8047c4a commit fec4d754ab1dc597df4f029d9e7feded3a8732d7
Showing with 55 additions and 10 deletions.
  1. +1 −0 src/all_types.hpp
  2. +33 −3 src/analyze.cpp
  3. +6 −0 src/codegen.cpp
  4. +1 −0 src/codegen.hpp
  5. +8 −7 src/link.cpp
  6. +6 −0 src/main.cpp
@@ -1462,6 +1462,7 @@ struct CodeGen {
Buf *libc_static_lib_dir;
Buf *libc_include_dir;
Buf *msvc_lib_dir;
Buf *kernel32_lib_dir;
Buf *zig_lib_dir;
Buf *zig_std_dir;
Buf *zig_c_headers_dir;
@@ -3362,12 +3362,14 @@ void find_libc_lib_path(CodeGen *g) {
#ifdef ZIG_OS_WINDOWS
if (!g->msvc_lib_dir && g->zig_target.os == ZigLLVM_Win32) {
Buf *msvc_lib_dir;
if (g->zig_target.os == ZigLLVM_arm) {
if (g->zig_target.arch.arch == ZigLLVM_arm) {
msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\arm");
} else if (g->zig_target.os == ZigLLVM_x86_64) {
} else if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\amd64");
} else if (g->zig_target.os == ZigLLVM_x86) {
} else if (g->zig_target.arch.arch == ZigLLVM_x86) {
msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib");
} else {
zig_panic("unable to determine msvc lib path");
}
Buf *test_path = buf_alloc();
os_path_join(msvc_lib_dir, buf_create_from_str("vcruntime.lib"), test_path);
@@ -3382,6 +3384,34 @@ void find_libc_lib_path(CodeGen *g) {
zig_panic("Unable to determine msvc lib path.");
}
}

if (!g->kernel32_lib_dir && g->zig_target.os == ZigLLVM_Win32) {
Buf *kernel32_lib_dir;
if (g->zig_target.arch.arch == ZigLLVM_arm) {
kernel32_lib_dir = buf_create_from_str(
"C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\arm");
} else if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
kernel32_lib_dir = buf_create_from_str(
"C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x64");
} else if (g->zig_target.arch.arch == ZigLLVM_x86) {
kernel32_lib_dir = buf_create_from_str(
"C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x86");
} else {
zig_panic("unable to determine kernel32 lib path");
}
Buf *test_path = buf_alloc();
os_path_join(kernel32_lib_dir, buf_create_from_str("kernel32.lib"), test_path);
bool result;
int err;
if ((err = os_file_exists(test_path, &result))) {
result = false;
}
if (result) {
g->kernel32_lib_dir = kernel32_lib_dir;
} else {
zig_panic("Unable to determine kernel32 lib path.");
}
}
#endif

// later we can handle this better by reporting an error via the normal mechanism
@@ -118,6 +118,7 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
g->libc_static_lib_dir = buf_create_from_str("");
g->libc_include_dir = buf_create_from_str("");
g->msvc_lib_dir = nullptr;
g->kernel32_lib_dir = nullptr;
g->each_lib_rpath = false;
} else {
// native compilation, we can rely on the configuration stuff
@@ -129,6 +130,7 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
g->libc_static_lib_dir = buf_create_from_str(ZIG_LIBC_STATIC_LIB_DIR);
g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR);
g->msvc_lib_dir = nullptr; // find it at runtime
g->kernel32_lib_dir = nullptr; // find it at runtime
#ifdef ZIG_EACH_LIB_RPATH
g->each_lib_rpath = true;
#endif
@@ -234,6 +236,10 @@ void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir) {
g->msvc_lib_dir = msvc_lib_dir;
}

void codegen_set_kernel32_lib_dir(CodeGen *g, Buf *kernel32_lib_dir) {
g->kernel32_lib_dir = kernel32_lib_dir;
}

void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) {
g->dynamic_linker = dynamic_linker;
}
@@ -32,6 +32,7 @@ void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir);
void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir);
void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);
void codegen_set_msvc_lib_dir(CodeGen *codegen, Buf *msvc_lib_dir);
void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir);
void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker);
void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole);
void codegen_set_windows_unicode(CodeGen *g, bool municode);
@@ -397,6 +397,14 @@ static void construct_linker_job_coff(LinkJob *lj) {

lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&lj->out_file))));

if (g->libc_link_lib != nullptr) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir))));
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir))));

lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir))));
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir))));
}

if (lj->link_in_crt) {
const char *lib_str = g->is_static ? "lib" : "";
const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : "";
@@ -441,13 +449,6 @@ static void construct_linker_job_coff(LinkJob *lj) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", lib_dir)));
}

if (g->libc_link_lib != nullptr) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir))));

lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir))));
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir))));
}

for (size_t i = 0; i < g->link_objects.length; i += 1) {
lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
}
@@ -60,6 +60,7 @@ static int usage(const char *arg0) {
" --libc-lib-dir [path] directory where libc crt1.o resides\n"
" --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n"
" --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n"
" --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n"
" --library [lib] link against lib\n"
" --library-path [dir] add a directory to the library search path\n"
" --linker-script [path] use a custom linker script\n"
@@ -281,6 +282,7 @@ int main(int argc, char **argv) {
const char *libc_static_lib_dir = nullptr;
const char *libc_include_dir = nullptr;
const char *msvc_lib_dir = nullptr;
const char *kernel32_lib_dir = nullptr;
const char *zig_install_prefix = nullptr;
const char *dynamic_linker = nullptr;
ZigList<const char *> clang_argv = {0};
@@ -522,6 +524,8 @@ int main(int argc, char **argv) {
libc_include_dir = argv[i];
} else if (strcmp(arg, "--msvc-lib-dir") == 0) {
msvc_lib_dir = argv[i];
} else if (strcmp(arg, "--kernel32-lib-dir") == 0) {
kernel32_lib_dir = argv[i];
} else if (strcmp(arg, "--zig-install-prefix") == 0) {
zig_install_prefix = argv[i];
} else if (strcmp(arg, "--dynamic-linker") == 0) {
@@ -734,6 +738,8 @@ int main(int argc, char **argv) {
codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir));
if (msvc_lib_dir)
codegen_set_msvc_lib_dir(g, buf_create_from_str(msvc_lib_dir));
if (kernel32_lib_dir)
codegen_set_kernel32_lib_dir(g, buf_create_from_str(kernel32_lib_dir));
if (dynamic_linker)
codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker));
codegen_set_verbose(g, verbose);

0 comments on commit fec4d75

Please sign in to comment.
You can’t perform that action at this time.