Skip to content

Commit

Permalink
does macos building work? (#134)
Browse files Browse the repository at this point in the history
* does macos building work?

* try brew install gcc

* force gcc/g++ when configuring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* clang compatible LDFLAGs

* ensure make

* try to set the path on osx correctly for make

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* satisfy clang requirements & use gnu make

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove quotes

* forgot to disable auto-ptr...

* Add wheels for MacOS

* Install extra deps for MacOS wheel

* Fix dangarous reallocs

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Chris Papageorgakis <Christos.Papageorgakis@cern.ch>
Co-authored-by: Chris Papageorgakis <chrispap95@gmail.com>
Co-authored-by: Javier Duarte <jduarte@ucsd.edu>
  • Loading branch information
5 people committed Dec 16, 2022
1 parent 0f3d3bc commit b3aead6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.7", "3.11"]
runs-on: [ubuntu-latest] # , macos-latest
runs-on: [ubuntu-latest, macos-latest]

# include:
# - python-version: pypy-3.8
Expand All @@ -51,27 +51,41 @@ jobs:

- name: Install compiler tools on macOS
if: runner.os == 'macOS'
run: brew install automake swig gmp mpfr boost
run: |
brew install make gcc automake swig gmp mpfr boost
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
- name: Install extra deps on Linux
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libboost-dev libmpfr-dev swig autoconf libtool

- name: Install package
run: python -m pip install '.[test]' -v
run: |
echo $PATH
python -m pip install '.[test]' -v
- name: Test package
run: python -m pytest -vv -rs -Wd

test_wheels:
name: Wheel on Linux
runs-on: ubuntu-latest
name: "Wheel on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install compiler tools on macOS
if: runner.os == 'macOS'
run: |
brew install make gcc automake swig gmp mpfr boost
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
- uses: pypa/cibuildwheel@v2.11.3
env:
CIBW_ARCHS: auto64
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
matrix:
python-build-version:
["cp37-*", "cp38-*", "cp39-*", "cp310-*", "cp311-*"]
os: [ubuntu-latest] # , macos-latest
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3
Expand All @@ -39,7 +39,9 @@ jobs:

- name: Install compiler tools on macOS
if: runner.os == 'macOS'
run: brew install automake
run: |
brew install make gcc automake swig gmp mpfr boost
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
- uses: pypa/cibuildwheel@v2.11.3
env:
Expand Down
28 changes: 20 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,27 @@ def build_extensions(self):
env = os.environ.copy()
env["PYTHON"] = sys.executable
env["PYTHON_INCLUDE"] = f'-I{sysconfig.get_path("include")}'
env["CXXFLAGS"] = "-O3 -Bstatic -lgmp -Bdynamic"
env["CXXFLAGS"] = "-O3 -Bstatic -lgmp -Bdynamic -std=c++17"
env["ORIGIN"] = "$ORIGIN" # if evaluated, it will still be '$ORIGIN'

args = [
f"--prefix={OUTPUT}",
"--disable-auto-ptr",
"--enable-allcxxplugins",
"--enable-cgal-header-only",
"--enable-cgal",
f"--with-cgaldir={cgal_dir}",
"--enable-swig",
"--enable-pyext",
"LDFLAGS=-Wl,-rpath=$$ORIGIN/_fastjet_core/lib:$$ORIGIN",
"LDFLAGS=-Wl,-rpath,$$ORIGIN/_fastjet_core/lib:$$ORIGIN",
]

try:
subprocess.run(
["./autogen.sh"] + args, cwd=FASTJET, env=env, check=True
["./autogen.sh"] + args,
cwd=FASTJET,
env=env,
check=True,
)
except Exception:
subprocess.run(["cat", "config.log"], cwd=FASTJET, check=True)
Expand All @@ -106,7 +110,11 @@ def build_extensions(self):
subprocess.run(["make", "install"], cwd=FASTJET, env=env, check=True)

subprocess.run(
["./configure", f"--fastjet-config={FASTJET}/fastjet-config"],
[
"./configure",
f"--fastjet-config={FASTJET}/fastjet-config",
"CXXFLAGS=-O3 -Bstatic -Bdynamic -std=c++17",
],
cwd=FASTJET_CONTRIB,
env=env,
check=True,
Expand Down Expand Up @@ -134,24 +142,28 @@ def run(self):

shutil.copytree(OUTPUT, fastjetdir / "_fastjet_core", symlinks=True)

make = "make"
if sys.platform == "darwin":
make = "gmake"

pythondir = pathlib.Path(
subprocess.check_output(
"""make -f pyinterface/Makefile --eval='print-pythondir:
f"""{make} -f Makefile --eval='print-pythondir:
\t@echo $(pythondir)
' print-pythondir""",
shell=True,
cwd=FASTJET,
cwd=FASTJET / "pyinterface",
universal_newlines=True,
).strip()
)

pyexecdir = pathlib.Path(
subprocess.check_output(
"""make -f pyinterface/Makefile --eval='print-pyexecdir:
f"""{make} -f Makefile --eval='print-pyexecdir:
\t@echo $(pyexecdir)
' print-pyexecdir""",
shell=True,
cwd=FASTJET,
cwd=FASTJET / "pyinterface",
universal_newlines=True,
).strip()
)
Expand Down
4 changes: 2 additions & 2 deletions src/_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ PYBIND11_MODULE(_ext, m) {

auto off = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor<int>::value, 1, {len+1}, {sizeof(int)}));
auto bufoff = off.request();
int *ptroff = (int *)realloc(bufoff.ptr, (len+1)*sizeof(int)+1);;
int *ptroff = (int *)bufoff.ptr;
size_t idxe = 0;
*ptroff = 0;
ptroff++;
Expand Down Expand Up @@ -2016,7 +2016,7 @@ PYBIND11_MODULE(_ext, m) {

auto off = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor<int>::value, 1, {len+1}, {sizeof(int)}));
auto bufoff = off.request();
int *ptroff = (int *)realloc(bufoff.ptr, (len+1)*sizeof(int)+1);;
int *ptroff = (int *)bufoff.ptr;
size_t idxe = 0;
*ptroff = 0;
ptroff++;
Expand Down

0 comments on commit b3aead6

Please sign in to comment.