Skip to content

Commit

Permalink
Merge pull request #297 from h-vetinari/pp
Browse files Browse the repository at this point in the history
package `$TRIPLE-clang-cpp` symlink on linux
  • Loading branch information
h-vetinari authored Jul 20, 2024
2 parents e0b8ef8 + b54747c commit e79d1b0
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .ci_support/linux_64_.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
c_stdlib:
- sysroot
c_stdlib_version:
- '2.12'
- '2.17'
cdt_name:
- cos6
- cos7
channel_sources:
- conda-forge
channel_targets:
Expand Down
1 change: 0 additions & 1 deletion .scripts/build_steps.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions recipe/install_clang_symlinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if [[ "$target_platform" == "linux-"* ]]; then
source ${RECIPE_DIR}/get_cpu_triplet.sh
CHOST=$(get_triplet $target_platform)
ln -s "${PREFIX}/bin/clang-${maj_version}" "${PREFIX}/bin/${CHOST}-clang"
ln -s "${PREFIX}/bin/clang-${maj_version}" "${PREFIX}/bin/${CHOST}-clang-cpp"
# for background, see comment in install_clangxx.sh
echo "--sysroot ${PREFIX}/${CHOST}/sysroot" >> ${PREFIX}/bin/${CHOST}-clang.cfg
echo "--sysroot ${PREFIX}/${CHOST}/sysroot" >> ${PREFIX}/bin/${CHOST}-clang-cpp.cfg
fi
13 changes: 12 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set version = "18.1.8" %}
{% set major_version = version.split(".")[0] %}
{% set build_number = 0 %}
{% set build_number = 1 %}

# always includes minor as of v18, see https://github.com/llvm/llvm-project/issues/76273
{% set minor_aware_ext = major_version ~ "." ~ version.split(".")[1] %}
Expand Down Expand Up @@ -430,6 +430,13 @@ outputs:
- clang --version
- clang-cl --version
- clang-cpp --version
# on linux, $TRIPLE-clang{,-cpp} are in this package
- x86_64-conda-linux-gnu-clang --version # [linux64]
- x86_64-conda-linux-gnu-clang-cpp --version # [linux64]
- aarch64-conda-linux-gnu-clang --version # [aarch64]
- aarch64-conda-linux-gnu-clang-cpp --version # [aarch64]
- powerpc64le-conda-linux-gnu-clang --version # [ppc64le]
- powerpc64le-conda-linux-gnu-clang-cpp --version # [ppc64le]

- name: clangxx
script: install_clangxx.sh # [unix]
Expand Down Expand Up @@ -466,6 +473,10 @@ outputs:
- unset CONDA_BUILD_SYSROOT # [unix]
- set "CONDA_BUILD_SYSROOT=" # [win]
- clang++ -v -c mytest.cxx
# on linux, $TRIPLE-clang++ is in this package
- x86_64-conda-linux-gnu-clang++ --version # [linux64]
- aarch64-conda-linux-gnu-clang++ --version # [aarch64]
- powerpc64le-conda-linux-gnu-clang++ --version # [ppc64le]

- name: clang-format-{{ major_version }}
script: install_clang_format.sh # [unix]
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0001-Find-conda-gcc-installation.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From a390f0067a5828a36dd06a06eafc500c9f4f80a1 Mon Sep 17 00:00:00 2001
From 3a0eaafcf3ec4889e035f4a08d319348b58c0952 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Mon, 8 Apr 2019 16:20:03 -0500
Subject: [PATCH 1/9] Find conda gcc installation
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0002-Fix-sysroot-detection-for-linux.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From d34673b8220a9239d6f0a5ce03be793bd428a387 Mon Sep 17 00:00:00 2001
From 748e0e2c13eb568d52ce18f75d578e38b52b1910 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Mon, 8 Apr 2019 16:32:17 -0500
Subject: [PATCH 2/9] Fix sysroot detection for linux
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
From 585a98186e296ad736e199886cf2b3e38678d5c0 Mon Sep 17 00:00:00 2001
From 631014f6a95f535410619a2a6e4a878d5dbbc9da Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sat, 25 Aug 2018 09:20:04 -0500
Subject: [PATCH 3/9] clang: add conda specific env var CONDA_BUILD_SYSROOT

And also improve logic for finding the macos sysroot for conda

Co-authored-by: Chris Burr <christopher.burr@cern.ch>
Co-authored-by: Vincenzo Eduardo Padulano <v.e.padulano@gmail.com>
Co-authored-by: Isuru Fernando <isuruf@gmail.com>
---
clang/lib/Driver/Driver.cpp | 5 +++++
clang/lib/Lex/InitHeaderSearch.cpp | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)
clang/lib/Driver/Driver.cpp | 5 ++
clang/lib/Driver/ToolChains/Darwin.cpp | 76 +++++++++++++++++++++++++-
clang/lib/Lex/InitHeaderSearch.cpp | 6 +-
3 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93cddf742d52..00d0466a5de2 100644
Expand All @@ -24,6 +30,107 @@ index 93cddf742d52..00d0466a5de2 100644
if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
SysRoot = A->getValue();
if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index fae8ad1a958a..2d5295719c58 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -29,6 +29,18 @@
#include "llvm/TargetParser/Triple.h"
#include <cstdlib> // ::getenv

