From 50d6336384c1f50dfa4eccd5cf14bab200f735df Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 21 Feb 2024 15:21:56 -0600 Subject: [PATCH] Set RPATH in LDFLAGS at ./autogen and ./configure time * Set RPATH to support both local and cibuildwheel wheel builds. * Set LDFLAGS for to be written into the Makefiles generated by both the calls to ./autogen.sh and ./configure. --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 36c24d65..36c0c44a 100644 --- a/setup.py +++ b/setup.py @@ -66,10 +66,16 @@ def build_extensions(self): cwd=FASTJET, ) + # RPATH is set for shared libraries in the following locations: + # * fastjet/ + # * fastjet/_fastjet_core/lib/ + # * fastjet/_fastjet_core/lib/python*/site-packages/ + _rpath = "'$$ORIGIN/_fastjet_core/lib:$$ORIGIN:$$ORIGIN/../..'" env = os.environ.copy() env["PYTHON"] = sys.executable env["PYTHON_INCLUDE"] = f'-I{sysconfig.get_path("include")}' env["CXXFLAGS"] = "-O3 -Bstatic -lgmp -Bdynamic -std=c++17" + env["LDFLAGS"] = env.get("LDFLAGS", "") + f" -Wl,-rpath,{_rpath}" env["ORIGIN"] = "$ORIGIN" # if evaluated, it will still be '$ORIGIN' args = [ @@ -82,7 +88,7 @@ def build_extensions(self): f"--with-cgaldir={cgal_dir}", "--enable-swig", "--enable-pyext", - "LDFLAGS=-Wl,-rpath,$ORIGIN/_fastjet_core/lib:$ORIGIN", + f'LDFLAGS={env["LDFLAGS"]}', ] try: @@ -98,6 +104,7 @@ def build_extensions(self): env = os.environ.copy() env["CXX"] = env.get("CXX", "g++") + env["LDFLAGS"] = env.get("LDFLAGS", "") + f" -Wl,-rpath,{_rpath}" env["ORIGIN"] = "$ORIGIN" # if evaluated, it will still be '$ORIGIN' subprocess.run(["make", "-j"], cwd=FASTJET, env=env, check=True) subprocess.run(["make", "install"], cwd=FASTJET, env=env, check=True) @@ -108,6 +115,7 @@ def build_extensions(self): f"--fastjet-config={FASTJET}/fastjet-config", f'CXX={env["CXX"]}', "CXXFLAGS=-O3 -Bstatic -Bdynamic -std=c++17", + f'LDFLAGS={env["LDFLAGS"]}', ], cwd=FASTJET_CONTRIB, env=env,