sbc100 created this revision. Herald added subscribers: cfe-commits, sunfish, aheejin, mgorny, dschuff. Herald added a project: clang. sbc100 retitled this revision from "Allow -DDEFAULT_SYSROOT to be a relative path" to "[clang] Allow -DDEFAULT_SYSROOT to be a relative path". sbc100 added reviewers: sunfish, phosek.
In this case we interpret the path as relative the llvm installation root. This allows SDKs to be build that include clang along with a custom sysroot without requiring users to specify --sysroot to point to the directory where they install the SDK. See https://github.com/WebAssembly/wasi-sdk/issues/58 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76653 Files: clang/CMakeLists.txt clang/lib/Driver/Driver.cpp Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -136,6 +136,10 @@ if (!this->VFS) this->VFS = llvm::vfs::getRealFileSystem(); + if (llvm::sys::path::is_relative(SysRoot)) { + SysRoot = GetResourcesPath(ClangExecutable, SysRoot); + } + Name = std::string(llvm::sys::path::filename(ClangExecutable)); Dir = std::string(llvm::sys::path::parent_path(ClangExecutable)); InstalledDir = Dir; // Provide a sensible default installed dir. Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -226,7 +226,7 @@ "Colon separated list of directories clang will search for headers.") set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." ) -set(DEFAULT_SYSROOT "" CACHE PATH +set(DEFAULT_SYSROOT "" CACHE STRING "Default <path> to all compiler invocations for --sysroot=<path>." ) set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -136,6 +136,10 @@ if (!this->VFS) this->VFS = llvm::vfs::getRealFileSystem(); + if (llvm::sys::path::is_relative(SysRoot)) { + SysRoot = GetResourcesPath(ClangExecutable, SysRoot); + } + Name = std::string(llvm::sys::path::filename(ClangExecutable)); Dir = std::string(llvm::sys::path::parent_path(ClangExecutable)); InstalledDir = Dir; // Provide a sensible default installed dir. Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -226,7 +226,7 @@ "Colon separated list of directories clang will search for headers.") set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." ) -set(DEFAULT_SYSROOT "" CACHE PATH +set(DEFAULT_SYSROOT "" CACHE STRING "Default <path> to all compiler invocations for --sysroot=<path>." ) set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits