[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: I think next on this would be to hook up so that it can call ld directly. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo approved this pull request. LGTM, thanks! https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo closed https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// jeremyd2019 wrote: Like so? https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/4] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -2632,6 +2632,27 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( return; } + if (TargetTriple.isWindowsCygwinEnvironment()) { +static const char *const CygwinX86Triples[] = {"i686-pc-cygwin", + "i686-pc-msys"}; +static const char *const CygwinX86_64Triples[] = {"x86_64-pc-cygwin", + "x86_64-pc-msys"}; +LibDirs.push_back("/lib"); +switch (TargetTriple.getArch()) { +case llvm::Triple::x86_64: + TripleAliases.append(begin(CygwinX86_64Triples), jeremyd2019 wrote: cool, I didn't know that worked. I was following what all the others were doing. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/3] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// MaskRay wrote: In new code, can remove the comments per the updated https://llvm.org/docs/CodingStandards.html#file-headers https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -2632,6 +2632,27 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( return; } + if (TargetTriple.isWindowsCygwinEnvironment()) { +static const char *const CygwinX86Triples[] = {"i686-pc-cygwin", + "i686-pc-msys"}; +static const char *const CygwinX86_64Triples[] = {"x86_64-pc-cygwin", + "x86_64-pc-msys"}; +LibDirs.push_back("/lib"); +switch (TargetTriple.getArch()) { +case llvm::Triple::x86_64: + TripleAliases.append(begin(CygwinX86_64Triples), MaskRay wrote: `TripleAliases.append({...})` and remove the array above https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/MaskRay commented: LGTM. But I hope folks more familiar with Windows can take a look. Can you describe the support triples in the description and state why we need the msys ones? (Wow, MSYS and Cygwin... familiar names! I used them back in 2009, but then I made the switch to Linux.) https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: Ping @MaskRay https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mati865 edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,77 @@ +// RUN: %clang -### %s --target=i686-pc-windows-cygnus --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s +// CHECK: "-cc1" +// CHECK-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]" +// CHECK-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/i686-pc-cygwin/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10/backward" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{(/|)}}include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/include" +// CHECK-SAME: "-internal-externc-isystem" "[[SYSROOT]]/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include/w32api" +// CHECK-SAME: "-femulated-tls" +// CHECK-SAME: "-exception-model=dwarf" +// CHECK: "{{.*}}gcc{{(\.exe)?}}" +// CHECK-SAME: "-m32" + +// RUN: %clang -### %s --target=i686-pc-cygwin --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: --stdlib=platform -static 2>&1 | FileCheck --check-prefix=CHECK-STATIC %s +// CHECK-STATIC: "-cc1" "-triple" "i686-pc-windows-cygnus" +// CHECK-STATIC-SAME: "-static-define" +// CHECK-STATIC: "{{.*}}gcc{{(\.exe)?}}" mstorsjo wrote: Sorry, I forgot to follow up here. Yes, calling GCC for linking certainly is fine, as that's what we're doing right now anyway, I guess. Getting rid of that is a future nice-to-have but not a blocker for taking this first step. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,77 @@ +// RUN: %clang -### %s --target=i686-pc-windows-cygnus --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s +// CHECK: "-cc1" +// CHECK-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]" +// CHECK-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/i686-pc-cygwin/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10/backward" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{(/|)}}include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/include" +// CHECK-SAME: "-internal-externc-isystem" "[[SYSROOT]]/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include/w32api" +// CHECK-SAME: "-femulated-tls" +// CHECK-SAME: "-exception-model=dwarf" +// CHECK: "{{.*}}gcc{{(\.exe)?}}" +// CHECK-SAME: "-m32" + +// RUN: %clang -### %s --target=i686-pc-cygwin --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: --stdlib=platform -static 2>&1 | FileCheck --check-prefix=CHECK-STATIC %s +// CHECK-STATIC: "-cc1" "-triple" "i686-pc-windows-cygnus" +// CHECK-STATIC-SAME: "-static-define" +// CHECK-STATIC: "{{.*}}gcc{{(\.exe)?}}" mati865 wrote: Agree with Jeremy, let's not spread oneself too thinly. Adding a dedicated driver is already a bit deal and solves a lot of problems. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,77 @@ +// RUN: %clang -### %s --target=i686-pc-windows-cygnus --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s +// CHECK: "-cc1" +// CHECK-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]" +// CHECK-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/i686-pc-cygwin/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10/backward" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{(/|)}}include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/include" +// CHECK-SAME: "-internal-externc-isystem" "[[SYSROOT]]/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include/w32api" +// CHECK-SAME: "-femulated-tls" +// CHECK-SAME: "-exception-model=dwarf" +// CHECK: "{{.*}}gcc{{(\.exe)?}}" +// CHECK-SAME: "-m32" + +// RUN: %clang -### %s --target=i686-pc-cygwin --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: --stdlib=platform -static 2>&1 | FileCheck --check-prefix=CHECK-STATIC %s +// CHECK-STATIC: "-cc1" "-triple" "i686-pc-windows-cygnus" +// CHECK-STATIC-SAME: "-static-define" +// CHECK-STATIC: "{{.*}}gcc{{(\.exe)?}}" jeremyd2019 wrote: yes. Once you are not calling GCC, you need to teach the driver about the default library search paths (which should already be taken care of), and default libraries, and the startup object files. Which is probably ultimately necessary, but for now, we can just keep calling gcc. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -0,0 +1,77 @@ +// RUN: %clang -### %s --target=i686-pc-windows-cygnus --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s +// CHECK: "-cc1" +// CHECK-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]" +// CHECK-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/i686-pc-cygwin/c++/10" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../include/c++/10/backward" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{(/|)}}include" +// CHECK-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/include" +// CHECK-SAME: "-internal-externc-isystem" "[[SYSROOT]]/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include" +// CHECK-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include/w32api" +// CHECK-SAME: "-femulated-tls" +// CHECK-SAME: "-exception-model=dwarf" +// CHECK: "{{.*}}gcc{{(\.exe)?}}" +// CHECK-SAME: "-m32" + +// RUN: %clang -### %s --target=i686-pc-cygwin --sysroot=%S/Inputs/basic_cygwin_tree \ +// RUN: --stdlib=platform -static 2>&1 | FileCheck --check-prefix=CHECK-STATIC %s +// CHECK-STATIC: "-cc1" "-triple" "i686-pc-windows-cygnus" +// CHECK-STATIC-SAME: "-static-define" +// CHECK-STATIC: "{{.*}}gcc{{(\.exe)?}}" mstorsjo wrote: Does this mean that we invoke `gcc` to drive the linking? I guess that's what's being done now before this change as well (and the fewer changes in this PR, the better); but I guess that's a nice to have for future changes as well, to be able to call the linker directly without involving gcc inbetween? https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo commented: I think the test looks good, thanks! I'd still want @MaskRay to ack this change before approving it though, as adding a new toolchain driver is a notable change. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: It did turn out to be just one more slash issue. Test is passing now on Windows (and Linux, and Cygwin itself) https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
mstorsjo wrote: > I'm fighting the tests on Windows - the hurd test I started from had `// > UNSUPPORTED: system-windows` at the top, probably because they weren't > interested in messing around with backslashes and .exe extensions. I don't > know if the cross test will work right for the path to the cross as, is there > some way to annotate just one test in the file as unsupported or expected > fail or something on Windows? > > (Locally, I ran the tests on Cygwin and they worked fine) > > Looking at the output, it looks like maybe just a slash vs backslash again, > so maybe it can be made to match on Windows If it's just a slash issue, then applying copious amounts of regexes (e.g. `{{/}}` to match both) may help. For skipping smaller sections of tests, you can apply `%if !system-windows %{ ... %}` around a bit of the RUN commands, see f5a93c5f2a4d0916c975bbf028768d58a29b6b73 for an example of that. If it's a bigger issue and relevant to most of a test file, it may be worth splitting into a separate file which can be marked `// UNSUPPORTED: system-windows`. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: I'm fighting the tests on Windows - the hurd test I started from had `// UNSUPPORTED: system-windows` at the top, probably because they weren't interested in messing around with backslashes and .exe extensions. I don't know if the cross test will work right for the path to the cross as, is there some way to annotate just one test in the file as unsupported on Windows? https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: I tried to exercise both the -msys and -cygwin directory structures in these tests - I alternated between i686 and x86_64 in the normal and cross basic trees. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/brad0 edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH 1/2] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(D
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: > > I don't have experience with llvm's test suite though, but if it's just a > > matter of adding additional cases to existing tests or maybe copying some > > existing tests I might be OK figuring it out. > > Yeah it's usually not that hard to figure out. A couple general pointers: > > * You can run all tests with `ninja check-clang` or so, but if working on one > single test, it's much faster to run e.g. `bin/llvm-lit -a > ../clang/test/Driver/mytest.c` to only run one single test, or `bin/llvm-lit > -sv ../clang/test/Driver` to run one subdirectory > * The general philosophy of tests within Clang and LLVM is to test the > minimal scope at each level. Initially, it may feel more intuitive to test > the driver by e.g. actually trying to compile something, but such a test only > works if you actually have the full environment available. But in Clang/LLVM, > as many tests as possible are desired to be runnable on any host, without any > dependencies. So e.g. a Clang codegen test takes a minimal selfcontained `.c` > input and produces LLVM IR (which can be done on any host), a Clang driver > test mostly runs with `-###` to check which `-cc1` command flags would be > prouduced for that. If necessary, it may set up a mock sysroot and try to > make Clang use that; some such tests rely on symlinking (and such tests may > only be usable on Unix or other systems where symlinks generally are usable) > - some of the mingw driver tests do that. > * As this is a new driver, I guess it'd be fine to just start out with some > very minimal test, trying to compile, `clang -### -c ...` and link `clang > -### foo.o -o foo.exe` and inspect some minimal detail in them. > * As a general rule, in Clang/LLVM, every functional change must be > accompanied by a test change/update to cover what is being changed. (As an > exception, if the test relies on tricky environmental factors it may be ok to > go without a testcase, but if possible to mock the environment, that's > preferred.) I figure I'll try starting with Hurd again, since I started with their ToolChain cpp :grin:. It looks like a pretty simple Inputs/basic_cygwin_tree and maybe Inputs/basic_cross_cygwin_tree would be in order. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -180,35 +170,14 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, return false; } -void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, - StringRef Arch, - StringRef Version) { - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", - CXXSystem, false); -} - void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { if (!ShouldAddDefaultIncludePaths(triple)) llvm_unreachable("Include management is handled in the driver."); - llvm::Triple::OSType os = triple.getOS(); - if (HSOpts.UseStandardSystemIncludes) { -switch (os) { -case llvm::Triple::Win32: - if (triple.getEnvironment() != llvm::Triple::Cygnus) -break; - [[fallthrough]]; -default: - // FIXME: temporary hack: hard-coded paths. - AddPath("/usr/local/include", System, false); - break; -} +// FIXME: temporary hack: hard-coded paths. brad0 wrote: > Won't this change here cause win32-non-cygwin (e.g. mingw) to end up adding > this path, where it wasn't added before? No, adding Win32 to ShouldAddDefaultIncludePaths means not utilizing this code path. > Then again, it looks like the removed switch below indicates that we never > hit the win32 case here before, except for cygwin. Correct. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: > I see that that patch also contains some similar cleanups to > InitHeaderSearch.cpp - do these patches share some common ancestry (e.g. some > cygwin specific clang patchsets that have been floating around somewhere?). No, I wasn't aware of that PR, I noticed that using Generic_GCC directly wasn't ever initing GCCInstallation member, and figured I had to add a derived class to do that to get rid of some of the "hacks" patches injecting paths elsewhere. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
mstorsjo wrote: > To me, the general theory is that Cygwin is more UNIXy than Windowsy, so I > based this off of actually the Hurd.h/cpp (as it had pretty limited amounts > of special cases). Sounds like a reasonable guess. In practice it's probably somewhere inbetween, and which side ends up dominating is hard to guess beforehand, but considering it mostly UNIXy is probably reasonable, and sticking close to the existing `Generic_GCC` case makes it much easier to review as a gradual change, rather than a full from-scratch implementation. > It looks to me like the #74933 PR followed the from-scratch ToolChain idea, > and that probably accounts for why it was much more code. I can look at that > more closely and see if there's anything I'm missing. Thanks, that's appeciated, although probably not strictly needed at this point. And if there are other valuable nuggets in there, we can probably add them as incremental changes on top here. > I believe cygwin target testing is very lacking/non-existent. Yes, definitely. And your and @mati865's effort here is very very much appreciated! > I don't have experience with llvm's test suite though, but if it's just a > matter of adding additional cases to existing tests or maybe copying some > existing tests I might be OK figuring it out. Yeah it's usually not that hard to figure out. A couple general pointers: - You can run all tests with `ninja check-clang` or so, but if working on one single test, it's much faster to run e.g. `bin/llvm-lit -a ../clang/test/Driver/mytest.c` to only run one single test, or `bin/llvm-lit -sv ../clang/test/Driver` to run one subdirectory - The general philosophy of tests within Clang and LLVM is to test the minimal scope at each level. Initially, it may feel more intuitive to test the driver by e.g. actually trying to compile something, but such a test only works if you actually have the full environment available. But in Clang/LLVM, as many tests as possible are desired to be runnable on any host, without any dependencies. So e.g. a Clang codegen test takes a minimal selfcontained `.c` input and produces LLVM IR (which can be done on any host), a Clang driver test mostly runs with `-###` to check which `-cc1` command flags would be prouduced for that. If necessary, it may set up a mock sysroot and try to make Clang use that; some such tests rely on symlinking (and such tests may only be usable on Unix or other systems where symlinks generally are usable) - some of the mingw driver tests do that. - As this is a new driver, I guess it'd be fine to just start out with some very minimal test, trying to compile, `clang -### -c ...` and link `clang -### foo.o -o foo.exe` and inspect some minimal detail in them. - As a general rule, in Clang/LLVM, every functional change must be accompanied by a test change/update to cover what is being changed. (As an exception, if the test relies on tricky environmental factors it may be ok to go without a testcase, but if possible to mock the environment, that's preferred.) https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: To me, the general theory is that Cygwin is more UNIXy than Windowsy, so I based this off of actually the Hurd.h/cpp (as it had pretty limited amounts of special cases). It looks to me like the #74933 PR followed the from-scratch ToolChain idea, and that probably accounts for why it was much more code. I can look at that more closely and see if there's anything I'm missing. I believe cygwin target testing is very lacking/non-existent. I don't have experience with llvm's test suite though, but if it's just a matter of adding additional cases to existing tests or maybe copying some existing tests I might be OK figuring it out. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -180,35 +170,14 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, return false; } -void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, - StringRef Arch, - StringRef Version) { - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", - CXXSystem, false); -} - void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { if (!ShouldAddDefaultIncludePaths(triple)) llvm_unreachable("Include management is handled in the driver."); - llvm::Triple::OSType os = triple.getOS(); - if (HSOpts.UseStandardSystemIncludes) { -switch (os) { -case llvm::Triple::Win32: - if (triple.getEnvironment() != llvm::Triple::Cygnus) -break; - [[fallthrough]]; -default: - // FIXME: temporary hack: hard-coded paths. - AddPath("/usr/local/include", System, false); - break; -} +// FIXME: temporary hack: hard-coded paths. jeremyd2019 wrote: It appears to me that this code is some legacy cruft left behind after all other targets were refactored to driver ToolChains, and all that was left was some Cygwin hackery that I now removed. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
mstorsjo wrote: Oh, also, what's the tradeoff between having this extend the `Generic_GCC` driver, vs doing a plain from-scratch implementation that extents the `ToolChain` base class like the `MinGW` driver does? I guess that it's a smaller step to just tweak `Generic_GCC`, not requiring all the same amount of boilerplate, potentially? https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
mstorsjo wrote: Adding @MaskRay as the Clang Driver maintainer. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo edited https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
@@ -180,35 +170,14 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, return false; } -void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, - StringRef Arch, - StringRef Version) { - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, - CXXSystem, false); - AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", - CXXSystem, false); -} - void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { if (!ShouldAddDefaultIncludePaths(triple)) llvm_unreachable("Include management is handled in the driver."); - llvm::Triple::OSType os = triple.getOS(); - if (HSOpts.UseStandardSystemIncludes) { -switch (os) { -case llvm::Triple::Win32: - if (triple.getEnvironment() != llvm::Triple::Cygnus) -break; - [[fallthrough]]; -default: - // FIXME: temporary hack: hard-coded paths. - AddPath("/usr/local/include", System, false); - break; -} +// FIXME: temporary hack: hard-coded paths. mstorsjo wrote: Won't this change here cause win32-non-cygwin (e.g. mingw) to end up adding this path, where it wasn't added before? Then again, it looks like the removed switch below indicates that we never hit the win32 case here before, except for cygwin. Is it the case that these files only were used for the Generic_GCC driver, while any other specific driver don't hit these codepaths at all? https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/mstorsjo commented: What test coverage do we have for targeting cygwin with clang right now? Do we have enough tests to make sure that this is a refactoring, so things work mostly like before, but with better structured code? If not, we should probably add some sort of minimal tests for this driver while adding it. FYI, as LLVM uses the "squash and merge" merge method, anything in the PR description ends up in the commit message (unless edited by whoever merges it, when merging), so for PRs it may be good to leave more discussion-like comments to a separate post after opening the PR. There was an earlier attempt to add a cygwin specific driver before, see https://github.com/llvm/llvm-project/pull/74933. That one didn't really go far though, but it seems to have much more code in the driver implementation. I guess this variant is simpler; where this is mostly a refactoring so far, making it easier to deal with. Then we can review incremental improvements on top of it. I see that that patch also contains some similar cleanups to InitHeaderSearch.cpp - do these patches share some common ancestry (e.g. some cygwin specific clang patchsets that have been floating around somewhere?). https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 949ec2a683faf53652b21a4c90206befa498bf4e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..c310f096a5d74 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations --*- C++ -*-===// +// +// 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(Drive
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From df6e55b21f2eca0d62c9c306fd0d00280f578861 Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..a7f8650331cef --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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(DriverAr
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 95196a22017a40fb3392661a0d0635bab81c825e Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 109 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 174 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..a7f8650331cef --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,109 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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(DriverAr
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From de135831a6c21ae48863f8867107753f865f29f2 Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 110 + clang/lib/Driver/ToolChains/Cygwin.h | 36 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 +-- 6 files changed, 175 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..ecc9d92f31b52 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,110 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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(DriverA
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: Ooh, I just noticed the "hack-cygwin-use-proper-EH-model.patch" patch would also be properly situated in the ToolChains/Cygwin.cpp file. https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
jeremyd2019 wrote: I don't have rights to push/merge. (I seem to remember being asked to mention this in the past) https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
mati865 wrote: So this is basically `hack: dynamically resolve G++ include dir` and `hack: add system search paths` from https://github.com/mati865/llvm-project/commits/cygwin-more-fixes/ but done the proper way. It will take a few more changes to get everything working, but this is a good start. LGTM https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 created https://github.com/llvm/llvm-project/pull/135691 Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp This is an outgrowth of @mati865's efforts to get a Cygwin target working again (#134494 for example). /cc @mstorsjo >From a67fa8d6346b75faae08562e4752a0dc0b27c4bb Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 102 + clang/lib/Driver/ToolChains/Cygwin.h | 33 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 87 + 6 files changed, 165 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..57a8815f9e4cc --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,102 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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); +} + +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(DriverA
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (jeremyd2019) Changes Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp This is an outgrowth of @mati865's efforts to get a Cygwin target working again (#134494 for example). /cc @mstorsjo --- Full diff: https://github.com/llvm/llvm-project/pull/135691.diff 6 Files Affected: - (modified) clang/lib/Driver/CMakeLists.txt (+1) - (modified) clang/lib/Driver/Driver.cpp (+4) - (added) clang/lib/Driver/ToolChains/Cygwin.cpp (+102) - (added) clang/lib/Driver/ToolChains/Cygwin.h (+33) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+21) - (modified) clang/lib/Lex/InitHeaderSearch.cpp (+4-83) ``diff diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..57a8815f9e4cc --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,102 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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); +} + +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 Dirs; +CIncludeDirs.split(Dirs, ":"); +for (StringRef Dir :
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 7bb8bc392d2ea0a0deabb69117da3305ac3137af Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 102 + clang/lib/Driver/ToolChains/Cygwin.h | 33 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 86 + 6 files changed, 164 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..62ac12923a9b9 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,102 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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); +} + +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 confi
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
https://github.com/jeremyd2019 updated https://github.com/llvm/llvm-project/pull/135691 >From 7f71c0f13661ea7ad1d6798e790463eedf1bb225 Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 14 Apr 2025 10:37:59 -0700 Subject: [PATCH] [Clang] [Driver] add a Cygwin ToolChain Add a new Cygwin toolchain that just goes through the motions to initialize the Generic_GCC base properly. This allows removing some old, almost certainly wrong hard-coded paths from Lex/InitHeaderSearch.cpp Signed-off-by: Jeremy Drake --- clang/lib/Driver/CMakeLists.txt| 1 + clang/lib/Driver/Driver.cpp| 4 + clang/lib/Driver/ToolChains/Cygwin.cpp | 102 + clang/lib/Driver/ToolChains/Cygwin.h | 33 clang/lib/Driver/ToolChains/Gnu.cpp| 21 + clang/lib/Lex/InitHeaderSearch.cpp | 87 + 6 files changed, 165 insertions(+), 83 deletions(-) create mode 100644 clang/lib/Driver/ToolChains/Cygwin.cpp create mode 100644 clang/lib/Driver/ToolChains/Cygwin.h diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 5bdb6614389cf..e72525e99d517 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -51,6 +51,7 @@ add_clang_library(clangDriver ToolChains/CrossWindows.cpp ToolChains/CSKYToolChain.cpp ToolChains/Cuda.cpp + ToolChains/Cygwin.cpp ToolChains/Darwin.cpp ToolChains/DragonFly.cpp ToolChains/Flang.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 90d8e823d1d02..9b2264bbc9eaa 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -17,6 +17,7 @@ #include "ToolChains/Clang.h" #include "ToolChains/CrossWindows.h" #include "ToolChains/Cuda.h" +#include "ToolChains/Cygwin.h" #include "ToolChains/Darwin.h" #include "ToolChains/DragonFly.h" #include "ToolChains/FreeBSD.h" @@ -6849,6 +6850,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::GNU: TC = std::make_unique(*this, Target, Args); break; + case llvm::Triple::Cygnus: +TC = std::make_unique(*this, Target, Args); +break; case llvm::Triple::Itanium: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp new file mode 100644 index 0..62ac12923a9b9 --- /dev/null +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -0,0 +1,102 @@ +//===--- Cygwin.cpp - Cygwin ToolChain Implementations *- C++ -*-===// +// +// 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); +} + +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 confi
[clang] [Clang] [Driver] add a Cygwin ToolChain (PR #135691)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/lib/Driver/ToolChains/Cygwin.cpp clang/lib/Driver/ToolChains/Cygwin.h clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Gnu.cpp clang/lib/Lex/InitHeaderSearch.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp index 57a8815f9..62ac12923 100644 --- a/clang/lib/Driver/ToolChains/Cygwin.cpp +++ b/clang/lib/Driver/ToolChains/Cygwin.cpp @@ -47,7 +47,7 @@ Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) } void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - ArgStringList &CC1Args) const { + ArgStringList &CC1Args) const { const Driver &D = getDriver(); std::string SysRoot = computeSysRoot(); `` https://github.com/llvm/llvm-project/pull/135691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits