From c281533638dd08bb84f4f538fd8c5ae85791d034 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 27 Jan 2016 19:22:58 -0700 Subject: [PATCH] build command supports -isystem argument --- src/all_types.hpp | 3 +++ src/analyze.cpp | 4 +++- src/codegen.cpp | 5 +++++ src/codegen.hpp | 1 + src/main.cpp | 17 +++++++++++------ src/parseh.cpp | 6 +++++- src/parseh.hpp | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index 890622e807..4e464d7137 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1041,6 +1041,9 @@ struct CodeGen { uint32_t error_value_count; TypeTableEntry *err_tag_type; LLVMValueRef int_overflow_fns[2][3][4]; // [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64] + + const char **clang_argv; + int clang_argv_len; }; struct VariableTableEntry { diff --git a/src/analyze.cpp b/src/analyze.cpp index 0ca480fdd0..a8434cde36 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1057,7 +1057,9 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *import, AstNode find_libc_path(g); int err; ParseH parse_h = {{0}}; - if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, buf_ptr(g->libc_include_path)))) { + if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, g->clang_argv, g->clang_argv_len, + buf_ptr(g->libc_include_path)))) + { zig_panic("unable to parse h file: %s\n", err_str(err)); } diff --git a/src/codegen.cpp b/src/codegen.cpp index 78592e4d09..c05dde8f69 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -32,6 +32,11 @@ CodeGen *codegen_create(Buf *root_source_dir) { return g; } +void codegen_set_clang_argv(CodeGen *g, const char **args, int len) { + g->clang_argv = args; + g->clang_argv_len = len; +} + void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) { g->build_type = build_type; } diff --git a/src/codegen.hpp b/src/codegen.hpp index b7cf9097d3..a8044a7395 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -13,6 +13,7 @@ CodeGen *codegen_create(Buf *root_source_dir); +void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len); void codegen_set_build_type(CodeGen *codegen, CodeGenBuildType build_type); void codegen_set_is_static(CodeGen *codegen, bool is_static); void codegen_set_strip(CodeGen *codegen, bool strip); diff --git a/src/main.cpp b/src/main.cpp index bd85f2c225..8505340239 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ static int usage(const char *arg0) { " build create executable, object, or library from target\n" " version print version number and exit\n" " parseh convert a c header file to zig extern declarations\n" - "Command: build target\n" + "Options:\n" " --release build with optimizations on and debug protection off\n" " --static output will be statically linked\n" " --strip exclude debug symbols\n" @@ -30,10 +30,8 @@ static int usage(const char *arg0) { " --verbose turn on compiler debug output\n" " --color [auto|off|on] enable or disable colored error messages\n" " --libc-path [path] set the C compiler data path\n" - "Command: parseh target\n" " -isystem [dir] add additional search path for other .h files\n" " -dirafter [dir] same as -isystem but do it last\n" - " -B[prefix] set the C compiler data path\n" , arg0); return EXIT_FAILURE; } @@ -54,6 +52,7 @@ struct Build { bool verbose; ErrColor color; const char *libc_path; + ZigList clang_argv; }; static int build(const char *arg0, int argc, char **argv) { @@ -62,7 +61,7 @@ static int build(const char *arg0, int argc, char **argv) { for (int i = 0; i < argc; i += 1) { char *arg = argv[i]; - if (arg[0] == '-' && arg[1] == '-') { + if (arg[0] == '-') { if (strcmp(arg, "--release") == 0) { b.release = true; } else if (strcmp(arg, "--strip") == 0) { @@ -103,6 +102,12 @@ static int build(const char *arg0, int argc, char **argv) { b.out_name = argv[i]; } else if (strcmp(arg, "--libc-path") == 0) { b.libc_path = argv[i]; + } else if (strcmp(arg, "-isystem") == 0) { + b.clang_argv.append("-isystem"); + b.clang_argv.append(argv[i]); + } else if (strcmp(arg, "-dirafter") == 0) { + b.clang_argv.append("-dirafter"); + b.clang_argv.append(argv[i]); } else { return usage(arg0); } @@ -140,6 +145,7 @@ static int build(const char *arg0, int argc, char **argv) { CodeGen *g = codegen_create(&root_source_dir); codegen_set_build_type(g, b.release ? CodeGenBuildTypeRelease : CodeGenBuildTypeDebug); + codegen_set_clang_argv(g, b.clang_argv.items, b.clang_argv.length); codegen_set_strip(g, b.strip); codegen_set_is_static(g, b.is_static); if (b.out_type != OutTypeUnknown) @@ -202,8 +208,7 @@ static int parseh(const char *arg0, int argc, char **argv) { } clang_argv.append("-isystem"); clang_argv.append(argv[i + 1]); - } else if (arg[1] == 'B') { - clang_argv.append(arg); + i += 1; } else { fprintf(stderr, "unrecognized argument: %s", arg); return usage(arg0); diff --git a/src/parseh.cpp b/src/parseh.cpp index 73f7faa041..3721c83e79 100644 --- a/src/parseh.cpp +++ b/src/parseh.cpp @@ -345,7 +345,7 @@ static bool decl_visitor(void *context, const Decl *decl) { return true; } -int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) { +int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path) { int err; Buf tmp_file_path = BUF_INIT; if ((err = os_buf_to_tmp_file(source, buf_create_from_str(".h"), &tmp_file_path))) { @@ -357,6 +357,10 @@ int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) { clang_argv.append("-isystem"); clang_argv.append(libc_include_path); + for (int i = 0; i < args_len; i += 1) { + clang_argv.append(args[i]); + } + err = parse_h_file(parse_h, &clang_argv); os_delete_file(&tmp_file_path); diff --git a/src/parseh.hpp b/src/parseh.hpp index 356bbf50cf..b7cb9af279 100644 --- a/src/parseh.hpp +++ b/src/parseh.hpp @@ -12,6 +12,6 @@ #include "all_types.hpp" int parse_h_file(ParseH *parse_h, ZigList *clang_argv); -int parse_h_buf(ParseH *parse_h, Buf *buf, const char *libc_include_path); +int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path); #endif