aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-26 22:48:37 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-26 22:48:37 -0400
commitdb17c0d88c44183b3060993d85657e7637b43d68 (patch)
tree5a267a81e6e28ecc1e46842696fd735a24757845 /src/codegen.cpp
parented0dbe1a64a80dc329daab3776bda9d3fa54c9f8 (diff)
downloadzig-db17c0d88c44183b3060993d85657e7637b43d68.tar.gz
zig-db17c0d88c44183b3060993d85657e7637b43d68.zip
ability to compile c++ hello world with `zig c++`
closes #4786
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index cb1ab6b6b8..d9e011c4f3 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -8700,6 +8700,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);
buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));
buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));
+ buf_appendf(contents, "pub const link_libcpp = %s;\n", bool_to_str(g->libcpp_link_lib != nullptr));
buf_appendf(contents, "pub const have_error_return_tracing = %s;\n", bool_to_str(g->have_err_ret_tracing));
buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));
buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
@@ -8798,6 +8799,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
}
cache_bool(&cache_hash, g->have_err_ret_tracing);
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
+ cache_bool(&cache_hash, g->libcpp_link_lib != nullptr);
cache_bool(&cache_hash, g->valgrind_support);
cache_bool(&cache_hash, g->link_eh_frame_hdr);
cache_int(&cache_hash, detect_subsystem(g));
@@ -9205,6 +9207,14 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
args.append(g->framework_dirs.at(i));
}
+ if (g->libcpp_link_lib != nullptr) {
+ const char *libcxx_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxx" OS_SEP "include",
+ buf_ptr(g->zig_lib_dir)));
+
+ args.append("-isystem");
+ args.append(libcxx_include_path);
+ }
+
// According to Rich Felker libc headers are supposed to go before C language headers.
// However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics
// and other compiler specific items.