use meson to build
(cfile, outputfilename, compile_extra, link_extra,
include_dirs, libraries, library_dirs)
| 201 | |
| 202 | |
| 203 | def build(cfile, outputfilename, compile_extra, link_extra, |
| 204 | include_dirs, libraries, library_dirs): |
| 205 | "use meson to build" |
| 206 | |
| 207 | build_dir = cfile.parent / "build" |
| 208 | os.makedirs(build_dir, exist_ok=True) |
| 209 | with open(cfile.parent / "meson.build", "wt") as fid: |
| 210 | link_dirs = ['-L' + d for d in library_dirs] |
| 211 | fid.write(textwrap.dedent(f"""\ |
| 212 | project('foo', 'c') |
| 213 | py = import('python').find_installation(pure: false) |
| 214 | py.extension_module( |
| 215 | '{outputfilename.parts[-1]}', |
| 216 | '{cfile.parts[-1]}', |
| 217 | c_args: {compile_extra}, |
| 218 | link_args: {link_dirs}, |
| 219 | include_directories: {include_dirs}, |
| 220 | ) |
| 221 | """)) |
| 222 | native_file_name = cfile.parent / ".mesonpy-native-file.ini" |
| 223 | with open(native_file_name, "wt") as fid: |
| 224 | fid.write(textwrap.dedent(f"""\ |
| 225 | [binaries] |
| 226 | python = '{sys.executable}' |
| 227 | """)) |
| 228 | if sys.platform == "win32": |
| 229 | run_subprocess(["meson", "setup", |
| 230 | "--buildtype=release", |
| 231 | "--vsenv", ".."], |
| 232 | build_dir) |
| 233 | else: |
| 234 | run_subprocess(["meson", "setup", "--vsenv", |
| 235 | "..", f'--native-file={os.fspath(native_file_name)}'], |
| 236 | build_dir) |
| 237 | |
| 238 | so_name = outputfilename.parts[-1] + get_so_suffix() |
| 239 | run_subprocess(["meson", "compile"], build_dir) |
| 240 | os.rename(str(build_dir / so_name), cfile.parent / so_name) |
| 241 | return cfile.parent / so_name |
| 242 | |
| 243 | |
| 244 | def get_so_suffix(): |
no test coverage detected
searching dependent graphs…