-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[Clang] [Driver] add a Cygwin ToolChain #135691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
949ec2a
[Clang] [Driver] add a Cygwin ToolChain
jeremyd2019 2604448
[Clang][Driver] add test for new Cygwin driver
jeremyd2019 35091a9
fixup! [Clang] [Driver] add a Cygwin ToolChain
jeremyd2019 7cefcc5
fixup! [Clang] [Driver] add a Cygwin ToolChain
jeremyd2019 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Cygwin.h" | ||
#include "CommonArgs.h" | ||
#include "clang/Config/config.h" | ||
#include "clang/Driver/Driver.h" | ||
#include "clang/Driver/Options.h" | ||
#include "llvm/Support/Path.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
|
||
using namespace clang::driver; | ||
using namespace clang::driver::toolchains; | ||
using namespace clang; | ||
using namespace llvm::opt; | ||
|
||
using tools::addPathIfExists; | ||
|
||
Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | ||
: Generic_GCC(D, Triple, Args) { | ||
GCCInstallation.init(Triple, Args); | ||
std::string SysRoot = computeSysRoot(); | ||
ToolChain::path_list &PPaths = getProgramPaths(); | ||
|
||
Generic_GCC::PushPPaths(PPaths); | ||
|
||
path_list &Paths = getFilePaths(); | ||
|
||
Generic_GCC::AddMultiarchPaths(D, SysRoot, "lib", Paths); | ||
|
||
// Similar to the logic for GCC above, if we are currently running Clang | ||
// inside of the requested system root, add its parent library path to those | ||
// searched. | ||
// FIXME: It's not clear whether we should use the driver's installed | ||
// directory ('Dir' below) or the ResourceDir. | ||
if (StringRef(D.Dir).starts_with(SysRoot)) | ||
addPathIfExists(D, D.Dir + "/../lib", Paths); | ||
|
||
addPathIfExists(D, SysRoot + "/lib", Paths); | ||
addPathIfExists(D, SysRoot + "/usr/lib", Paths); | ||
addPathIfExists(D, SysRoot + "/usr/lib/w32api", Paths); | ||
} | ||
|
||
llvm::ExceptionHandling Cygwin::GetExceptionModel(const ArgList &Args) const { | ||
if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 || | ||
getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb) | ||
return llvm::ExceptionHandling::WinEH; | ||
return llvm::ExceptionHandling::DwarfCFI; | ||
} | ||
|
||
void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | ||
ArgStringList &CC1Args) const { | ||
const Driver &D = getDriver(); | ||
std::string SysRoot = computeSysRoot(); | ||
|
||
if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) | ||
return; | ||
|
||
if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) | ||
addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); | ||
|
||
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | ||
SmallString<128> P(D.ResourceDir); | ||
llvm::sys::path::append(P, "include"); | ||
addSystemInclude(DriverArgs, CC1Args, P); | ||
} | ||
|
||
if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | ||
return; | ||
|
||
// Check for configure-time C include directories. | ||
StringRef CIncludeDirs(C_INCLUDE_DIRS); | ||
if (CIncludeDirs != "") { | ||
SmallVector<StringRef, 5> Dirs; | ||
CIncludeDirs.split(Dirs, ":"); | ||
for (StringRef Dir : Dirs) { | ||
StringRef Prefix = | ||
llvm::sys::path::is_absolute(Dir) ? "" : StringRef(SysRoot); | ||
addExternCSystemInclude(DriverArgs, CC1Args, Prefix + Dir); | ||
} | ||
return; | ||
} | ||
|
||
// Lacking those, try to detect the correct set of system includes for the | ||
// target triple. | ||
|
||
AddMultilibIncludeArgs(DriverArgs, CC1Args); | ||
|
||
// On systems using multiarch, add /usr/include/$triple before | ||
// /usr/include. | ||
std::string MultiarchIncludeDir = getTriple().str(); | ||
if (!MultiarchIncludeDir.empty() && | ||
D.getVFS().exists(SysRoot + "/usr/include/" + MultiarchIncludeDir)) | ||
addExternCSystemInclude(DriverArgs, CC1Args, | ||
SysRoot + "/usr/include/" + MultiarchIncludeDir); | ||
|
||
// Add an include of '/include' directly. This isn't provided by default by | ||
// system GCCs, but is often used with cross-compiling GCCs, and harmless to | ||
// add even when Clang is acting as-if it were a system compiler. | ||
addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); | ||
|
||
addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); | ||
addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CYGWIN_H | ||
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CYGWIN_H | ||
|
||
#include "Gnu.h" | ||
#include "clang/Driver/ToolChain.h" | ||
|
||
namespace clang { | ||
namespace driver { | ||
namespace toolchains { | ||
|
||
class LLVM_LIBRARY_VISIBILITY Cygwin : public Generic_GCC { | ||
public: | ||
Cygwin(const Driver &D, const llvm::Triple &Triple, | ||
const llvm::opt::ArgList &Args); | ||
|
||
llvm::ExceptionHandling | ||
GetExceptionModel(const llvm::opt::ArgList &Args) const override; | ||
|
||
void | ||
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, | ||
llvm::opt::ArgStringList &CC1Args) const override; | ||
}; | ||
|
||
} // end namespace toolchains | ||
} // end namespace driver | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CYGWIN_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.