diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf984670..ad6051dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,59 +17,90 @@ on: jobs: linux: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + buildType: [Debug, Release] steps: - uses: actions/checkout@v3 with: submodules: true - name: build run: | - make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y all run-test262 + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=${{matrix.buildType}} .. + cd .. + cmake --build build -j$(getconf _NPROCESSORS_ONLN) + - name: stats + run: | + ./build/qjs -qd - name: test run: | - make test test2 + ./build/qjs tests/test_bigint.js + ./build/qjs tests/test_closure.js + ./build/qjs tests/test_language.js + ./build/qjs tests/test_builtin.js + ./build/qjs tests/test_loop.js + ./build/qjs tests/test_std.js + ./build/qjs tests/test_worker.js + - name: test 262 + run: | + time ./build/run-test262 -m -c test262.conf -a linux-asan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: test + env: + ASAN_OPTIONS: halt_on_error=1 run: | - make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_ASAN=y ASAN_OPTIONS="halt_on_error=1" test + mkdir build + cd build + cmake -DCONFIG_ASAN=ON .. + cd .. + cmake --build build -j$(getconf _NPROCESSORS_ONLN) + ./build/qjs tests/test_bigint.js + ./build/qjs tests/test_closure.js + ./build/qjs tests/test_language.js + ./build/qjs tests/test_builtin.js + ./build/qjs tests/test_loop.js + ./build/qjs tests/test_std.js + ./build/qjs tests/test_worker.js linux-msan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: test + env: + CC: clang + MSAN_OPTIONS: halt_on_error=1 run: | - make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_MSAN=y CONFIG_CLANG=y MSAN_OPTIONS="halt_on_error=1" test + mkdir build + cd build + cmake -DCONFIG_MSAN=ON .. + cd .. + cmake --build build -j$(getconf _NPROCESSORS_ONLN) + ./build/qjs tests/test_bigint.js + ./build/qjs tests/test_closure.js + ./build/qjs tests/test_language.js + ./build/qjs tests/test_builtin.js + ./build/qjs tests/test_loop.js + ./build/qjs tests/test_std.js + ./build/qjs tests/test_worker.js linux-ubsan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: test - run: | - make -j$(getconf _NPROCESSORS_ONLN) CONFIG_WERROR=y CONFIG_UBSAN=y UBSAN_OPTIONS="halt_on_error=1" test - linux-cmake: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - buildType: [Debug, Release] - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: build + env: + UBSAN_OPTIONS: halt_on_error=1 run: | mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=${{matrix.buildType}} .. + cmake -DCONFIG_UBSAN=ON .. cd .. cmake --build build -j$(getconf _NPROCESSORS_ONLN) - - name: stats - run: | - ./build/qjs -qd - - name: test - run: | ./build/qjs tests/test_bigint.js ./build/qjs tests/test_closure.js ./build/qjs tests/test_language.js @@ -77,9 +108,6 @@ jobs: ./build/qjs tests/test_loop.js ./build/qjs tests/test_std.js ./build/qjs tests/test_worker.js - - name: test 262 - run: | - time ./build/run-test262 -m -c test262.conf -a macos: runs-on: macos-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index b2f0eb5d..076c8da6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ project(quickjs LANGUAGES C) # TODO: # - LTO # - Support cross-compilation -# - ASAN / MSAN / UBSAN # - Install targets # - Shared library target @@ -51,7 +50,49 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug") ) endif() -set(CMAKE_VERBOSE_MAKEFILE TRUE) +option(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF) +option(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF) +option(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF) + +if(CONFIG_ASAN) +message(STATUS "Building with ASan") +add_compile_options( + -fsanitize=address + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +add_link_options( + -fsanitize=address + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +elseif(CONFIG_MSAN) +message(STATUS "Building with MSan") +add_compile_options( + -fsanitize=memory + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +add_link_options( + -fsanitize=memory + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +elseif(CONFIG_UBSAN) +message(STATUS "Building with UBSan") +add_compile_options( + -fsanitize=undefined + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +add_link_options( + -fsanitize=undefined + -fno-sanitize-recover=all + -fno-omit-frame-pointer +) +endif() + +set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON") # QuickJS library