diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed8ec56..2fe644f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,15 @@ on: - master jobs: + codegen: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: build + run: | + make codegen + - name: Check if the git repository is clean + run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1) linux: runs-on: ubuntu-latest strategy: diff --git a/CMakeLists.txt b/CMakeLists.txt index 103e9a3..f7a1d1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,6 @@ project(quickjs LANGUAGES C) include(CheckCCompilerFlag) include(GNUInstallDirs) -# TODO: -# - Support cross-compilation - set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON) @@ -183,19 +180,10 @@ target_link_libraries(qjsc ${qjs_libs}) # QuickJS CLI # -add_custom_command( - OUTPUT repl.c - COMMAND qjsc -o ./repl.c -m ${CMAKE_CURRENT_SOURCE_DIR}/repl.js - DEPENDS qjsc - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Compile repl.js to bytecode" - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/repl.js -) - add_executable(qjs_exe + gen/repl.c qjs.c quickjs-libc.c - ${CMAKE_CURRENT_BINARY_DIR}/repl.c ) set_target_properties(qjs_exe PROPERTIES OUTPUT_NAME "qjs" @@ -236,16 +224,8 @@ add_executable(unicode_gen EXCLUDE_FROM_ALL ) target_compile_definitions(unicode_gen PRIVATE ${qjs_defines}) -add_custom_command( - OUTPUT function_source.c - COMMAND qjsc -e -o function_source.c ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js - DEPENDS qjsc ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Compile function_source.js to a C file with bytecode embedded" - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js -) add_executable(function_source - ${CMAKE_CURRENT_BINARY_DIR}/function_source.c + gen/function_source.c quickjs-libc.c ) target_include_directories(function_source PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) @@ -256,32 +236,16 @@ target_link_libraries(function_source ${qjs_libs}) # if(BUILD_EXAMPLES AND NOT WIN32) - add_custom_command( - OUTPUT hello.c - COMMAND qjsc -e -o hello.c ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello.js - DEPENDS qjsc - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Compile hello.js to a C file with bytecode embedded" - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello.js - ) add_executable(hello - ${CMAKE_CURRENT_BINARY_DIR}/hello.c + gen/hello.c quickjs-libc.c ) target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(hello PRIVATE ${qjs_defines}) target_link_libraries(hello ${qjs_libs}) - add_custom_command( - OUTPUT hello_module.c - COMMAND qjsc -e -o hello_module.c -m ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello_module.js - DEPENDS qjsc - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Compile hello_module.js to a C file with bytecode embedded" - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello_module.js - ) add_executable(hello_module - ${CMAKE_CURRENT_BINARY_DIR}/hello_module.c + gen/hello_module.c quickjs-libc.c ) target_include_directories(hello_module PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) @@ -320,17 +284,9 @@ if(BUILD_EXAMPLES AND NOT WIN32) endif() endif() - add_custom_command( - OUTPUT test_fib.c - COMMAND qjsc -e -o test_fib.c -M ${CMAKE_CURRENT_SOURCE_DIR}/examples/fib.so,fib -m ${CMAKE_CURRENT_SOURCE_DIR}/examples/test_fib.js - DEPENDS qjsc - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Compile test_fib.js to a C file with bytecode embedded" - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/test_fib.js - ) add_executable(test_fib - ${CMAKE_CURRENT_BINARY_DIR}/test_fib.c examples/fib.c + gen/test_fib.c quickjs-libc.c ) target_include_directories(test_fib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/Makefile b/Makefile index 4d25cdf..26eb386 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ BUILD_DIR=build BUILD_TYPE?=Release QJS=$(BUILD_DIR)/qjs +QJSC=$(BUILD_DIR)/qjsc RUN262=$(BUILD_DIR)/run-test262 JOBS?=$(shell getconf _NPROCESSORS_ONLN) @@ -49,12 +50,22 @@ $(BUILD_DIR): $(QJS): $(BUILD_DIR) cmake --build $(BUILD_DIR) -j $(JOBS) -install: $(QJS) +$(QJSC): $(BUILD_DIR) + cmake --build $(BUILD_DIR) --target qjsc -j $(JOBS) + +install: $(QJS) $(QJSC) cmake --build $(BUILD_DIR) --target install clean: cmake --build $(BUILD_DIR) --target clean +codegen: $(QJSC) + $(QJSC) -o gen/repl.c -m repl.js + $(QJSC) -e -o gen/function_source.c tests/function_source.js + $(QJSC) -e -o gen/hello.c examples/hello.js + $(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js + $(QJSC) -e -o gen/test_fib.c -M examples/fib.so,fib -m examples/test_fib.js + debug: BUILD_TYPE=Debug $(MAKE) @@ -92,4 +103,4 @@ unicode_gen: $(BUILD_DIR) libunicode-table.h: unicode_gen $(BUILD_DIR)/unicode_gen unicode $@ -.PHONY: all debug install clean distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) +.PHONY: all debug install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC) diff --git a/gen/function_source.c b/gen/function_source.c new file mode 100644 index 0000000..6c1b490 Binary files /dev/null and b/gen/function_source.c differ diff --git a/gen/hello.c b/gen/hello.c new file mode 100644 index 0000000..34376e2 Binary files /dev/null and b/gen/hello.c differ diff --git a/gen/hello_module.c b/gen/hello_module.c new file mode 100644 index 0000000..e4c6056 Binary files /dev/null and b/gen/hello_module.c differ diff --git a/gen/repl.c b/gen/repl.c new file mode 100644 index 0000000..808933e Binary files /dev/null and b/gen/repl.c differ diff --git a/gen/test_fib.c b/gen/test_fib.c new file mode 100644 index 0000000..1d9d138 Binary files /dev/null and b/gen/test_fib.c differ