Skip to content

Commit bf0a910

Browse files
Compile the C template with the LPython generated C file and create a shared library
Co-authored-by: Ondřej Čertík <[email protected]>
1 parent 1fd75d9 commit bf0a910

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/runtime/lpython/lpython.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,24 @@ def get_data_type(t):
705705
file.write(template)
706706

707707
# ----------------------------------------------------------------------
708+
# Generate the Shared library
708709
# TODO: Use LLVM instead of C backend
709710
r = os.system("lpython --show-c --disable-main a.py > a.h")
710711
assert r == 0, "Failed to create C file"
712+
gcc_flags = ""
713+
if platform.system() == "Linux":
714+
gcc_flags = " -shared -fPIC "
715+
elif platform.system() == "Darwin":
716+
gcc_flags = " -bundle -flat_namespace -undefined suppress "
717+
else:
718+
raise NotImplementedError("Platform not implemented")
719+
python_path = "-I" + get_python_inc() + " "
720+
numpy_path = "-I" + get_include()
721+
rt_path_01 = "-I" + get_rtlib_dir() + "/../libasr/runtime "
722+
rt_path_02 = "-L" + get_rtlib_dir() + " -Wl,-rpath " \
723+
+ get_rtlib_dir() + " -llpython_runtime "
724+
python_lib = "-L" "$CONDA_PREFIX/lib/ -lpython3.10 -lm"
725+
r = os.system("gcc -g" + gcc_flags + python_path + numpy_path +
726+
" a.c -o lpython_jit_module.so " + rt_path_01 + rt_path_02 + python_lib)
727+
assert r == 0, "Failed to create the shared library"
728+

0 commit comments

Comments
 (0)