From 94dede77cd7f077eecf8e7014e20482e3e7abe7d Mon Sep 17 00:00:00 2001 From: Hamada Gasmallah Date: Mon, 17 Apr 2023 11:10:53 -0400 Subject: [PATCH 1/5] feat: installing libmozjs to local directory instead of global root default --- .gitignore | 1 + CMakeLists.txt | 4 ++-- pyproject.toml | 16 ++++++++++++++++ setup.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 25 +++++++++++++++++++++---- 5 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.py 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/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..32796943 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "pythonmonkey" +version = "0.1.0" +description = "" +authors = ["Caleb Aikens ", "Tom Tang "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.9" + + +[build-system] +requires = ['setuptools>=61.0'] # 'cython' +build-backend = 'setuptools.build_meta' + + diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..f878380f --- /dev/null +++ b/setup.py @@ -0,0 +1,50 @@ +from setuptools import setup, find_packages +from setuptools.command.build_ext import build_ext as _build_ext +import subprocess +import os, sys + +dir_path = os.path.dirname( os.path.realpath(__file__) ) + + +def execute(cmd: str): + popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, + shell = True, text = True ) + for stdout_line in iter(popen.stdout.readline, ""): + sys.stdout.write(stdout_line) + sys.stdout.flush() + + popen.stdout.close() + return_code = popen.wait() + if return_code: + raise subprocess.CalledProcessError(return_code, cmd) + + +class build_ext(): #_build_ext): + def __init__(self): #run(self): + setup_sh = os.path.join( dir_path, 'setup.sh ') + build_script_sh = os.path.join( dir_path, 'build_script.sh' ) + + #execute(f"bash {setup_sh}") + execute(f"bash {build_script_sh}") +build_ext() + +#with open( os.path.join( dir_path, 'version.txt' ), 'r' ) as f: +# version = "".join(f.readlines()) +# +#version = version.split(".") +# +#if len(version) > 3: +# version = ".".join( version[:3] ) +#elif len(version) !=3: +# raise ValueError(f"Version in version.txt is incorrect semver for python packages: {'.'.join(version)}") +#else: +# version = ".".join( version ) +# +# +# +#setup( +# cmdclass={"build_ext": build_ext}, +# version = version, +# packages = find_packages(), +# package_data = { ' +#) 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" From 022b416bbee79ff88c813a298e5fa7db6f779118 Mon Sep 17 00:00:00 2001 From: Hamada Gasmallah Date: Mon, 17 Apr 2023 11:37:44 -0400 Subject: [PATCH 2/5] feat: Updated find spidermonkey to use local to repo spidermonkey install location --- cmake/modules/FindSpiderMonkey.cmake | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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) From af91b2b9824eb9979b0c67d0f9644928177c6104 Mon Sep 17 00:00:00 2001 From: Hamada Gasmallah Date: Mon, 17 Apr 2023 11:38:25 -0400 Subject: [PATCH 3/5] chore: Removed unfinished pyproject.toml and setup.py --- pyproject.toml | 16 ---------------- setup.py | 50 -------------------------------------------------- 2 files changed, 66 deletions(-) delete mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 32796943..00000000 --- a/pyproject.toml +++ /dev/null @@ -1,16 +0,0 @@ -[tool.poetry] -name = "pythonmonkey" -version = "0.1.0" -description = "" -authors = ["Caleb Aikens ", "Tom Tang "] -readme = "README.md" - -[tool.poetry.dependencies] -python = "^3.9" - - -[build-system] -requires = ['setuptools>=61.0'] # 'cython' -build-backend = 'setuptools.build_meta' - - diff --git a/setup.py b/setup.py deleted file mode 100644 index f878380f..00000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -from setuptools import setup, find_packages -from setuptools.command.build_ext import build_ext as _build_ext -import subprocess -import os, sys - -dir_path = os.path.dirname( os.path.realpath(__file__) ) - - -def execute(cmd: str): - popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, - shell = True, text = True ) - for stdout_line in iter(popen.stdout.readline, ""): - sys.stdout.write(stdout_line) - sys.stdout.flush() - - popen.stdout.close() - return_code = popen.wait() - if return_code: - raise subprocess.CalledProcessError(return_code, cmd) - - -class build_ext(): #_build_ext): - def __init__(self): #run(self): - setup_sh = os.path.join( dir_path, 'setup.sh ') - build_script_sh = os.path.join( dir_path, 'build_script.sh' ) - - #execute(f"bash {setup_sh}") - execute(f"bash {build_script_sh}") -build_ext() - -#with open( os.path.join( dir_path, 'version.txt' ), 'r' ) as f: -# version = "".join(f.readlines()) -# -#version = version.split(".") -# -#if len(version) > 3: -# version = ".".join( version[:3] ) -#elif len(version) !=3: -# raise ValueError(f"Version in version.txt is incorrect semver for python packages: {'.'.join(version)}") -#else: -# version = ".".join( version ) -# -# -# -#setup( -# cmdclass={"build_ext": build_ext}, -# version = version, -# packages = find_packages(), -# package_data = { ' -#) From c585f1730b8a610422afc746fefd9bf8850a3a73 Mon Sep 17 00:00:00 2001 From: Hamada Gasmallah Date: Mon, 17 Apr 2023 12:45:46 -0400 Subject: [PATCH 4/5] ci: Update ci to use build scripts rather than have their own build process. --- .github/workflows/tests.yaml | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2460cc32..d7458b47 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,40 +30,15 @@ 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 - name: google-tests run: | - cd firefox-102.2.0/js/src/_build - sudo make install - cd ../../../../build + mkdir -p ./build + cd build make && make tests gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml cd tests && ctest From 10979299943c73a366ff7bbd073b8a9e6468e1d0 Mon Sep 17 00:00:00 2001 From: Hamada Gasmallah Date: Mon, 17 Apr 2023 13:05:56 -0400 Subject: [PATCH 5/5] CI: Update build to also build pythonmonkey --- .github/workflows/tests.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d7458b47..01ef0077 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,14 +30,13 @@ jobs: path: | ./build/* ./firefox-102.2.0/* - ./_spidermonkey_install + ./_spidermonkey_install/* key: ${{ runner.os }}-spidermonkey - name: Build-Library if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }} - run: ./setup.sh + run: ./setup.sh && ./build_script.sh - name: google-tests run: | - mkdir -p ./build cd build make && make tests gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml