ability to compile c++ hello world with zig c++

closes #4786
This commit is contained in:
Andrew Kelley
2020-03-26 22:48:37 -04:00
parent ed0dbe1a64
commit db17c0d88c
10 changed files with 221 additions and 2 deletions

View File

@@ -412,6 +412,7 @@ static int main0(int argc, char **argv) {
ZigList<const char *> framework_dirs = {0};
ZigList<const char *> frameworks = {0};
bool have_libc = false;
bool have_libcpp = false;
const char *target_string = nullptr;
bool rdynamic = false;
const char *linker_script = nullptr;
@@ -456,6 +457,7 @@ static int main0(int argc, char **argv) {
const char *override_soname = nullptr;
bool only_preprocess = false;
bool ensure_libc_on_non_freestanding = false;
bool ensure_libcpp_on_non_freestanding = false;
ZigList<const char *> llvm_argv = {0};
llvm_argv.append("zig (LLVM option parsing)");
@@ -580,10 +582,11 @@ static int main0(int argc, char **argv) {
return (term.how == TerminationIdClean) ? term.code : -1;
} else if (argc >= 2 && strcmp(argv[1], "fmt") == 0) {
return stage2_fmt(argc, argv);
} else if (argc >= 2 && strcmp(argv[1], "cc") == 0) {
} else if (argc >= 2 && (strcmp(argv[1], "cc") == 0 || strcmp(argv[1], "c++") == 0)) {
emit_h = false;
strip = true;
ensure_libc_on_non_freestanding = true;
ensure_libcpp_on_non_freestanding = (strcmp(argv[1], "c++") == 0);
bool c_arg = false;
Stage2ClangArgIterator it;
@@ -632,6 +635,8 @@ static int main0(int argc, char **argv) {
case Stage2ClangArgL: // -l
if (strcmp(it.only_arg, "c") == 0)
have_libc = true;
if (strcmp(it.only_arg, "c++") == 0)
have_libcpp = true;
link_libs.append(it.only_arg);
break;
case Stage2ClangArgIgnore:
@@ -648,6 +653,9 @@ static int main0(int argc, char **argv) {
case Stage2ClangArgNoStdLib:
ensure_libc_on_non_freestanding = false;
break;
case Stage2ClangArgNoStdLibCpp:
ensure_libcpp_on_non_freestanding = false;
break;
case Stage2ClangArgShared:
is_dynamic = true;
is_shared_lib = true;
@@ -916,6 +924,8 @@ static int main0(int argc, char **argv) {
const char *l = &arg[2];
if (strcmp(l, "c") == 0)
have_libc = true;
if (strcmp(l, "c++") == 0)
have_libcpp = true;
link_libs.append(l);
} else if (arg[1] == 'I' && arg[2] != 0) {
clang_argv.append("-I");
@@ -1057,6 +1067,8 @@ static int main0(int argc, char **argv) {
} else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
if (strcmp(argv[i], "c") == 0)
have_libc = true;
if (strcmp(argv[i], "c++") == 0)
have_libcpp = true;
link_libs.append(argv[i]);
} else if (strcmp(arg, "--forbid-library") == 0) {
forbidden_link_libs.append(argv[i]);
@@ -1221,6 +1233,10 @@ static int main0(int argc, char **argv) {
have_libc = true;
link_libs.append("c");
}
if (!have_libcpp && ensure_libcpp_on_non_freestanding && target.os != OsFreestanding) {
have_libcpp = true;
link_libs.append("c++");
}
Buf zig_triple_buf = BUF_INIT;
target_triple_zig(&zig_triple_buf, &target);