| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import subprocess |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
from setuptools import Extension, setup |
| 7 |
from setuptools.command.build_ext import build_ext |
| 8 |
|
| 9 |
|
| 10 |
class BuildExt(build_ext): |
| 11 |
def run(self) -> None: |
| 12 |
outputs = self.get_outputs() |
| 13 |
assert len(outputs) == 1 |
| 14 |
liba_path = Path(outputs[0]).parent / "liba.so" |
| 15 |
libb_path = Path(outputs[0]).parent / "libb.so" |
| 16 |
|
| 17 |
cmd = f"gcc -fPIC -shared -o {libb_path} b/b.c" |
| 18 |
subprocess.check_call(cmd.split()) |
| 19 |
libb_parent_path = libb_path.parent.resolve(strict=True) |
| 20 |
cmd = f"gcc -fPIC -shared -o {liba_path} -Ib a/a.c -L{libb_parent_path} -lb" |
| 21 |
subprocess.check_call(cmd.split()) |
| 22 |
liba_path = liba_path.resolve(strict=True) |
| 23 |
liba_link_path = Path("a/liba.so") |
| 24 |
if liba_link_path.exists(): |
| 25 |
liba_link_path.unlink() |
| 26 |
liba_link_path.symlink_to(liba_path) |
| 27 |
|
| 28 |
super().run() |
| 29 |
|
| 30 |
|
| 31 |
setup( |
| 32 |
name="testpartialresolution", |
| 33 |
version="0.0.1", |
| 34 |
packages=["testpartialresolution"], |
| 35 |
package_dir={"": "src"}, |
| 36 |
cmdclass={"build_ext": BuildExt}, |
| 37 |
ext_modules=[ |
| 38 |
Extension( |
| 39 |
"testpartialresolution/testpartialresolution", |
| 40 |
sources=["src/testpartialresolution/testpartialresolution.c"], |
| 41 |
extra_link_args=["-Wl,--disable-new-dtags", "-Wl,-rpath=$ORIGIN"], |
| 42 |
include_dirs=["a"], |
| 43 |
libraries=["a"], |
| 44 |
library_dirs=["a"], |
| 45 |
), |
| 46 |
], |
| 47 |
) |