Skip to content
Permalink
Browse files
wip
  • Loading branch information
whitequark committed Jul 2, 2020
1 parent 14845af commit 3b9cb5e9b9f1aa3f7c95bb9d9e2cd0ff917b7d79
Showing with 33 additions and 0 deletions.
  1. +33 −0 nmigen/_cxx.py
@@ -0,0 +1,33 @@
import tempfile
import sysconfig
import os.path
from distutils import ccompiler


def build(*, cxx_sources, output_name, include_dirs, macros):
build_dir = tempfile.TemporaryDirectory(prefix="nmigen_cxx_")

cc = ccompiler.new_compiler()
cc.output_dir = build_dir.name
cc.set_executables(
compiler=sysconfig.get_config_var('CC'),
compiler_cxx=sysconfig.get_config_var('CXX'),
linker_so=sysconfig.get_config_var("LDCXXSHARED"),
)

for include_dir in include_dirs:
cc.add_include_dir(include_dir)
for macro in macros:
cc.define_macro(macro)
for cxx_filename, cxx_source in cxx_sources.items():
with open(os.path.join(build_dir.name, cxx_filename), "w") as f:
f.write(cxx_source)

cc.compile([os.path.join(build_dir.name, cxx_filename)
for cxx_filename in cxx_sources.keys()])

so_filename = cc.shared_object_filename(output_name)
cc.link_shared_object(cc.object_filenames(cxx_sources.keys()),
output_filename=so_filename)

return build_dir, so_filename

0 comments on commit 3b9cb5e

Please sign in to comment.