Skip to content

Commit

Permalink
Refactor build of C++ for pygambit extension.
Browse files Browse the repository at this point in the history
This refactors the build of the pygambit extension to create more granular libraries of the C++ code,
with the aim of reducing unnecessary re-builds when changes are made.
  • Loading branch information
tturocy committed Apr 16, 2024
1 parent 0ef930e commit 777523b
Showing 1 changed file with 58 additions and 15 deletions.
73 changes: 58 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,66 @@
# with passing C++-specific flags when building the extension
lrslib = ("lrslib", {"sources": glob.glob("src/solvers/lrs/*.c")})

cppgambit = (
"cppgambit",
cppgambit_include_dirs = ["src"]
cppgambit_cflags = (
["-std=c++17"] if platform.system() == "Darwin"
else ["/std:c++17"] if platform.system() == "Windows"
else []
)

cppgambit_core = (
"cppgambit_core",
{
"sources": glob.glob("src/core/*.cc"),
"obj_deps": {"": glob.glob("src/core/*.h") + glob.glob("src/core/*.imp")},
"include_dirs": cppgambit_include_dirs,
"cflags": cppgambit_cflags,
}
)

cppgambit_games = (
"cppgambit_games",
{
"sources": (
glob.glob("src/core/*.cc") +
glob.glob("src/games/*.cc") +
glob.glob("src/games/agg/*.cc") +
[fn for fn in glob.glob("src/solvers/*/*.cc") if "enumpoly" not in fn]
),
"include_dirs": ["src"],
"cflags": (
["-std=c++17"] if platform.system() == "Darwin"
else ["/std:c++17"] if platform.system() == "Windows"
else []
)
"sources": glob.glob("src/games/*.cc") + glob.glob("src/games/agg/*.cc"),
"obj_deps": {
"": (
glob.glob("src/core/*.h") + glob.glob("src/core/*.imp") +
glob.glob("src/games/*.h") + glob.glob("src/games/*.imp") +
glob.glob("src/games/agg/*.h")
)
},
"include_dirs": cppgambit_include_dirs,
"cflags": cppgambit_cflags,
}
)


def solver_library_config(library_name: str, paths: list) -> tuple:
return (
library_name,
{
"sources": [fn for solver in paths for fn in glob.glob(f"src/solvers/{solver}/*.cc")],
"obj_deps": {
"": (
glob.glob("src/core/*.h") + glob.glob("src/games/*.h") +
glob.glob("src/games/agg/*.h") +
[fn for solver in paths for fn in glob.glob(f"src/solvers/{solver}/*.h")]
)
},
"include_dirs": cppgambit_include_dirs,
"cflags": cppgambit_cflags,
}
)


cppgambit_bimatrix = solver_library_config("cppgambit_bimatrix",
["linalg", "lp", "lcp", "enummixed"])
cppgambit_liap = solver_library_config("cppgambit_liap", ["liap"])
cppgambit_logit = solver_library_config("cppgambit_logit", ["logit"])
cppgambit_gtracer = solver_library_config("cppgambit_gtracer", ["gtracer", "ipa", "gnm"])
cppgambit_simpdiv = solver_library_config("cppgambit_simpdiv", ["simpdiv"])


libgambit = setuptools.Extension(
"pygambit.gambit",
sources=["src/pygambit/gambit.pyx"],
Expand Down Expand Up @@ -101,7 +142,9 @@ def readme():
"scipy",
"deprecated",
],
libraries=[cppgambit, lrslib],
libraries=[cppgambit_bimatrix, cppgambit_liap, cppgambit_logit, cppgambit_simpdiv,
cppgambit_gtracer,
cppgambit_games, cppgambit_core, lrslib],
package_dir={"": "src"},
packages=["pygambit"],
ext_modules=Cython.Build.cythonize(libgambit,
Expand Down

0 comments on commit 777523b

Please sign in to comment.