Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Jul 2, 2020
1 parent 14845af commit 3b9cb5e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions nmigen/_cxx.py
Original file line number Diff line number Diff line change
@@ -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.