Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether -std=c++11 can be safely added to the compiler flags #82

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ jobs:
tests:
name: tests
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
pyver: [3.7, 3.8, 3.9]
compiler: [gcc]
include:
- os: macos-latest
pyver: 3.9
compiler: clang

runs-on: "ubuntu-latest"
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
Expand All @@ -22,6 +29,8 @@ jobs:
python-version: ${{ matrix.pyver }}

- name: Install code
env:
CC: ${{ matrix.compiler }}
run: pip install -e .

- name: lint
Expand Down
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
local_tmp = "tmp"


def try_compile(cpp_code, compiler, cflags=[], lflags=[]):
def try_compile(cpp_code, compiler, cflags=[], lflags=[], c_not_cpp=False):
"""
Check if compiling some code with the given compiler and flags works
properly.
Expand All @@ -38,7 +38,7 @@ def try_compile(cpp_code, compiler, cflags=[], lflags=[]):
# tmp directory so the user can troubleshoot the problem if they were
# expecting it to work.
with tempfile.NamedTemporaryFile(
delete=False, suffix=".cpp", dir=local_tmp
delete=False, suffix=".c" if c_not_cpp else ".cpp" , dir=local_tmp
) as cpp_file:
cpp_file.write(cpp_code.encode())
cpp_name = cpp_file.name
Expand Down Expand Up @@ -81,6 +81,9 @@ def try_compile(cpp_code, compiler, cflags=[], lflags=[]):
# Don't delete files in case helpful for troubleshooting.
return False

if lflags == []:
return returncode == 0

# Link
cc = compiler.linker_so[0]
cmd = [cc] + compiler.linker_so[1:] + lflags + [o_name, "-o", exe_name]
Expand Down Expand Up @@ -111,7 +114,10 @@ def check_flags(compiler):
cflags = extra_compile_args
lflags = extra_link_args

cflags += ["-std=c++11"]
# Check whether we can safely add -std=c++11
if try_compile("int main (int argc, char **argv) { return 0; }",
compiler, ["-std=c++11"], [], c_not_cpp=True):
cflags += ["-std=c++11"]

if platform.system() == "Darwin":
# Usually Macs need this, but they might not, so try it, and only add
Expand Down