Skip to content

Commit b924d1d

Browse files
czgdp1807certik
andcommitted
Build numpy and builtin intrinsics at build time
Co-authored-by: Ondřej Čertík <[email protected]>
1 parent 6051950 commit b924d1d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ set(WITH_LFORTRAN_BINARY_MODFILES YES
8080
set(WITH_RUNTIME_LIBRARY YES
8181
CACHE BOOL "Compile and install the runtime library")
8282

83+
set(WITH_INTRINSIC_MODULES no
84+
CACHE BOOL "Compile intrinsic modules to .pyc (ASR) at build time")
85+
8386
# Find ZLIB with our custom finder before including LLVM since the finder for LLVM
8487
# might search for ZLIB again and find the shared libraries instead of the static ones
8588
find_package(StaticZLIB REQUIRED)

src/bin/CMakeLists.txt

+28
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,31 @@ set_target_properties(lpython PROPERTIES
5757
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
5858
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
5959
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>)
60+
61+
if (WITH_INTRINSIC_MODULES)
62+
macro(LPYTHON_COMPILE_MODULE name)
63+
add_custom_command(
64+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../runtime/${name}.pyc
65+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lpython
66+
ARGS --disable-main -c ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${name}.py -o ${name}.o
67+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../runtime
68+
DEPENDS lpython ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${name}.py ${ARGN}
69+
COMMENT "LPython Compiling ${name}.py")
70+
endmacro(LPYTHON_COMPILE_MODULE)
71+
72+
LPYTHON_COMPILE_MODULE(lpython_intrinsic_numpy)
73+
LPYTHON_COMPILE_MODULE(lpython_builtin)
74+
75+
add_custom_target(lpython_intrinsics
76+
ALL
77+
DEPENDS
78+
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lpython_intrinsic_numpy.pyc
79+
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lpython_builtin.pyc
80+
)
81+
82+
install(
83+
FILES ${CMAKE_CURRENT_BINARY_DIR}/../runtime/lpython_intrinsic_numpy.pyc
84+
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lpython_builtin.pyc
85+
DESTINATION share/lfortran/lib
86+
)
87+
endif()

0 commit comments

Comments
 (0)