Skip to content

Commit ff01191

Browse files
authored
Merge pull request #34 from jorisv/topic/minimize_build_memory
Avoid to consume too much memory while building
2 parents 323a284 + e666894 commit ff01191

14 files changed

+219
-210
lines changed

.github/workflows/ci-ubuntu-macos.yml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,39 @@ jobs:
2222
os: ["ubuntu-latest", "macos-latest"]
2323

2424
steps:
25-
- uses: actions/checkout@v2
26-
27-
- name: Checkout submodules
28-
run: |
29-
git submodule update --init
25+
- uses: actions/checkout@v4
26+
with:
27+
submodules: recursive
3028

31-
- uses: conda-incubator/setup-miniconda@v2
29+
- uses: conda-incubator/setup-miniconda@v3
3230
with:
3331
activate-environment: pycppad
3432
auto-update-conda: true
3533
environment-file: .github/workflows/conda/conda-env.yml
3634
python-version: 3.8
37-
38-
- name: Install cmake and update conda
39-
shell: bash -l {0}
40-
run: |
41-
conda activate pycppad
42-
conda install cmake -c main
35+
auto-activate-base: false
4336

4437
- name: Build PyCppAD
45-
shell: bash -l {0}
38+
shell: bash -el {0}
4639
run: |
47-
conda activate pycppad
40+
conda list
4841
echo $CONDA_PREFIX
4942
5043
mkdir build
5144
cd build
5245
53-
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPYTHON_EXECUTABLE=$(which python3) -DBUILD_WITH_CPPAD_CODEGEN_BINDINGS=ON
54-
make
55-
export CTEST_OUTPUT_ON_FAILURE=1
56-
make test
57-
make install
46+
cmake .. \
47+
-G "Ninja" \
48+
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
49+
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
50+
-DPYTHON_EXECUTABLE=$(which python3) \
51+
-DBUILD_WITH_CPPAD_CODEGEN_BINDINGS=ON
52+
ninja -j1
53+
ctest --output-on-failure -C Release -V
54+
ninja install
5855
5956
- name: Uninstall PyCppAD
60-
shell: bash -l {0}
57+
shell: bash -el {0}
6158
run: |
6259
cd build
63-
make uninstall
60+
ninja uninstall

.github/workflows/ci-windows-clang.yml

Lines changed: 0 additions & 103 deletions
This file was deleted.

.github/workflows/ci-windows-v142.yml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.github/workflows/ci-windows.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: PyCppAD CI for Windows
2+
on:
3+
pull_request:
4+
push:
5+
6+
env:
7+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
8+
BUILD_TYPE: Release
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
os: [windows-2019]
18+
compiler:
19+
- cmd: cl
20+
cppad_codegen: OFF
21+
- cmd: clang-cl
22+
cppad_codegen: ON
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
submodules: recursive
28+
29+
- uses: conda-incubator/setup-miniconda@v3
30+
with:
31+
activate-environment: pycppad
32+
auto-update-conda: true
33+
environment-file: .github/workflows/conda/conda-env.yml
34+
python-version: 3.8
35+
auto-activate-base: false
36+
37+
- name: Build PyCppAD
38+
shell: cmd /C CALL {0}
39+
run: |
40+
:: Set compiler to use.
41+
:: This must be done here and not in env since
42+
:: cxx-compiler activation script set this variable
43+
:: and is called before.
44+
set CC=${{ matrix.compiler.cmd }}
45+
set CXX=${{ matrix.compiler.cmd }}
46+
47+
:: Create build directory
48+
mkdir build
49+
pushd build
50+
51+
:: Configure
52+
cmake ^
53+
-G "Ninja" ^
54+
-DCMAKE_BUILD_TYPE=Release ^
55+
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library ^
56+
-DPYTHON_SITELIB=%CONDA_PREFIX%\Lib\site-packages ^
57+
-DPYTHON_EXECUTABLE=%CONDA_PREFIX%\python.exe ^
58+
-DBUILD_WITH_CPPAD_CODEGEN_BINDINGS=${{ matrix.compiler.cppad_codegen }} ^
59+
..
60+
61+
:: Build
62+
ninja -j1
63+
64+
:: Testing
65+
ctest --output-on-failure -C Release -V
66+
67+
:: Test Python import
68+
ninja install
69+
cd ..
70+
python -c "import pycppad"

.github/workflows/conda/conda-env-win.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/conda/conda-env.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
name: pycppad
22
channels:
33
- conda-forge
4-
- nodefaults
54
dependencies:
65
- boost
76
- eigenpy
87
- python
98
- cppad
10-
- cppadcodegen
9+
- cppadcodegen
10+
- ninja
11+
- cmake
12+
- pkg-config
13+
- ninja
14+
- cxx-compiler

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ SET(${PROJECT_NAME}_HEADERS
6767

6868
SET(${PROJECT_NAME}_SOURCES
6969
src/cppad.cpp
70+
src/expose-type-double.cpp
71+
src/expose-type-double-row-major.cpp
7072
)
7173

7274
IF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)

python/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ SET_TARGET_PROPERTIES(${PYWRAP}
3636
SUFFIX ${PYTHON_EXT_SUFFIX}
3737
OUTPUT_NAME "${PYWRAP}"
3838
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/${PROJECT_NAME}"
39+
# On Windows, shared library are treated as binary
40+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/${PROJECT_NAME}"
3941
)
4042

4143
IF(UNIX AND NOT APPLE)
@@ -47,6 +49,7 @@ INSTALL(TARGETS ${PYWRAP} DESTINATION ${${PYWRAP}_INSTALL_DIR})
4749
# --- INSTALL SCRIPTS
4850
SET(PYTHON_FILES
4951
__init__.py
52+
windows_dll_manager.py
5053
)
5154

5255
FOREACH(python ${PYTHON_FILES})

python/pycppad/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,30 @@
44

55
from .pycppad_pywrap import *
66
from .pycppad_pywrap import __version__, __raw_version__
7+
8+
# On Windows, if pycppad.dll is not in the same directory than
9+
# the .pyd, it will not be loaded.
10+
# We first try to load pycppad, then, if it fail and we are on Windows:
11+
# 1. We add all paths inside PYCPPAD_WINDOWS_DLL_PATH to DllDirectory
12+
# 2. If PYCPPAD_WINDOWS_DLL_PATH we add the relative path from the
13+
# package directory to the bin directory to DllDirectory
14+
# This solution is inspired from:
15+
# - https://github.com/PixarAnimationStudios/OpenUSD/pull/1511/files
16+
# - https://stackoverflow.com/questions/65334494/python-c-extension-packaging-dll-along-with-pyd
17+
# More resources on https://github.com/diffpy/pyobjcryst/issues/33
18+
try:
19+
from .pycppad_pywrap import *
20+
from .pycppad_pywrap import __version__, __raw_version__
21+
except ImportError:
22+
import platform
23+
24+
if platform.system() == "Windows":
25+
from .windows_dll_manager import get_dll_paths, build_directory_manager
26+
27+
with build_directory_manager() as dll_dir_manager:
28+
for p in get_dll_paths():
29+
dll_dir_manager.add_dll_directory(p)
30+
from .pycppad_pywrap import *
31+
from .pycppad_pywrap import __version__, __raw_version__
32+
else:
33+
raise

0 commit comments

Comments
 (0)