Skip to content

Instantly share code, notes, and snippets.

@cognifloyd
Created December 2, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognifloyd/2f94bebd3231a815516c4e5f364c81b5 to your computer and use it in GitHub Desktop.
Save cognifloyd/2f94bebd3231a815516c4e5f364c81b5 to your computer and use it in GitHub Desktop.
gentoo prefix darwin clang patch
This mirrors cmake-*-prefix-dirs.patch
It add EPREFIX to search paths for c/cxx headers.
It also adds EPREFIX/MacOSX.sdk to search paths for c and Frameworks.
Assumes that c++ lib and headers will be installed in the prefix.
Also, a couple of args are populated by inspecting the SDK,
so, default to EPREFIX/MacOSX.sdk when the sysroot is not specified.
(This does NOT set sysroot).
The ebuild adds an extra / at the end of EPREFIX so that it is never
an empty string.
--- a/clang/lib/Frontend/InitHeaderSearch.cpp 2020-11-30 12:53:42.000000000 -0600
+++ b/clang/lib/Frontend/InitHeaderSearch.cpp 2020-11-30 13:57:52.000000000 -0600
@@ -445,6 +445,9 @@
// All header search logic is handled in the Driver for Darwin.
if (triple.isOSDarwin()) {
if (HSOpts.UseStandardSystemIncludes) {
+ // Add Gentoo Prefix framework dirs first
+ AddPath("@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk/System/Library/Frameworks", System, true);
+ AddPath("@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk/Library/Frameworks", System, true);
// Add the default framework include paths on Darwin.
AddPath("/System/Library/Frameworks", System, true);
AddPath("/Library/Frameworks", System, true);
--- a/clang/lib/Driver/ToolChains/Darwin.cpp 2020-10-07 05:10:48.000000000 -0500
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp 2020-11-30 12:57:15.000000000 -0600
@@ -1737,9 +1737,9 @@
const ArgList &Args,
const Driver &TheDriver) {
const Arg *A = Args.getLastArg(options::OPT_isysroot);
- if (!A)
- return None;
- StringRef isysroot = A->getValue();
+ //if (!A)
+ // return None;
+ StringRef isysroot = A ? A->getValue() : "@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk";
auto SDKInfoOrErr = driver::parseDarwinSDKInfo(VFS, isysroot);
if (!SDKInfoOrErr) {
llvm::consumeError(SDKInfoOrErr.takeError());
@@ -1921,13 +1921,14 @@
return DriverArgs.getLastArgValue(options::OPT_isysroot);
if (!getDriver().SysRoot.empty())
return getDriver().SysRoot;
- return "/";
+ return "@GENTOO_PORTAGE_EPREFIX@";
}
void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const Driver &D = getDriver();
+ // Sysroot is effectively Gentoo EPREFIX when -isysroot/-sysroot is not defined
llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc);
@@ -1969,6 +1970,10 @@
SmallString<128> P(Sysroot);
llvm::sys::path::append(P, "usr", "include");
addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+ // And add <sysroot>/MacOSX.sdk/usr/include.
+ SmallString<128> Psdk(Sysroot);
+ llvm::sys::path::append(Psdk, "MacOSX.sdk", "usr", "include");
+ addExternCSystemInclude(DriverArgs, CC1Args, Psdk.str());
}
}
@@ -2017,6 +2022,7 @@
DriverArgs.hasArg(options::OPT_nostdincxx))
return;
+ // Sysroot is effectively Gentoo EPREFIX when -isysroot/-sysroot is not defined
llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
switch (GetCXXStdlibType(DriverArgs)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment