diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2460cc32..01ef0077 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,40 +30,14 @@ jobs: path: | ./build/* ./firefox-102.2.0/* + ./_spidermonkey_install/* key: ${{ runner.os }}-spidermonkey - name: Build-Library if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }} - run: | - # Get number of CPU cores - CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1) - echo "Building SpiderMonkey" - #install rust compiler - curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y - wget -q https://ftp.mozilla.org/pub/firefox/releases/102.2.0esr/source/firefox-102.2.0esr.source.tar.xz - tar xf firefox-102.2.0esr.source.tar.xz - cd firefox-102.2.0/js - sed -i 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey - sed -i 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./src/vm/JSObject.cpp # same here - cd src - cp ./configure.in ./configure - chmod +x ./configure - mkdir _build - cd _build - ../configure --disable-jemalloc --with-system-zlib --with-intl-api --enable-optimize - make -j$CPUS - sudo make install - cd ../../../.. - echo "Building the library" - mkdir build - cd build - cmake .. - cmake --build . -j$CPUS - echo "Build complete" + run: ./setup.sh && ./build_script.sh - name: google-tests run: | - cd firefox-102.2.0/js/src/_build - sudo make install - cd ../../../../build + cd build make && make tests gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml cd tests && ctest diff --git a/.gitignore b/.gitignore index b11fc25f..a66f88ed 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ firefox-*/ tests/__pycache__/* tests/python/__pycache__/* Testing/Temporary +_spidermonkey_install diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b732cbe..4d34aea9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) elseif(WIN32) find_package(PythonInterp 3.9...3.11 REQUIRED) find_package(PythonLibs 3.9...3.11 REQUIRED) - find_package(SpiderMonkey REQUIRED) + find_package(SpiderMonkey REQUIRED) set(PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION}) endif() include_directories(${PYTHON_INCLUDE_DIRS}) @@ -94,4 +94,4 @@ add_subdirectory(src) pythonmonkey_add_external("uncrustify") pythonmonkey_add_external("autopep8") -add_subdirectory(format) \ No newline at end of file +add_subdirectory(format) diff --git a/cmake/modules/FindSpiderMonkey.cmake b/cmake/modules/FindSpiderMonkey.cmake index e7c3292f..0410b8d7 100644 --- a/cmake/modules/FindSpiderMonkey.cmake +++ b/cmake/modules/FindSpiderMonkey.cmake @@ -38,7 +38,9 @@ endif() # SpiderMonkey search paths set(SPIDERMONKEY_PATHS - ${SPIDERMONKEY_ROOT} + "${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install" + "${CMAKE_CURRENT_SOURCE_DIR}/_spidermonkey_install/lib" + ${SPIDERMONKEY_ROOT} $ENV{SPIDERMONKEY_ROOT} ~/Library/Frameworks /Library/Frameworks @@ -60,11 +62,12 @@ set(SPIDERMONKEY_HEADERS jsapi.h js/RequiredDefines.h) set(SPIDERMONKEY_INCLUDE_SUFFIX_PATHS dist/include js/src include include/js include/mozjs-48a1 include/mozjs-102/) # Find SpiderMonkey include path - find_path(SPIDERMONKEY_INCLUDE_DIR ${SPIDERMONKEY_HEADERS} - PATHS ${SPIDERMONKEY_PATHS} - PATH_SUFFIXES ${SPIDERMONKEY_INCLUDE_SUFFIX_PATHS} - DOC "Mozilla SpiderMonkey JavaScript Engine Headers" - ) +find_path(SPIDERMONKEY_INCLUDE_DIR ${SPIDERMONKEY_HEADERS} + PATHS ${SPIDERMONKEY_PATHS} + PATH_SUFFIXES ${SPIDERMONKEY_INCLUDE_SUFFIX_PATHS} + DOC "Mozilla SpiderMonkey JavaScript Engine Headers" + NO_DEFAULT_PATH +) # SpiderMonkey libs set(SPIDERMONKEY_LIBRARY_NAMES mozjs-107a1.lib libmozjs-102.so mozjs185 mozjs-1.9.2 mozjs-48a1 mozjs js185 js js32 js3250) @@ -154,4 +157,4 @@ list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${SPIDERMONKEY_LIBRARY}) list(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES) mark_as_advanced(SPIDERMONKEY_INCLUDE_DIR SPIDERMONKEY_LIBRARY) -mark_as_advanced(SPIDERMONKEY_JS_CONFIG_HEADER_PATH) \ No newline at end of file +mark_as_advanced(SPIDERMONKEY_JS_CONFIG_HEADER_PATH) diff --git a/setup.sh b/setup.sh index 21528a3d..b1f75598 100755 --- a/setup.sh +++ b/setup.sh @@ -1,20 +1,37 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + + # Get number of CPU cores CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1) +echo "Installing dependencies" sudo apt-get update --yes sudo apt-get upgrade --yes sudo apt-get install cmake python3-dev python3-pytest doxygen graphviz gcovr llvm g++ pkg-config m4 --yes sudo curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y #install rust compiler -wget -q https://ftp.mozilla.org/pub/firefox/releases/102.2.0esr/source/firefox-102.2.0esr.source.tar.xz +echo "Done installing dependencies" + +echo "Downloading spidermonkey source code" +wget -c -q https://ftp.mozilla.org/pub/firefox/releases/102.2.0esr/source/firefox-102.2.0esr.source.tar.xz tar xf firefox-102.2.0esr.source.tar.xz +echo "Done downloading spidermonkey source code" + +echo "Building spidermonkey" cd firefox-102.2.0/js sed -i 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey sed -i 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./src/vm/JSObject.cpp # same here cd src cp ./configure.in ./configure chmod +x ./configure -mkdir _build +mkdir -p _build cd _build -../configure --disable-jemalloc --with-system-zlib --with-intl-api --enable-optimize +../configure --disable-jemalloc --with-system-zlib --with-intl-api --enable-optimize --prefix=$(realpath $PWD/../../../../_spidermonkey_install) make -j$CPUS -sudo make install \ No newline at end of file +echo "Done building spidermonkey" + +echo "Installing spidermonkey" +mkdir -p ../../../../_spidermonkey_install/ +make install +echo "Done installing spidermonkey"