authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 19:22:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 19:22:58-07:00
logc281533638dd08bb84f4f538fd8c5ae85791d034
tree94ed711ef254a4b35d729dd944c1da2d0f833e63
parent69d4f55fbf816bf417dfab9c0e7525971922f166

build command supports -isystem argument


7 files changed, 29 insertions(+), 9 deletions(-)

src/all_types.hpp+3
...@@ -1041,6 +1041,9 @@ struct CodeGen {...@@ -1041,6 +1041,9 @@ struct CodeGen {
1041 uint32_t error_value_count;1041 uint32_t error_value_count;
1042 TypeTableEntry *err_tag_type;1042 TypeTableEntry *err_tag_type;
1043 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]1043 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]
1044
1045 const char **clang_argv;
1046 int clang_argv_len;
1044};1047};
10451048
1046struct VariableTableEntry {1049struct VariableTableEntry {
src/analyze.cpp+3-1
...@@ -1057,7 +1057,9 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *import, AstNode...@@ -1057,7 +1057,9 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *import, AstNode
1057 find_libc_path(g);1057 find_libc_path(g);
1058 int err;1058 int err;
1059 ParseH parse_h = {{0}};1059 ParseH parse_h = {{0}};
1060 if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, buf_ptr(g->libc_include_path)))) {1060 if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, g->clang_argv, g->clang_argv_len,
1061 buf_ptr(g->libc_include_path))))
1062 {
1061 zig_panic("unable to parse h file: %s\n", err_str(err));1063 zig_panic("unable to parse h file: %s\n", err_str(err));
1062 }1064 }
10631065
src/codegen.cpp+5
...@@ -32,6 +32,11 @@ CodeGen *codegen_create(Buf *root_source_dir) {...@@ -32,6 +32,11 @@ CodeGen *codegen_create(Buf *root_source_dir) {
32 return g;32 return g;
33}33}
3434
35void codegen_set_clang_argv(CodeGen *g, const char **args, int len) {
36 g->clang_argv = args;
37 g->clang_argv_len = len;
38}
39
35void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) {40void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) {
36 g->build_type = build_type;41 g->build_type = build_type;
37}42}
src/codegen.hpp+1
...@@ -13,6 +13,7 @@...@@ -13,6 +13,7 @@
1313
14CodeGen *codegen_create(Buf *root_source_dir);14CodeGen *codegen_create(Buf *root_source_dir);
1515
16void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len);
16void codegen_set_build_type(CodeGen *codegen, CodeGenBuildType build_type);17void codegen_set_build_type(CodeGen *codegen, CodeGenBuildType build_type);
17void codegen_set_is_static(CodeGen *codegen, bool is_static);18void codegen_set_is_static(CodeGen *codegen, bool is_static);
18void codegen_set_strip(CodeGen *codegen, bool strip);19void codegen_set_strip(CodeGen *codegen, bool strip);
src/main.cpp+11-6
...@@ -20,7 +20,7 @@ static int usage(const char *arg0) {...@@ -20,7 +20,7 @@ static int usage(const char *arg0) {
20 " build create executable, object, or library from target\n"20 " build create executable, object, or library from target\n"
21 " version print version number and exit\n"21 " version print version number and exit\n"
22 " parseh convert a c header file to zig extern declarations\n"22 " parseh convert a c header file to zig extern declarations\n"
23 "Command: build target\n"23 "Options:\n"
24 " --release build with optimizations on and debug protection off\n"24 " --release build with optimizations on and debug protection off\n"
25 " --static output will be statically linked\n"25 " --static output will be statically linked\n"
26 " --strip exclude debug symbols\n"26 " --strip exclude debug symbols\n"
...@@ -30,10 +30,8 @@ static int usage(const char *arg0) {...@@ -30,10 +30,8 @@ static int usage(const char *arg0) {
30 " --verbose turn on compiler debug output\n"30 " --verbose turn on compiler debug output\n"
31 " --color [auto|off|on] enable or disable colored error messages\n"31 " --color [auto|off|on] enable or disable colored error messages\n"
32 " --libc-path [path] set the C compiler data path\n"32 " --libc-path [path] set the C compiler data path\n"
33 "Command: parseh target\n"
34 " -isystem [dir] add additional search path for other .h files\n"33 " -isystem [dir] add additional search path for other .h files\n"
35 " -dirafter [dir] same as -isystem but do it last\n"34 " -dirafter [dir] same as -isystem but do it last\n"
36 " -B[prefix] set the C compiler data path\n"
37 , arg0);35 , arg0);
38 return EXIT_FAILURE;36 return EXIT_FAILURE;
39}37}
...@@ -54,6 +52,7 @@ struct Build {...@@ -54,6 +52,7 @@ struct Build {
54 bool verbose;52 bool verbose;
55 ErrColor color;53 ErrColor color;
56 const char *libc_path;54 const char *libc_path;
55 ZigList<const char *> clang_argv;
57};56};
5857
59static int build(const char *arg0, int argc, char **argv) {58static int build(const char *arg0, int argc, char **argv) {
...@@ -62,7 +61,7 @@ static int build(const char *arg0, int argc, char **argv) {...@@ -62,7 +61,7 @@ static int build(const char *arg0, int argc, char **argv) {
6261
63 for (int i = 0; i < argc; i += 1) {62 for (int i = 0; i < argc; i += 1) {
64 char *arg = argv[i];63 char *arg = argv[i];
65 if (arg[0] == '-' && arg[1] == '-') {64 if (arg[0] == '-') {
66 if (strcmp(arg, "--release") == 0) {65 if (strcmp(arg, "--release") == 0) {
67 b.release = true;66 b.release = true;
68 } else if (strcmp(arg, "--strip") == 0) {67 } else if (strcmp(arg, "--strip") == 0) {
...@@ -103,6 +102,12 @@ static int build(const char *arg0, int argc, char **argv) {...@@ -103,6 +102,12 @@ static int build(const char *arg0, int argc, char **argv) {
103 b.out_name = argv[i];102 b.out_name = argv[i];
104 } else if (strcmp(arg, "--libc-path") == 0) {103 } else if (strcmp(arg, "--libc-path") == 0) {
105 b.libc_path = argv[i];104 b.libc_path = argv[i];
105 } else if (strcmp(arg, "-isystem") == 0) {
106 b.clang_argv.append("-isystem");
107 b.clang_argv.append(argv[i]);
108 } else if (strcmp(arg, "-dirafter") == 0) {
109 b.clang_argv.append("-dirafter");
110 b.clang_argv.append(argv[i]);
106 } else {111 } else {
107 return usage(arg0);112 return usage(arg0);
108 }113 }
...@@ -140,6 +145,7 @@ static int build(const char *arg0, int argc, char **argv) {...@@ -140,6 +145,7 @@ static int build(const char *arg0, int argc, char **argv) {
140145
141 CodeGen *g = codegen_create(&root_source_dir);146 CodeGen *g = codegen_create(&root_source_dir);
142 codegen_set_build_type(g, b.release ? CodeGenBuildTypeRelease : CodeGenBuildTypeDebug);147 codegen_set_build_type(g, b.release ? CodeGenBuildTypeRelease : CodeGenBuildTypeDebug);
148 codegen_set_clang_argv(g, b.clang_argv.items, b.clang_argv.length);
143 codegen_set_strip(g, b.strip);149 codegen_set_strip(g, b.strip);
144 codegen_set_is_static(g, b.is_static);150 codegen_set_is_static(g, b.is_static);
145 if (b.out_type != OutTypeUnknown)151 if (b.out_type != OutTypeUnknown)
...@@ -202,8 +208,7 @@ static int parseh(const char *arg0, int argc, char **argv) {...@@ -202,8 +208,7 @@ static int parseh(const char *arg0, int argc, char **argv) {
202 }208 }
203 clang_argv.append("-isystem");209 clang_argv.append("-isystem");
204 clang_argv.append(argv[i + 1]);210 clang_argv.append(argv[i + 1]);
205 } else if (arg[1] == 'B') {211 i += 1;
206 clang_argv.append(arg);
207 } else {212 } else {
208 fprintf(stderr, "unrecognized argument: %s", arg);213 fprintf(stderr, "unrecognized argument: %s", arg);
209 return usage(arg0);214 return usage(arg0);
src/parseh.cpp+5-1
...@@ -345,7 +345,7 @@ static bool decl_visitor(void *context, const Decl *decl) {...@@ -345,7 +345,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
345 return true;345 return true;
346}346}
347347
348int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) {348int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path) {
349 int err;349 int err;
350 Buf tmp_file_path = BUF_INIT;350 Buf tmp_file_path = BUF_INIT;
351 if ((err = os_buf_to_tmp_file(source, buf_create_from_str(".h"), &tmp_file_path))) {351 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) {...@@ -357,6 +357,10 @@ int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) {
357 clang_argv.append("-isystem");357 clang_argv.append("-isystem");
358 clang_argv.append(libc_include_path);358 clang_argv.append(libc_include_path);
359359
360 for (int i = 0; i < args_len; i += 1) {
361 clang_argv.append(args[i]);
362 }
363
360 err = parse_h_file(parse_h, &clang_argv);364 err = parse_h_file(parse_h, &clang_argv);
361365
362 os_delete_file(&tmp_file_path);366 os_delete_file(&tmp_file_path);
src/parseh.hpp+1-1
...@@ -12,6 +12,6 @@...@@ -12,6 +12,6 @@
12#include "all_types.hpp"12#include "all_types.hpp"
1313
14int parse_h_file(ParseH *parse_h, ZigList<const char *> *clang_argv);14int parse_h_file(ParseH *parse_h, ZigList<const char *> *clang_argv);
15int parse_h_buf(ParseH *parse_h, Buf *buf, const char *libc_include_path);15int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path);
1616
17#endif17#endif