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 f2c43ee
Showing 1 changed file with 60 additions and 15 deletions.
75 changes: 60 additions & 15 deletions setup.py
Expand Up @@ -30,24 +30,68 @@
# 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,
}
)

solvers = ["enummixed", "enumpure", "gnm", "gtracer", "ipa",
"lcp", "liap", "linalg", "logit", "lp", "lrs", "simpdiv"]


def solver_library_config(library_name: str, paths: list[str]) -> 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",
Expand Down Expand Up @@ -101,7 +145,8 @@ def readme():
"scipy",
"deprecated",
],
libraries=[cppgambit, lrslib],
libraries=[cppgambit_core, cppgambit_games, cppgambit_bimatrix,
cppgambit_liap, cppgambit_logit, cppgambit_simpdiv, cppgambit_gtracer, lrslib],
package_dir={"": "src"},
packages=["pygambit"],
ext_modules=Cython.Build.cythonize(libgambit,
Expand Down

0 comments on commit f2c43ee

Please sign in to comment.