Skip to content

Commit

Permalink
Make: Override flags for any Clang compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Sep 19, 2024
1 parent 86a165c commit 7b81f6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ jobs:
python -m pip install --upgrade pip
pip install pytest pytest-repeat numpy
python -m pip install .
env:
CC: clang++ # Override to use a C++ compiler for C files
CXX: clang++
- name: Test Python
run: pytest

Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_bool_env_w_name(name: str, preference: bool) -> tuple:


is_gcc = False
is_clang = False
if is_linux:
cxx = os.environ.get("CXX")
if cxx:
Expand All @@ -36,6 +37,7 @@ def get_bool_env_w_name(name: str, preference: bool) -> tuple:
full_path = subprocess.check_output([command, cxx], text=True).strip()
compiler_name = os.path.basename(full_path)
is_gcc = ("g++" in compiler_name) and ("clang++" not in compiler_name)
is_clang = ("clang++" in compiler_name) and ("g++" not in compiler_name)
except subprocess.CalledProcessError:
pass

Expand Down Expand Up @@ -176,12 +178,12 @@ def get_bool_env_w_name(name: str, preference: bool) -> tuple:
include_dirs.append("fp16/include")


# On MacOS, `setuptools` doesn't properly use the `language="c++"` argument we pass.
# With Clang, `setuptools` doesn't properly use the `language="c++"` argument we pass.
# The right thing would be to pass down `-x c++` to the compiler, before specifying the source files.
# This nasty workaround overrides the `CC` environment variable with the `CXX` variable.
cc_compiler_variable = os.environ.get("CC")
cxx_compiler_variable = os.environ.get("CXX")
if is_macos:
if is_clang:
if cxx_compiler_variable:
os.environ["CC"] = cxx_compiler_variable

Expand Down Expand Up @@ -227,6 +229,6 @@ def get_bool_env_w_name(name: str, preference: bool) -> tuple:
)

# Reset the CC environment variable, that we overrode earlier.
if is_macos:
if is_clang:
if cxx_compiler_variable:
os.environ["CC"] = cc_compiler_variable

0 comments on commit 7b81f6c

Please sign in to comment.