Skip to content

Commit

Permalink
Fix python workflow for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheitman committed Aug 25, 2023
1 parent 0ffc28a commit 04fd303
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 127 deletions.
251 changes: 124 additions & 127 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,130 +130,127 @@ jobs:
# if-no-files-found: warn


# FIXME
#build-macos:
# runs-on: macos-latest
# strategy:
# matrix:
# python-version: ['3.8', '3.9', '3.10']
# include:
# - python-version: 3.8
# - python-version: 3.9
# - python-version: 3.10
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}

# - name: Install LLVM and Clang
# uses: KyleMayes/install-llvm-action@v1
# with:
# version: "14.0"
# directory: ${{ runner.temp }}/llvm

# - name: Upgrade pip version
# run: |
# sudo python -m pip install -U pip

# - name: Install build package
# run: |
# sudo python -m pip install build

# - name: Download and build GMP
# run: |
# wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
# tar xvf gmp-6.2.1.tar.xz
# cd gmp-6.2.1/
# ./configure --enable-cxx
# make
# make check
# make install

# - name: Download and build Bitwuzla
# run: |
# git clone https://github.com/bitwuzla/bitwuzla.git
# cd bitwuzla
# ./contrib/setup-cadical.sh
# ./contrib/setup-btor2tools.sh
# ./contrib/setup-symfpu.sh
# ./configure.sh --shared --prefix $(pwd)/install
# cd build
# make
# make install

# - name: Download Z3
# run: |
# wget https://github.com/Z3Prover/z3/releases/download/z3-4.8.17/z3-4.8.17-x64-osx-10.16.zip
# unzip z3-4.8.17-x64-osx-10.16.zip

# - name: Install Capstone
# run: |
# wget https://github.com/aquynh/capstone/archive/4.0.2.tar.gz
# tar -xf ./4.0.2.tar.gz
# cd ./capstone-4.0.2
# bash ./make.sh
# sudo make install
# cd ../

# - name: Build Triton Python package
# run: python -m build --wheel
# env:
# PYTHON_VERSION: ${{ matrix.python-version }}
# PYTHON_LIBRARIES: ${{ env.pythonLocation }}/lib/libpython${{ matrix.python-version }}.dylib
# PYTHON_LIBRARY: ${{ env.pythonLocation }}/lib/libpython${{ matrix.python-version }}.dylib
# PYTHON_INCLUDE_DIRS: ${{ env.pythonLocation }}/include/python${{ matrix.python-version }}
# Z3_INCLUDE_DIRS: ${{ github.workspace }}/z3-4.8.17-x64-osx-10.16/include
# Z3_LIBRARIES: ${{ github.workspace }}/z3-4.8.17-x64-osx-10.16/bin/libz3.a
# CAPSTONE_INCLUDE_DIRS: /usr/local/include
# CAPSTONE_LIBRARIES: /usr/local/lib/libcapstone.a
# BITWUZLA_INTERFACE: On
# BITWUZLA_INCLUDE_DIRS: ${{ github.workspace }}/bitwuzla/install/include
# BITWUZLA_LIBRARIES: ${{ github.workspace }}/bitwuzla/install/lib/libbitwuzla.dylib
# LLVM_INTERFACE: On
# CMAKE_PREFIX_PATH: ${{env.LLVM_PATH}}

# - name: Repair wheel package (Python 3.8)
# if: ${{ matrix.python-version == '3.8' }}
# run: |
# pip install delocate
# delocate-wheel -w wheel-final -v ${{ github.workspace }}/dist/triton_library-${{ env.package-version }}-cp38-cp38-macosx_11_0_x86_64.whl

# - name: Upload Wheel packages (Python 3.8)
# uses: actions/upload-artifact@v3
# if: ${{ matrix.python-version == '3.8' }}
# with:
# name: triton_library-${{ env.package-version }}-cp38-cp38-macosx_11_0_x86_64.whl
# path: ${{ github.workspace }}/wheel-final/triton_library-${{ env.package-version }}-cp38-cp38-macosx_11_0_x86_64.whl
# if-no-files-found: warn

# - name: Repair wheel package (Python 3.9)
# if: ${{ matrix.python-version == '3.9' }}
# run: |
# pip install delocate
# delocate-wheel -w wheel-final -v ${{ github.workspace }}/dist/triton_library-${{ env.package-version }}-cp39-cp39-macosx_11_0_x86_64.whl

# - name: Upload Wheel packages (Python 3.9)
# uses: actions/upload-artifact@v3
# if: ${{ matrix.python-version == '3.9' }}
# with:
# name: triton_library-${{ env.package-version }}-cp39-cp39-macosx_11_0_x86_64.whl
# path: ${{ github.workspace }}/wheel-final/triton_library-${{ env.package-version }}-cp39-cp39-macosx_11_0_x86_64.whl
# if-no-files-found: warn

# - name: Repair wheel package (Python 3.10)
# if: ${{ matrix.python-version == '3.10' }}
# run: |
# pip install delocate
# delocate-wheel -w wheel-final -v ${{ github.workspace }}/dist/triton_library-${{ env.package-version }}-cp310-cp310-macosx_11_0_x86_64.whl

