Debian Codegraph @

clang/test/Driver/mingw-sysroot.cpp

raw
1 // UNSUPPORTED: system-windows
2
3 // RUN: rm -rf %t.dir/testroot-gcc
4 // RUN: mkdir -p %t.dir/testroot-gcc/bin
5 // RUN: ln -s %clang %t.dir/testroot-gcc/bin/x86_64-w64-mingw32-gcc
6 // RUN: ln -s %clang %t.dir/testroot-gcc/bin/x86_64-w64-mingw32-clang
7 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %t.dir/testroot-gcc/x86_64-w64-mingw32
8 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/lib %t.dir/testroot-gcc/lib
9
10 // RUN: rm -rf %t.dir/testroot-clang
11 // RUN: mkdir -p %t.dir/testroot-clang/bin
12 // RUN: ln -s %clang %t.dir/testroot-clang/bin/x86_64-w64-mingw32-clang
13 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %t.dir/testroot-clang/x86_64-w64-mingw32
14 // RUN: ln -s %S/Inputs/mingw_arch_tree/usr/i686-w64-mingw32 %t.dir/testroot-clang/i686-w64-mingw32
15
16 // RUN: rm -rf %t.dir/testroot-clang-native
17 // RUN: mkdir -p %t.dir/testroot-clang-native/bin
18 // RUN: ln -s %clang %t.dir/testroot-clang-native/bin/clang
19 // RUN: mkdir -p %t.dir/testroot-clang-native/include/_mingw.h
20 // RUN: mkdir -p %t.dir/testroot-clang-native/lib/libkernel32.a
21
22 // RUN: rm -rf %t.dir/testroot-custom-triple
23 // RUN: mkdir -p %t.dir/testroot-custom-triple/bin
24 // RUN: ln -s %clang %t.dir/testroot-custom-triple/bin/clang
25 // RUN: ln -s %S/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32 %t.dir/testroot-custom-triple/x86_64-w64-mingw32foo
26
27 // If we find a gcc in the path with the right triplet prefix, pick that as
28 // sysroot:
29
30 // This test is only executed on non-Windows systems, i.e. only when
31 // cross compiling. Check that we don't add the tool root's plain include
32 // directory to the path - this would end up including /usr/include for
33 // cross toolchains installed in /usr.
34
35 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s --implicit-check-not="\"{{.*}}/testroot-gcc{{/|\\\\}}include\""
36 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE:[^"]+]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++"
37 // CHECK_TESTROOT_GCC-SAME: {{^}} "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}x86_64-w64-mingw32"
38 // CHECK_TESTROOT_GCC-SAME: {{^}} "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}backward"
39 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10.2-posix"
40 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10.2"
41 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}10.2-posix{{/|\\\\}}include{{/|\\\\}}g++-v10"
42 // CHECK_TESTROOT_GCC: "-internal-isystem" "[[BASE]]/testroot-gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
43
44
45 // If we pass --sysroot explicitly, then we do include <sysroot>/include
46 // even when cross compiling.
47 // RUN: %clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="%t.dir/testroot-gcc" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC_EXPLICIT %s
48
49 // CHECK_TESTROOT_GCC_EXPLICIT: "-internal-isystem" "{{[^"]+}}/testroot-gcc{{/|\\\\}}include"
50
51
52 // If -no-canonical-prefixes and there's a matching sysroot next to the clang binary itself, prefer that
53 // over a gcc in the path:
54
55 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %t.dir/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC2 %s
56 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %t.dir/testroot-clang/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s -no-canonical-prefixes 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG %s
57 // CHECK_TESTROOT_GCC2: "{{[^"]+}}/testroot-gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
58 // CHECK_TESTROOT_CLANG: "{{[^"]+}}/testroot-clang{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
59
60
61 // If we pick a root based on a sysroot next to the clang binary, which also
62 // happens to be in the same directory as gcc, make sure we still can pick up
63 // the libgcc directory:
64
65 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %t.dir/testroot-gcc/bin/x86_64-w64-mingw32-clang --target=x86_64-w64-mingw32 -rtlib=platform -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_GCC %s
66
67
68 // If we're executing clang from a directory with what looks like a mingw sysroot,
69 // with headers in <base>/include and libs in <base>/lib, use that rather than looking
70 // for another GCC in the path.
71 //
72 // Note, this test has a surprising quirk: We're testing with an install directory,
73 // testroot-clang-native, which lacks the "x86_64-w64-mingw32" subdirectory, it only
74 // has the include and lib subdirectories without any triple prefix.
75 //
76 // Since commit fd15cb935d7aae25ad62bfe06fe9f17cea585978, we avoid using the
77 // <base>/include and <base>/lib directories when cross compiling. So technically, this
78 // case testcase only works exactly as expected when running on x86_64 Windows, when
79 // this target isn't considered cross compiling.
80 //
81 // However we do still pass the include directory <base>/x86_64-w64-mingw32/include to
82 // the -cc1 interface, even if it is missing. Thus, this test looks for this path name,
83 // that indicates that we did choose the right base, even if this particular directory
84 // actually doesn't exist here.
85
86 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %t.dir/testroot-clang-native/bin/clang -no-canonical-prefixes --target=x86_64-w64-mingw32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG_NATIVE %s
87 // CHECK_TESTROOT_CLANG_NATIVE: "{{[^"]+}}/testroot-clang-native{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
88
89
90 // If the user requests a different arch via the -m32 option, which changes
91 // x86_64 into i386, check that the driver notices that it can't find a
92 // sysroot for i386 but there is one for i686, and uses that one.
93 // (In practice, the real usecase is when using an unprefixed native clang
94 // that defaults to x86_64 mingw, but it's easier to test this in cross setups
95 // with symlinks, like the other tests here.)
96
97 // RUN: env "PATH=%t.dir/testroot-gcc/bin:%PATH%" %t.dir/testroot-clang/bin/x86_64-w64-mingw32-clang -no-canonical-prefixes --target=x86_64-w64-mingw32 -m32 -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CLANG_I686 %s
98 // CHECK_TESTROOT_CLANG_I686: "{{[^"]+}}/testroot-clang{{/|\\\\}}i686-w64-mingw32{{/|\\\\}}include"
99
100
101 // If the user calls clang with a custom literal triple, make sure this maps
102 // to sysroots with the matching spelling.
103
104 // RUN: %t.dir/testroot-custom-triple/bin/clang -no-canonical-prefixes --target=x86_64-w64-mingw32foo -rtlib=compiler-rt -stdlib=libstdc++ --sysroot="" -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_TESTROOT_CUSTOM_TRIPLE %s
105 // CHECK_TESTROOT_CUSTOM_TRIPLE: "{{[^"]+}}/testroot-custom-triple{{/|\\\\}}x86_64-w64-mingw32foo{{/|\\\\}}include"