Browse Source

Make sure the compilers find the files

HOLZSCHUCH Nicolas 5 năm trước cách đây
mục cha
commit
ebd095683a

+ 12 - 0
lib/Driver/Driver.cpp

@@ -86,6 +86,14 @@
 #include <sysexits.h> // EX_IOERR
 #endif
 
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
+#include "ios_error.h"
+#endif
+#endif 
+
+
 using namespace clang::driver;
 using namespace clang;
 using namespace llvm::opt;
@@ -131,6 +139,10 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
       CheckInputsExist(true), GenReproducer(false),
       SuppressMissingInputWarning(false) {
 
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+	// sysroot location depends on App location, which is unknown at compile time:
+	SysRoot = ::getenv("SYSROOT");
+#endif
   // Provide a sane fallback if no VFS is specified.
   if (!this->VFS)
     this->VFS = llvm::vfs::getRealFileSystem();

+ 15 - 0
lib/Driver/ToolChains/Darwin.cpp

@@ -25,6 +25,14 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include <cstdlib> // ::getenv
 
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
+#include "ios_error.h"
+#undef getenv
+#endif
+#endif 
+
 using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
@@ -1922,7 +1930,14 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
     // On Darwin, libc++ is installed alongside the compiler in
     // include/c++/v1, so get from '<install>/bin' to '<install>/include/c++/v1'.
     {
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+		// on iOS, compilers are installed elsewhere, but we pretend they are in 
+		// $SYSROOT/usr/bin 
+      llvm::SmallString<128> P = Sysroot;
+      llvm::sys::path::append(P, "usr", "bin");
+#else    	
       llvm::SmallString<128> P = llvm::StringRef(getDriver().getInstalledDir());
+#endif
       // Note that P can be relative, so we have to '..' and not parent_path.
       llvm::sys::path::append(P, "..", "include", "c++", "v1");
       addSystemInclude(DriverArgs, CC1Args, P);

+ 8 - 0
lib/Driver/ToolChains/WebAssembly.cpp

@@ -98,7 +98,15 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
 
   assert(Triple.isArch32Bit() != Triple.isArch64Bit());
 
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+		// on iOS, compilers are installed elsewhere, but we pretend they are in 
+		// $SYSROOT/usr/bin 
+      llvm::SmallString<128> P = Sysroot;
+      llvm::sys::path::append(P, "usr", "bin");
+	  getProgramPaths().push_back(P);
+#else    	
   getProgramPaths().push_back(getDriver().getInstalledDir());
+#endif
 
   if (getTriple().getOS() == llvm::Triple::UnknownOS) {
     // Theoretically an "unknown" OS should mean no standard libraries, however