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/cc_test.go b/cc/cc_test.go
index 2e6c152..90ec811 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -2734,6 +2734,11 @@
func TestIncludeDirectoryOrdering(t *testing.T) {
t.Parallel()
+
+ expectedPlatformFlags := []string{
+ "-nostdlibinc",
+ }
+
baseExpectedFlags := []string{
"${config.ArmThumbCflags}",
"${config.ArmCflags}",
@@ -2795,9 +2800,9 @@
cstd := []string{"-std=gnu17", "-std=conly"}
cppstd := []string{"-std=gnu++20", "-std=cpp", "-fno-rtti"}
- lastNDKIncludes := []string{
- "out/soong/ndk/sysroot/usr/include",
- "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
+ lastNDKFlags := []string{
+ "--sysroot",
+ "out/soong/ndk/sysroot",
}
lastPlatformIncludes := []string{
@@ -2821,10 +2826,11 @@
expectedNDKSTLIncludes,
cflags,
cstd,
- lastNDKIncludes,
+ lastNDKFlags,
[]string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"},
),
expectedPlatform: slices.Concat(
+ expectedPlatformFlags,
baseExpectedFlags,
expectedTargetPlatformFlags,
conly,
@@ -2846,10 +2852,11 @@
expectedNDKSTLIncludes,
cflags,
cppstd,
- lastNDKIncludes,
+ lastNDKFlags,
[]string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"},
),
expectedPlatform: slices.Concat(
+ expectedPlatformFlags,
baseExpectedFlags,
expectedTargetPlatformFlags,
cppOnly,
@@ -2869,9 +2876,10 @@
[]string{"${config.CommonGlobalAsflags}"},
expectedIncludes,
expectedNDKSTLIncludes,
- lastNDKIncludes,
+ lastNDKFlags,
),
expectedPlatform: slices.Concat(
+ expectedPlatformFlags,
baseExpectedFlags,
expectedTargetPlatformFlags,
[]string{"${config.CommonGlobalAsflags}"},