diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 51cb90dd76..09154914d9 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -35,7 +35,7 @@ jobs: run: | python -m cibuildwheel --output-dir wheelhouse env: - CIBW_ENVIRONMENT: "PYBAMM_USE_VCPKG=ON VCPKG_ROOT_DIR=$cd/vcpkg VCPKG_DEFAULT_TRIPLET=x64-windows-static VCPKG_FEATURE_FLAGS=manifests,registries CMAKE_GENERATOR=\"Visual Studio 17 2022\" CMAKE_GENERATOR_PLATFORM=x64" + CIBW_ENVIRONMENT: "PYBAMM_USE_VCPKG=ON VCPKG_ROOT_DIR=$cd/vcpkg VCPKG_DEFAULT_TRIPLET=x64-windows-static-md VCPKG_FEATURE_FLAGS=manifests,registries CMAKE_GENERATOR=\"Visual Studio 17 2022\" CMAKE_GENERATOR_PLATFORM=x64" CIBW_ARCHS: "AMD64" - uses: actions/upload-artifact@v2 @@ -74,7 +74,11 @@ jobs: run: python -m cibuildwheel --output-dir wheelhouse env: CIBW_BEFORE_ALL_LINUX: "bash build_manylinux_wheels/install_sundials.sh 5.8.1 5.7.0" - CIBW_BEFORE_BUILD: "python -m pip install cmake casadi numpy" + CIBW_BEFORE_BUILD_LINUX: "python -m pip install cmake casadi numpy" + CIBW_BEFORE_BUILD_MACOS: "python -m pip install cmake casadi numpy && python scripts/fix_casadi_rpath_mac.py" + # got error "re.error: multiple repeat at position 104" on python 3.7 when --require-archs added, so remove + # it for mac + CIBW_REPAIR_WHEEL_COMMAND_MACOS: "delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}" CIBW_SKIP: pp* - uses: actions/upload-artifact@v2 diff --git a/scripts/fix_casadi_rpath_mac.py b/scripts/fix_casadi_rpath_mac.py new file mode 100644 index 0000000000..73657bfc31 --- /dev/null +++ b/scripts/fix_casadi_rpath_mac.py @@ -0,0 +1,36 @@ +""" +Removes the rpath from libcasadi.dylib in the casadi python install +and uses a fixed path + +Used when building the wheels for macos +""" +import casadi +import os +import subprocess + +casadi_dir = casadi.__path__[0] +print('Removing rpath references in python casadi install at', casadi_dir) + +libcpp_name = "libc++.1.dylib" +libcppabi_name = "libc++abi.dylib" +libcasadi_name = "libcasadi.dylib" +install_name_tool_args = [ + "-change", + os.path.join("@rpath", libcpp_name), + os.path.join(casadi_dir, libcpp_name), + os.path.join(casadi_dir, libcasadi_name), +] +subprocess.run(["otool"] + ["-L", os.path.join(casadi_dir, libcasadi_name)]) +print(' '.join(["install_name_tool"] + install_name_tool_args)) +subprocess.run(["install_name_tool"] + install_name_tool_args) +subprocess.run(["otool"] + ["-L", os.path.join(casadi_dir, libcasadi_name)]) +install_name_tool_args = [ + "-change", + os.path.join("@rpath", libcppabi_name), + os.path.join(casadi_dir, libcppabi_name), + os.path.join(casadi_dir, libcpp_name), +] +subprocess.run(["otool"] + ["-L", os.path.join(casadi_dir, libcpp_name)]) +print(' '.join(["install_name_tool"] + install_name_tool_args)) +subprocess.run(["install_name_tool"] + install_name_tool_args) +subprocess.run(["otool"] + ["-L", os.path.join(casadi_dir, libcpp_name)]) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index d13ca52088..756c42aef8 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -106,6 +106,8 @@ def download_extract_library(url, download_dir): "-DKLU_INCLUDE_DIR={}".format(KLU_INCLUDE_DIR), "-DKLU_LIBRARY_DIR={}".format(KLU_LIBRARY_DIR), "-DCMAKE_INSTALL_PREFIX=" + install_dir, + # on mac use fixed paths rather than rpath + "-DCMAKE_INSTALL_NAME_DIR=" + KLU_LIBRARY_DIR, ] # SUNDIALS are built within download_dir 'build_sundials' in the PyBaMM root diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 378b18f6c3..ecdff5f79d 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -13,7 +13,7 @@ { "kind": "git", "repository": "https://github.com/pybamm-team/casadi-vcpkg-registry.git", - "baseline": "c44b0b834404dea4af79b8bc621ac513aefbd53d", + "baseline": "70f49f3c22fee4874fb8a36ef1a559f2c185ef1f", "packages": [ "casadi" ] } ]