Commit 52db13738b

Andrew Kelley <andrew@ziglang.org>
2020-04-04 20:58:24
zig cc looks for native include directories unless -nostdinc
closes #4938
1 parent d02838b
src/main.cpp
@@ -447,6 +447,7 @@ static int main0(int argc, char **argv) {
     bool ensure_libc_on_non_freestanding = false;
     bool ensure_libcpp_on_non_freestanding = false;
     bool disable_c_depfile = false;
+    bool want_native_include_dirs = false;
     Buf *linker_optimization = nullptr;
     OptionalBool linker_gc_sections = OptionalBoolNull;
     OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;
@@ -581,6 +582,7 @@ static int main0(int argc, char **argv) {
         strip = true;
         ensure_libc_on_non_freestanding = true;
         ensure_libcpp_on_non_freestanding = (strcmp(argv[1], "c++") == 0);
+        want_native_include_dirs = true;
 
         bool c_arg = false;
         Stage2ClangArgIterator it;
@@ -747,6 +749,9 @@ static int main0(int argc, char **argv) {
                 case Stage2ClangArgFramework:
                     frameworks.append(it.only_arg);
                     break;
+                case Stage2ClangArgNoStdLibInc:
+                    want_native_include_dirs = false;
+                    break;
             }
         }
         // Parse linker args
@@ -1418,7 +1423,7 @@ static int main0(int argc, char **argv) {
                 }
             }
 
-            if (target.is_native_os && any_system_lib_dependencies) {
+            if (target.is_native_os && (any_system_lib_dependencies || want_native_include_dirs)) {
                 Error err;
                 Stage2NativePaths paths;
                 if ((err = stage2_detect_native_paths(&paths))) {
src/stage2.h
@@ -352,6 +352,7 @@ enum Stage2ClangArg {
     Stage2ClangArgDepFile,
     Stage2ClangArgFrameworkDir,
     Stage2ClangArgFramework,
+    Stage2ClangArgNoStdLibInc,
 };
 
 // ABI warning
src-self-hosted/clang_options_data.zig
@@ -1725,7 +1725,7 @@ flagpsl("MT"),
 .{
     .name = "no-standard-includes",
     .syntax = .flag,
-    .zig_equivalent = .other,
+    .zig_equivalent = .nostdlibinc,
     .pd1 = false,
     .pd2 = true,
     .psl = false,
@@ -3781,7 +3781,14 @@ flagpd1("nocudainc"),
 flagpd1("nodefaultlibs"),
 flagpd1("nofixprebinding"),
 flagpd1("nogpulib"),
-flagpd1("nolibc"),
+.{
+    .name = "nolibc",
+    .syntax = .flag,
+    .zig_equivalent = .nostdlib,
+    .pd1 = true,
+    .pd2 = false,
+    .psl = false,
+},
 flagpd1("nomultidefs"),
 flagpd1("fnon-call-exceptions"),
 flagpd1("fno-non-call-exceptions"),
@@ -3790,8 +3797,22 @@ flagpd1("noprebind"),
 flagpd1("noprofilelib"),
 flagpd1("noseglinkedit"),
 flagpd1("nostartfiles"),
-flagpd1("nostdinc"),
-flagpd1("nostdinc++"),
+.{
+    .name = "nostdinc",
+    .syntax = .flag,
+    .zig_equivalent = .nostdlibinc,
+    .pd1 = true,
+    .pd2 = false,
+    .psl = false,
+},
+.{
+    .name = "nostdinc++",
+    .syntax = .flag,
+    .zig_equivalent = .nostdlib_cpp,
+    .pd1 = true,
+    .pd2 = false,
+    .psl = false,
+},
 .{
     .name = "nostdlib",
     .syntax = .flag,
@@ -3800,7 +3821,14 @@ flagpd1("nostdinc++"),
     .pd2 = false,
     .psl = false,
 },
-flagpd1("nostdlibinc"),
+.{
+    .name = "nostdlibinc",
+    .syntax = .flag,
+    .zig_equivalent = .nostdlibinc,
+    .pd1 = true,
+    .pd2 = false,
+    .psl = false,
+},
 .{
     .name = "nostdlib++",
     .syntax = .flag,
src-self-hosted/stage2.zig
@@ -1293,6 +1293,7 @@ pub const ClangArgIterator = extern struct {
         dep_file,
         framework_dir,
         framework,
+        nostdlibinc,
     };
 
     const Args = struct {
tools/update_clang_options.zig
@@ -54,6 +54,10 @@ const known_options = [_]KnownOpt{
         .name = "fno-PIC",
         .ident = "no_pic",
     },
+    .{
+        .name = "nolibc",
+        .ident = "nostdlib",
+    },
     .{
         .name = "nostdlib",
         .ident = "nostdlib",
@@ -66,6 +70,22 @@ const known_options = [_]KnownOpt{
         .name = "nostdlib++",
         .ident = "nostdlib_cpp",
     },
+    .{
+        .name = "nostdinc++",
+        .ident = "nostdlib_cpp",
+    },
+    .{
+        .name = "nostdlibinc",
+        .ident = "nostdlibinc",
+    },
+    .{
+        .name = "nostdinc",
+        .ident = "nostdlibinc",
+    },
+    .{
+        .name = "no-standard-includes",
+        .ident = "nostdlibinc",
+    },
     .{
         .name = "shared",
         .ident = "shared",