+// Extra includes for conda patch
+#include <cstdio>
+#include <memory>
+#include <optional>
+#include <string>
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Program.h"
+
using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang::driver::toolchains;
@@ -2186,15 +2198,75 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
if (!getVFS().exists(A->getValue()))
getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
} else {
+ std::string foundSDKPath = "/";
+ std::string prefixToTry = "/";
+
if (char *env = ::getenv("SDKROOT")) {
// We only use this value as the default if it is an absolute path,
// exists, and it is not the root path.
if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
StringRef(env) != "/") {
- Args.append(Args.MakeSeparateArg(
- nullptr, Opts.getOption(options::OPT_isysroot), env));
+ foundSDKPath = std::string(env);
+ }
+ }
+
+ if (foundSDKPath == "/") {
+ if (char *env = ::getenv("CONDA_BUILD_SYSROOT")) {
+ // We only use this value as the default if it is an absolute path,
+ // exists, and it is not the root path.
+ if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
+ StringRef(env) != "/") {
+ foundSDKPath = std::string(env);
+ }
}
}
+
+ // If the SDK is not found by now and it's not inside /, our only choice
+ // is to fail or ask Apple CLI utilities for help
+ if (foundSDKPath == "/" && !getVFS().exists("/usr/include/sys/types.h")) {
+
+ auto pathFromExecutable = [](llvm::ArrayRef<llvm::StringRef> Argv)
+ -> std::optional<std::string> {
+ // Inspired by clang-tools-extra/clangd/CompileCommands.cpp
+ auto Exe = llvm::sys::findProgramByName(Argv[0]);
+ if (!Exe) {
+ return std::nullopt;
+ }
+ llvm::SmallString<64> OutFile;
+ llvm::sys::fs::createTemporaryFile("darwin-adddeploymenttarget", "",
+ OutFile);
+ llvm::FileRemover OutRemover(OutFile);
+ std::optional<llvm::StringRef> Redirects[3] = {
+ /*stdin=*/{""}, /*stdout=*/{OutFile.str()}, /*stderr=*/{""}};
+ int Ret = llvm::sys::ExecuteAndWait(*Exe, Argv,
+ /*Env=*/std::nullopt, Redirects,
+ /*SecondsToWait=*/10);
+ if (Ret != 0) {
+ return std::nullopt;
+ }
+
+ auto Buf = llvm::MemoryBuffer::getFile(OutFile);
+ if (!Buf) {
+ return std::nullopt;
+ }
+ llvm::StringRef Path = Buf->get()->getBuffer().trim();
+ if (Path.empty()) {
+ return std::nullopt;
+ }
+ return Path.str();
+ };
+
+ auto XcrunPath = pathFromExecutable({"xcrun", "--show-sdk-path"});
+ if (foundSDKPath == "/" && XcrunPath &&
+ getVFS().exists(XcrunPath.value() + "/usr/include/sys/types.h")) {
+ foundSDKPath = XcrunPath.value();
+ }
+ }
+
+ if (foundSDKPath != "/") {
+ Args.append(Args.MakeSeparateArg(
+ nullptr, Opts.getOption(options::OPT_isysroot), foundSDKPath));
+ }
}

// Read the SDKSettings.json file for more information, like the SDK version
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index 2218db15013d..d05cfa38e4fb 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From aa9600567468405f86135bbbe58b3ce869154fab Mon Sep 17 00:00:00 2001
From 20a563a3181a1b1eebb78d769c9ca0213e37cb80 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Wed, 30 Aug 2017 20:01:49 +0100
Subject: [PATCH 4/9] Fix normalizeProgramName()'s handling of dots outside of
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0005-Set-VERSION-in-osx-as-well.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From c8cafc369b349f48160c85b414a9872f8235f67c Mon Sep 17 00:00:00 2001
From 0357a1816f76c0ae2ea6251fe491653fd3613266 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Sat, 27 Jul 2019 11:55:23 -0500
Subject: [PATCH 5/9] Set VERSION in osx as well
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0006-Fix-crosscompiling-LLVM-tools.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 4d5ac3c2a2261ef80bc06669afb64b84be20c21b Mon Sep 17 00:00:00 2001
From 08cfe1706e6eb0d8a5a9c88a0ecce0b7f1b4f906 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Tue, 11 May 2021 15:08:13 +0200
Subject: [PATCH 6/9] Fix crosscompiling LLVM tools
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From c20486aa9cde575aba207a20bc4cea402f783132 Mon Sep 17 00:00:00 2001
From 93c3a2c85af6da6d19e7e59a1bb202808c6b7671 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
Date: Thu, 14 Apr 2022 11:57:00 +1100
Subject: [PATCH 7/9] set libclang SOVERSION unconditionally
Expand Down
6 changes: 3 additions & 3 deletions recipe/patches/0008-Make-PIE-default-on-macOS-too.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 1971f81eb0c68dc4b57b2a734c4a5916f6250be4 Mon Sep 17 00:00:00 2001
From 78108c49ab2f571f7c2825427793d98a334d45a7 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Thu, 28 Dec 2023 19:32:19 +0530
Subject: [PATCH 8/9] Make PIE default on macOS too.
Expand All @@ -9,10 +9,10 @@ This is the default for Linux from LLVM-15
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index fae8ad1a958a..565fdbd6a4d6 100644
index 2d5295719c58..4223701f4539 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3127,7 +3127,7 @@ bool Darwin::SupportsEmbeddedBitcode() const {
@@ -3199,7 +3199,7 @@ bool Darwin::SupportsEmbeddedBitcode() const {

bool MachO::isPICDefault() const { return true; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 04615fd6f04ffa5ca7d0f0a1310804167a5499b5 Mon Sep 17 00:00:00 2001
From 90ff366749dc09eae1bc69e00afd91e6db05ceee Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Mon, 11 Mar 2024 14:03:12 -0500
Subject: [PATCH 9/9] Find ROCm device library in conda layout
Expand Down

0 comments on commit e79d1b0

Please sign in to comment.