Use --sysroot when compiling against the NDK

Match the NDK build by using --sysroot to point to the NDK headers
rather than manually specifying the include directories with -isystem.
Also remove --nostdlibinc from the global cflags so it is not used
for NDK builds, and manually add it back for non-NDK builds.

This relands I42ed714ba534d8ce252609bf618d4e3433875f28 with a fix to
also apply -nostdlibinc to rust bindgen compilations.

Bug: 374130155
Test: all NDK modules build
Test: TestIncludeDirectoryOrdering
Flag: EXEMPT refactor
Change-Id: Ib809ca2790b6a62f52e5492a67767b49c25fd702
diff --git a/cc/compiler.go b/cc/compiler.go
index 7bba962..e49de6f 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -430,14 +430,14 @@
 	}
 
 	if ctx.useSdk() {
-		// TODO: Switch to --sysroot.
 		// The NDK headers are installed to a common sysroot. While a more
 		// typical Soong approach would be to only make the headers for the
 		// library you're using available, we're trying to emulate the NDK
 		// behavior here, and the NDK always has all the NDK headers available.
 		flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
-			"-isystem "+getCurrentIncludePath(ctx).String(),
-			"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
+			"--sysroot "+getNdkSysrootBase(ctx).String())
+	} else if ctx.Device() {
+		flags.Global.CommonFlags = append(flags.Global.CFlags, "-nostdlibinc")
 	}
 
 	if ctx.InVendorOrProduct() {