From 4e6ea0f78112d794b60d46c6be5e4e564165749a Mon Sep 17 00:00:00 2001 From: Vincent Traag Date: Fri, 12 Jul 2024 13:41:34 +0200 Subject: [PATCH] CI: Change build using external igraph --- .github/workflows/build.yml | 16 +++++----- .gitmodules | 3 -- scripts/build_igraph.bat | 63 +++++++++++++++++++++++++++++++++++++ scripts/build_igraph.sh | 61 +++++++++++++++++++++++++++++++++++ setup.py | 2 ++ vendor/source/igraph | 1 - 6 files changed, 134 insertions(+), 12 deletions(-) delete mode 100644 .gitmodules create mode 100644 scripts/build_igraph.bat create mode 100644 scripts/build_igraph.sh delete mode 160000 vendor/source/igraph diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b86dc0b30..34f9e0636 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,7 @@ jobs: - name: Build wheels (manylinux) uses: pypa/cibuildwheel@v2.19.2 env: - CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && scripts/build_igraph.sh" CIBW_BUILD: "*-manylinux_${{ matrix.wheel_arch }}" # Skip tests for Python 3.10 onwards because SciPy does not have # 32-bit wheels for Linux @@ -41,7 +41,7 @@ jobs: - name: Build wheels (musllinux) uses: pypa/cibuildwheel@v2.19.2 env: - CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && scripts/build_igraph.sh" CIBW_BUILD: "*-musllinux_${{ matrix.wheel_arch }}" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" @@ -66,7 +66,7 @@ jobs: - name: Build wheels (manylinux) uses: pypa/cibuildwheel@v2.19.2 env: - CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && scripts/build_igraph.sh" CIBW_ARCHS_LINUX: aarch64 CIBW_BUILD: "*-manylinux_aarch64" @@ -91,7 +91,7 @@ jobs: - name: Build wheels (musllinux) uses: pypa/cibuildwheel@v2.19.2 env: - CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && scripts/build_igraph.sh" CIBW_ARCHS_LINUX: aarch64 CIBW_BUILD: "*-musllinux_aarch64" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" @@ -159,7 +159,7 @@ jobs: uses: pypa/cibuildwheel@v2.19.2 env: CIBW_ARCHS_MACOS: "${{ matrix.wheel_arch }}" - CIBW_BEFORE_BUILD: "pip install -U setuptools && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "pip install -U setuptools && scripts/build_igraph.sh" CIBW_ENVIRONMENT: "LDFLAGS=-L$HOME/local/lib" IGRAPH_CMAKE_EXTRA_ARGS: -DCMAKE_OSX_ARCHITECTURES=${{ matrix.cmake_arch }} ${{ matrix.cmake_extra_args }} -DCMAKE_PREFIX_PATH=$HOME/local @@ -258,7 +258,7 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.19.2 env: - CIBW_BEFORE_BUILD: "pip install -U setuptools && python setup.py build_c_core" + CIBW_BEFORE_BUILD: "pip install -U setuptools && scripts/build_igraph.bat" CIBW_BUILD: "*-${{ matrix.wheel_arch }}" CIBW_TEST_COMMAND: "cd /d {project} && pip install --prefer-binary \".[test]\" && python -m pytest tests" # Skip tests for Python 3.10 onwards because SciPy does not have @@ -303,7 +303,7 @@ jobs: - name: Build sdist run: | - python setup.py build_c_core + scripts/build_igraph.sh python setup.py sdist python setup.py install @@ -356,7 +356,7 @@ jobs: env: IGRAPH_USE_SANITIZERS: 1 run: | - python setup.py build_c_core + scripts/build_igraph.sh - name: Build and install Python extension env: diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index bb3f72ea4..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "vendor/source/igraph"] - path = vendor/source/igraph - url = https://github.com/igraph/igraph diff --git a/scripts/build_igraph.bat b/scripts/build_igraph.bat new file mode 100644 index 000000000..68140917c --- /dev/null +++ b/scripts/build_igraph.bat @@ -0,0 +1,63 @@ +@echo off + +set IGRAPH_VERSION=0.10.13 + +set ROOT_DIR=%cd% +echo Using root dir %ROOT_DIR% + +if not exist "%ROOT_DIR%\build-deps\src\" ( + md %ROOT_DIR%\build-deps\src +) + +cd "%ROOT_DIR%\build-deps\src" +if not exist "igraph\" ( + echo. + echo Cloning igraph into %ROOT_DIR%\build-deps\src\igraph + REM Clone repository if it does not exist yet + git clone --depth 1 --branch %IGRAPH_VERSION% https://github.com/igraph/igraph.git +) + +REM Make sure the git repository points to the correct version +echo. +echo Checking out %IGRAPH_VERSION} in ${ROOT_DIR%\build-deps\src\igraph +cd "%ROOT_DIR%\build-deps\src\igraph" +git fetch origin tag %IGRAPH_VERSION% --no-tags +git checkout %IGRAPH_VERSION% + +REM Make build directory +if not exist "%ROOT_DIR%\build-deps\build\igraph\" ( + echo. + echo Make directory %ROOT_DIR%\build-deps\build\igraph + md %ROOT_DIR%\build-deps\build\igraph +) + +REM Configure, build and install +cd "%ROOT_DIR%\build-deps\build\igraph" + +echo. +echo Configure igraph build +cmake %ROOT_DIR%\build-deps\src\igraph ^ + -DCMAKE_INSTALL_PREFIX=%ROOT_DIR%\build-deps\install\ ^ + -DBUILD_SHARED_LIBS=ON ^ + -DIGRAPH_GLPK_SUPPORT=ON ^ + -DIGRAPH_GRAPHML_SUPPORT=ON ^ + -DIGRAPH_OPENMP_SUPPORT=ON ^ + -DIGRAPH_USE_INTERNAL_BLAS=ON ^ + -DIGRAPH_USE_INTERNAL_LAPACK=ON ^ + -DIGRAPH_USE_INTERNAL_ARPACK=ON ^ + -DIGRAPH_USE_INTERNAL_GLPK=ON ^ + -DIGRAPH_USE_INTERNAL_GMP=ON ^ + -DIGRAPH_WARNINGS_AS_ERRORS=OFF ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DBUILD_TESTING=OFF ^ + %EXTRA_CMAKE_ARGS% + +echo. +echo Build igraph +cmake --build . --config Release + +echo. +echo Install igraph to %ROOT_DIR%\build-deps\install\ +cmake --build . --target install --config Release + +cd "%ROOT_DIR%" \ No newline at end of file diff --git a/scripts/build_igraph.sh b/scripts/build_igraph.sh new file mode 100644 index 000000000..9d082a40f --- /dev/null +++ b/scripts/build_igraph.sh @@ -0,0 +1,61 @@ +IGRAPH_VERSION=0.10.13 + +ROOT_DIR=`pwd` +echo "Using root dir ${ROOT_DIR}" + +# Create source directory +if [ ! -d "${ROOT_DIR}/build-deps/src" ]; then + echo "" + echo "Make directory ${ROOT_DIR}/build-deps/src" + mkdir -p ${ROOT_DIR}/build-deps/src +fi + +cd ${ROOT_DIR}/build-deps/src +if [ ! -d "igraph" ]; then + echo "" + echo "Cloning igraph into ${ROOT_DIR}/build-deps/src/igraph" + # Clone repository if it does not exist yet + git clone --branch ${IGRAPH_VERSION} https://github.com/igraph/igraph.git --single-branch +fi + +# Make sure the git repository points to the correct version +echo "" +echo "Checking out ${IGRAPH_VERSION} in ${ROOT_DIR}/build-deps/src/igraph" +cd ${ROOT_DIR}/build-deps/src/igraph +git fetch origin tag ${IGRAPH_VERSION} --no-tags +git checkout ${IGRAPH_VERSION} + +# Make build directory +if [ ! -d "${ROOT_DIR}/build-deps/build/igraph" ]; then + echo "" + echo "Make directory ${ROOT_DIR}/build-deps/build/igraph" + mkdir -p ${ROOT_DIR}/build-deps/build/igraph +fi + +# Configure, build and install +cd ${ROOT_DIR}/build-deps/build/igraph + +echo "" +echo "Configure igraph build" +cmake ${ROOT_DIR}/build-deps/src/igraph \ + -DCMAKE_INSTALL_PREFIX=${ROOT_DIR}/build-deps/install/ \ + -DBUILD_SHARED_LIBS=ON \ + -DIGRAPH_GLPK_SUPPORT=ON \ + -DIGRAPH_GRAPHML_SUPPORT=ON \ + -DIGRAPH_OPENMP_SUPPORT=ON \ + -DIGRAPH_USE_INTERNAL_BLAS=ON \ + -DIGRAPH_USE_INTERNAL_LAPACK=ON \ + -DIGRAPH_USE_INTERNAL_ARPACK=ON \ + -DIGRAPH_USE_INTERNAL_GLPK=ON \ + -DIGRAPH_USE_INTERNAL_GMP=ON \ + -DIGRAPH_WARNINGS_AS_ERRORS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + ${EXTRA_CMAKE_ARGS} + +echo "" +echo "Build igraph" +cmake --build . + +echo "" +echo "Install igraph to ${ROOT_DIR}/build-deps/install/" +cmake --build . --target install diff --git a/setup.py b/setup.py index dc0246486..d38dc5f7b 100644 --- a/setup.py +++ b/setup.py @@ -73,6 +73,8 @@ def get_tag(self): igraph_extension = Extension( "igraph._igraph", libraries=["igraph"], + include_dirs=['build-deps/install/include'], + library_dirs=['build-deps/install/lib'], sources=sources, py_limited_api=should_build_abi3_wheel, define_macros=macros, diff --git a/vendor/source/igraph b/vendor/source/igraph deleted file mode 160000 index ac22a920d..000000000 --- a/vendor/source/igraph +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ac22a920d882ec9e2bd433c55e2da2fce0ebe529