From 4c0259b107236b39f7b1e8f423d2bf9f48e89b54 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 18 Sep 2016 21:28:06 -0400 Subject: [PATCH] ability to specify -framework linker args for MacOS --- src/all_types.hpp | 2 ++ src/codegen.cpp | 4 ++++ src/codegen.hpp | 1 + src/link.cpp | 5 +++++ src/main.cpp | 7 +++++++ 5 files changed, 19 insertions(+) diff --git a/src/all_types.hpp b/src/all_types.hpp index 71bc596f81..27c519a1b1 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1195,6 +1195,8 @@ struct CodeGen { ZigLLVMDICompileUnit *compile_unit; ZigList link_libs; // non-libc link libs + // add -framework [name] args to linker + ZigList darwin_frameworks; // reminder: hash tables must be initialized before use HashMap import_table; diff --git a/src/codegen.cpp b/src/codegen.cpp index 827836925c..39a3d498fe 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -193,6 +193,10 @@ void codegen_add_link_lib(CodeGen *g, const char *lib) { } } +void codegen_add_framework(CodeGen *g, const char *framework) { + g->darwin_frameworks.append(buf_create_from_str(framework)); +} + void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole) { g->windows_subsystem_windows = mwindows; g->windows_subsystem_console = mconsole; diff --git a/src/codegen.hpp b/src/codegen.hpp index dbb7564117..17fd7ed73e 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -38,6 +38,7 @@ void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); void codegen_set_windows_unicode(CodeGen *g, bool municode); void codegen_add_lib_dir(CodeGen *codegen, const char *dir); void codegen_add_link_lib(CodeGen *codegen, const char *lib); +void codegen_add_framework(CodeGen *codegen, const char *name); void codegen_set_mlinker_version(CodeGen *g, Buf *darwin_linker_version); void codegen_set_rdynamic(CodeGen *g, bool rdynamic); void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min); diff --git a/src/link.cpp b/src/link.cpp index 56a44c4612..caec1176be 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -671,6 +671,11 @@ static void construct_linker_job_darwin(LinkJob *lj) { zig_panic("TODO"); } + for (int i = 0; i < g->darwin_frameworks.length; i += 1) { + lj->args.append("-framework"); + lj->args.append(buf_ptr(g->darwin_frameworks.at(i))); + } + } static void construct_linker_job(LinkJob *lj) { diff --git a/src/main.cpp b/src/main.cpp index e55350a274..6b97056e88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,7 @@ static int usage(const char *arg0) { " -rdynamic add all symbols to the dynamic symbol table\n" " -mmacosx-version-min [ver] (darwin only) set Mac OS X deployment target\n" " -mios-version-min [ver] (darwin only) set iOS deployment target\n" + " -framework [name] (darwin only) link against framework\n" " --check-unused perform semantic analysis on unused declarations\n" , arg0); return EXIT_FAILURE; @@ -125,6 +126,7 @@ int main(int argc, char **argv) { ZigList clang_argv = {0}; ZigList lib_dirs = {0}; ZigList link_libs = {0}; + ZigList frameworks = {0}; int err; const char *target_arch = nullptr; const char *target_os = nullptr; @@ -226,6 +228,8 @@ int main(int argc, char **argv) { mmacosx_version_min = argv[i]; } else if (strcmp(arg, "-mios-version-min") == 0) { mios_version_min = argv[i]; + } else if (strcmp(arg, "-framework") == 0) { + frameworks.append(argv[i]); } else { fprintf(stderr, "Invalid argument: %s\n", arg); return usage(arg0); @@ -377,6 +381,9 @@ int main(int argc, char **argv) { for (int i = 0; i < link_libs.length; i += 1) { codegen_add_link_lib(g, link_libs.at(i)); } + for (int i = 0; i < frameworks.length; i += 1) { + codegen_add_framework(g, frameworks.at(i)); + } codegen_set_windows_subsystem(g, mwindows, mconsole); codegen_set_windows_unicode(g, municode);