# - name: Upload Wheel packages (Python 3.10)
# uses: actions/upload-artifact@v3
# if: ${{ matrix.python-version == '3.10' }}
# with:
# name: triton_library-${{ env.package-version }}-cp310-cp310-macosx_11_0_x86_64.whl
# path: ${{ github.workspace }}/wheel-final/triton_library-${{ env.package-version }}-cp310-cp310-macosx_11_0_x86_64.whl
# if-no-files-found: warn
build-macos:
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
include:
- python-version: 3.8
pycp: cp38-cp38
- python-version: 3.9
pycp: cp39-cp39
- python-version: 3.10
pycp: cp310-cp310
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1.6.1
with:
version: "14.0"
directory: ${{ runner.temp }}/llvm

- name: Upgrade pip version
run: |
sudo python -m pip install -U pip
- name: Install build package
run: |
sudo python -m pip install build
- name: Download and build GMP
run: |
wget -q https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz
tar -xf gmp-6.2.1.tar.xz
cd gmp-6.2.1
./configure --enable-cxx
make
make install
- name: Install Ninja
run: |
brew install ninja
- name: Install Meson
run: |
python -m pip install meson
- name: Install Bitwuzla
run: |
git clone https://github.com/bitwuzla/bitwuzla.git
cd bitwuzla
git checkout -b 0.1.0 0.1.0
python ./configure.py --shared --prefix $(pwd)/install
cd build
sudo ninja install
- name: Download Z3
run: |
wget -q https://github.com/Z3Prover/z3/releases/download/z3-4.8.17/z3-4.8.17-x64-osx-10.16.zip
unzip z3-4.8.17-x64-osx-10.16.zip
- name: Install Capstone
run: |
wget -q https://github.com/aquynh/capstone/archive/4.0.2.tar.gz
tar -xf ./4.0.2.tar.gz
cd capstone-4.0.2
bash ./make.sh
sudo make install
- name: Build Triton Python package
run: python -m build --wheel --outdir wheelhouse/default_x86_64
env:
Z3_INTERFACE: On
Z3_INCLUDE_DIRS: ${{ github.workspace }}/z3-4.8.17-x64-osx-10.16/include
Z3_LIBRARIES: ${{ github.workspace }}/z3-4.8.17-x64-osx-10.16/bin/libz3.a
BITWUZLA_INTERFACE: On
BITWUZLA_INCLUDE_DIRS: ${{ github.workspace }}/bitwuzla/install/include
BITWUZLA_LIBRARIES: ${{ github.workspace }}/bitwuzla/install/lib/libbitwuzla.dylib
CAPSTONE_INCLUDE_DIRS: /usr/local/include
CAPSTONE_LIBRARIES: /usr/local/lib/libcapstone.a
LLVM_INTERFACE: On
CMAKE_PREFIX_PATH: ${{env.LLVM_PATH}}
BOOST_INTERFACE: Off

- name: Repair wheel package
run: |
pip install delocate
python ${{ github.workspace }}/src/scripts/macos/delocate-wheel-custom.py \
--verbose \
--wheel-dir wheelhouse/repaired_x86_64 \
${{ github.workspace }}/wheelhouse/default_x86_64/triton_library-${{ env.package-version }}-${{ matrix.pycp }}-macosx_12_0_x86_64.whl
- name: Test wheel package
run: |
pip install virtualenv
virtualenv test-venv
source test-venv/bin/activate
pip install ${{ github.workspace }}/wheelhouse/repaired_x86_64/triton_library-${{ env.package-version }}-${{ matrix.pycp }}-macosx_12_0_x86_64.whl
python -c "import triton"
pip install capstone
pip install lief
pip install unicorn==2.0.0
pip install z3-solver
cd ${{ github.workspace }}/src/testers
python -m unittest discover -b -v unittests
deactivate
- name: Upload wheel package
uses: actions/upload-artifact@v3
with:
name: triton_library-${{ env.package-version }}-${{ matrix.pycp }}-macosx_12_0_x86_64.whl
path: ${{ github.workspace }}/wheelhouse/repaired_x86_64/triton_library-${{ env.package-version }}-${{ matrix.pycp }}-macosx_12_0_x86_64.whl
if-no-files-found: warn
40 changes: 40 additions & 0 deletions src/scripts/macos/delocate-wheel-custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys

from delocate.cmd.delocate_wheel import main
import delocate.delocating


def filter_system_libs(libname):
copy_lib = not (libname.startswith('/usr/lib') or
libname.startswith('/System') or
libname.find('libpython') >= 0)

print(f'[filter_system_libs] libname: {libname}, copy_lib: {copy_lib}')

return copy_lib


def delocate_wheel(in_wheel,
out_wheel=None,
lib_sdir='.dylibs',
lib_filt_func=None,
copy_filt_func=filter_system_libs,
require_archs=None,
check_verbose=None,
executable_path=None,
ignore_missing=False):
return delocate.delocating.delocate_wheel(in_wheel,
out_wheel,
lib_sdir,
lib_filt_func,
copy_filt_func,
require_archs,
check_verbose,
executable_path,
ignore_missing)

delocate.cmd.delocate_wheel.delocate_wheel = delocate_wheel


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 04fd303

Please sign in to comment.