Commit c281533638
Changed files (7)
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 {
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));
}
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;
}
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);
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<const char *> 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);
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);
src/parseh.hpp
@@ -12,6 +12,6 @@
#include "all_types.hpp"
int parse_h_file(ParseH *parse_h, ZigList<const char *> *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