Skip to content

Commit 1386ed8

Browse files
committed
Merge branch 'main' into Xmader/feat/WtfPM
2 parents 6296419 + e31cc94 commit 1386ed8

File tree

89 files changed

+6446
-5017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+6446
-5017
lines changed

.git-blame-ignore-revs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# chore(linting): lint all python files
2+
aae30e864449442cf0b04e94f8a242b1b667de9a
3+
4+
# chore(linting): lint all JavaScript files
5+
16dc3153b3cb684ca72445ed058babc8f5d97f42
6+
7+
# chore(linting): lint all C++ files
8+
58cd4b45777b046f03a63255c1d93e289e1cab5e

.github/workflows/test-and-publish.yaml

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,40 @@ on:
99
workflow_call:
1010
workflow_dispatch:
1111
inputs:
12-
debug_enabled:
13-
type: boolean
14-
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
12+
debug_enabled_os:
13+
type: choice
14+
description: Optionally, choose an OS to run the build with SSH debugging on (https://github.com/fawazahmed0/action-debug)
1515
required: false
16-
default: false
17-
dump_cores:
18-
type: boolean
19-
description: 'Include core dumps in CI artifacts'
16+
options:
17+
- ''
18+
- 'ubuntu-20.04'
19+
- 'macos-12'
20+
- 'macos-13'
21+
- 'macos-14'
22+
- 'windows-2019'
23+
debug_enabled_python:
24+
type: choice
25+
description: Choose a Python version to run the build with SSH debugging on
2026
required: false
21-
default: false
27+
options:
28+
- ''
29+
- '3.8'
30+
- '3.9'
31+
- '3.10'
32+
- '3.11'
33+
- '3.12'
34+
build_type:
35+
type: choice
36+
description: 'Choose the build type to use'
37+
required: false
38+
default: 'Debug'
39+
options:
40+
- 'Debug'
41+
- 'Profile'
42+
- 'Sanitize'
43+
- 'DRelease'
44+
- 'Release'
45+
- 'None'
2246
pull_request:
2347

2448
env:
@@ -100,11 +124,10 @@ jobs:
100124
fail-fast: false
101125
matrix:
102126
# The lowest supported version is Ubuntu 20.04 + Python 3.8 or macOS 12 + Python 3.9
103-
os: [ 'ubuntu-20.04', 'macos-12', 'windows-2019', 'macos-14' ]
127+
os: [ 'ubuntu-20.04', 'macos-12', 'macos-13', 'macos-14', 'windows-2019' ]
104128
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
105129
exclude:
106130
# macOS 12 comes with Python 3.9 by default, so we drop ci support for Python 3.8 on macOS
107-
# FIXME: We can't build on macOS 11 for now because our prebuilt `uncrustify` binary requires macOS 12
108131
- os: 'macos-12'
109132
python_version: '3.8'
110133
# actions/setup-python: The version '3.8'/'3.9' with architecture 'arm64' was not found for macOS.
@@ -133,15 +156,9 @@ jobs:
133156
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
134157
sudo apt-get update -y
135158
sudo apt-get install -y cmake graphviz llvm
136-
# Install Doxygen
137-
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
138-
wget -c -q https://www.doxygen.nl/files/doxygen-1.9.7.linux.bin.tar.gz
139-
tar xf doxygen-1.9.7.linux.bin.tar.gz
140-
cd doxygen-1.9.7 && sudo make install && cd -
141-
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
142159
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
143160
brew update || true # allow failure
144-
brew install cmake doxygen pkg-config wget coreutils # `coreutils` installs the `realpath` command
161+
brew install cmake pkg-config wget coreutils # `coreutils` installs the `realpath` command
145162
fi
146163
echo "Installing python deps"
147164
poetry self add "poetry-dynamic-versioning[plugin]"
@@ -165,21 +182,16 @@ jobs:
165182
- name: Build wheel
166183
run: |
167184
echo $(poetry run python --version)
168-
poetry build --format=wheel
185+
WORKFLOW_BUILD_TYPE=${{ inputs.build_type }}
186+
BUILD_TYPE=${WORKFLOW_BUILD_TYPE:-"Debug"} poetry build --format=wheel
169187
ls -lah ./dist/
170188
- name: Upload wheel as CI artifacts
171189
uses: actions/upload-artifact@v3
172190
with:
173191
name: wheel-${{ github.run_id }}-${{ github.sha }}
174192
path: ./dist/
175-
- name: Upload Doxygen-generated docs as CI artifacts
176-
uses: actions/upload-artifact@v3
177-
if: ${{ matrix.os == 'ubuntu-20.04' && matrix.python_version == '3.11' }} # making sure we only upload once
178-
with:
179-
name: docs-${{ github.run_id }}-${{ github.sha }}
180-
path: ./build/docs/html/
181193
- name: Set cores to get stored in /cores
182-
if: ${{ matrix.os != 'windows-2019' && github.event_name == 'workflow_dispatch' && inputs.dump_cores }}
194+
if: ${{ matrix.os != 'windows-2019' }}
183195
# TODO (Caleb Aikens) figure out how to get Windows core dumps
184196
run: |
185197
sudo mkdir -p /cores
@@ -196,7 +208,8 @@ jobs:
196208
# TODO (Caleb Aikens) figure out how to get Windows core dumps
197209
ulimit -c unlimited
198210
fi
199-
poetry run python -m pip install --force-reinstall --verbose ./dist/*
211+
WORKFLOW_BUILD_TYPE=${{ inputs.build_type }}
212+
BUILD_TYPE=${WORKFLOW_BUILD_TYPE:-"Debug"} poetry run python -m pip install --force-reinstall --verbose ./dist/*
200213
poetry run python -m pytest tests/python
201214
- name: Run JS tests (peter-jr)
202215
if: ${{ (success() || failure()) }}
@@ -206,20 +219,18 @@ jobs:
206219
ulimit -c unlimited
207220
fi
208221
poetry run bash ./peter-jr ./tests/js/
222+
- name: SSH debug session
223+
if: ${{ (success() || failure()) && github.event_name == 'workflow_dispatch' && inputs.debug_enabled_os == matrix.os && inputs.debug_enabled_python == matrix.python_version}}
224+
uses: fawazahmed0/action-debug@main
225+
with:
226+
credentials: "admin:admin"
209227
- name: Upload core dumps as CI artifacts
210228
uses: actions/upload-artifact@v3
211-
if: ${{ matrix.os != 'windows-2019' && github.event_name == 'workflow_dispatch' && inputs.dump_cores }}
229+
if: ${{ matrix.os != 'windows-2019' && failure() }}
212230
# TODO (Caleb Aikens) figure out how to get Windows core dumps
213231
with:
214232
name: cores-${{ matrix.os }}-${{ matrix.python_version }}
215233
path: /cores
216-
# Enable tmate debugging of manually-triggered workflows if the input option was provided
217-
- name: SSH debug session
218-
if: ${{ (success() || failure()) && github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
219-
uses: mxschmitt/action-tmate@v3
220-
with:
221-
detached: true
222-
limit-access-to-actor: true
223234
sdist:
224235
runs-on: ubuntu-20.04
225236
steps:
@@ -235,14 +246,26 @@ jobs:
235246
version: 1.5.1
236247
- name: Build source distribution (sdist) file
237248
run: |
249+
# Install Doxygen
250+
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
251+
wget -c -q https://www.doxygen.nl/files/doxygen-1.9.7.linux.bin.tar.gz
252+
tar xf doxygen-1.9.7.linux.bin.tar.gz
253+
cd doxygen-1.9.7 && sudo make install && cd -
254+
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
238255
poetry self add "poetry-dynamic-versioning[plugin]"
256+
BUILD_DOCS=1 BUILD_TYPE=None poetry install
239257
poetry build --format=sdist
240258
ls -lah ./dist/
241259
- name: Upload sdist as CI artifacts
242260
uses: actions/upload-artifact@v3
243261
with:
244262
name: wheel-${{ github.run_id }}-${{ github.sha }}
245263
path: ./dist/
264+
- name: Upload Doxygen-generated docs as CI artifacts
265+
uses: actions/upload-artifact@v3
266+
with:
267+
name: docs-${{ github.run_id }}-${{ github.sha }}
268+
path: ./build/docs/html/
246269
publish:
247270
needs: [build-and-test, sdist]
248271
runs-on: ubuntu-20.04

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ firefox-*/
1111
__pycache__
1212
Testing/Temporary
1313
_spidermonkey_install
14+
uncrustify-*.tar.gz
15+
uncrustify-*/
16+
uncrustify
17+
*.uncrustify
1418
__pycache__/*
1519
dist
1620
*.so

CMakeLists.txt

Lines changed: 89 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1717
set(CMAKE_CXX_EXTENSIONS OFF)
1818
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1919

20-
# Add an external; appends to `PYTHONMONKEY_EXTERNAL_FILES` in the parent scope.
21-
function(pythonmonkey_add_external PYTHONMONKEY_EXTERNAL)
22-
add_subdirectory("cmake/externals/${PYTHONMONKEY_EXTERNAL}")
23-
set(PYTHONMONKEY_EXTERNAL_FILE "cmake/externals/${PYTHONMONKEY_EXTERNAL}/CMakeLists.txt")
24-
source_group(
25-
TREE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/externals/${PYTHONMONKEY_EXTERNAL}"
26-
PREFIX "Externals\\${PYTHONMONKEY_EXTERNAL}"
27-
FILES "${PYTHONMONKEY_EXTERNAL_FILE}"
28-
)
29-
list(APPEND PYTHONMONKEY_EXTERNAL_FILES "${PYTHONMONKEY_EXTERNAL_FILE}")
30-
31-
set(PYTHONMONKEY_EXTERNAL_FILES ${PYTHONMONKEY_EXTERNAL_FILES} PARENT_SCOPE)
32-
endfunction()
33-
34-
file (GLOB SOURCE_FILES "src/*.cc" "src/internalBinding/*.cc") # Find all C++ files in the src directory
35-
file (GLOB HEADER_FILES "include/*.hh") # Find all header files in the include directory
36-
file (GLOB PYTHON_FILES "python/*.cc" "python/*.hh") # Find all the python bindings in the python directory
20+
file (GLOB_RECURSE HEADER_FILES "include/*.hh") # Find all header files in the include directory and below
21+
file (GLOB_RECURSE SOURCE_FILES "src/*.cc") # Find all C++ files in the src directory and below
22+
3723

3824
include_directories(${CMAKE_CURRENT_LIST_DIR})
3925

@@ -43,48 +29,97 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
4329
### Code block from: https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
4430
include(FetchContent)
4531

46-
SET(COMPILE_FLAGS "-ggdb -Ofast -fno-rtti") # optimize but also emit debug symbols
47-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} $ENV{EXTRA_CMAKE_CXX_FLAGS}")
48-
49-
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
50-
if(APPLE)
51-
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
52-
find_package(SpiderMonkey REQUIRED)
53-
set(PYTHON_MAJOR $ENV{Python_VERSION_MAJOR})
54-
set(PYTHON_MINOR $ENV{Python_VERSION_MINOR})
55-
set(PYTHONLIBS_VERSION_STRING ${Python_VERSION})
56-
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS})
57-
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
58-
message("Apple - Using Python:${Python_VERSION_MAJOR} - Libraries:${PYTHON_LIBRARIES} - IncludeDirs: ${PYTHON_INCLUDE_DIR}")
59-
elseif(UNIX)
60-
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
61-
set(Python_FIND_VIRTUALENV FIRST) # (require cmake >= v3.15 and this is the default) use the Python version configured by pyenv if available
62-
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
63-
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS})
64-
message("Linux - Using Python:${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - Libraries:${PYTHON_LIBRARIES} - IncludeDirs: ${PYTHON_INCLUDE_DIR}")
65-
find_package(SpiderMonkey REQUIRED)
66-
elseif(WIN32)
67-
find_package(PythonInterp 3.8 REQUIRED)
68-
find_package(PythonLibs 3.8 REQUIRED)
69-
find_package(SpiderMonkey REQUIRED)
70-
set(PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION})
32+
if (WIN32)
33+
SET(COMPILE_FLAGS "/GR- /W0")
34+
35+
SET(OPTIMIZED "/O2")
36+
SET(UNOPTIMIZED "/Od")
37+
SET(KEEP_SYMBOLS "/DEBUG:FULL")
38+
SET(STRIP_SYMBOLS "/DEBUG:NONE")
39+
SET(PROFILE "/PROFILE")
40+
SET(ADDRESS_SANITIZE "/fsanitize=address /Oy-")
41+
else()
42+
SET(COMPILE_FLAGS "-fno-rtti -Wno-invalid-offsetof")
43+
44+
SET(OPTIMIZED "-Ofast -DNDEBUG")
45+
SET(UNOPTIMIZED "-O0")
46+
SET(KEEP_SYMBOLS "-ggdb")
47+
SET(STRIP_SYMBOLS "-s")
48+
SET(PROFILE "-pg")
49+
SET(ADDRESS_SANITIZE "-fsanitize=address -fno-omit-frame-pointer")
50+
endif()
51+
SET(PROFILE_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} ${PROFILE}")
52+
SET(SANITIZE_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} ${ADDRESS_SANITIZE}")
53+
SET(DEBUG_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS}")
54+
SET(DRELEASE_FLAGS "${OPTIMIZED} ${KEEP_SYMBOLS}")
55+
SET(RELEASE_FLAGS "${OPTIMIZED} ${STRIP_SYMBOLS}")
56+
57+
if(GENERATOR_IS_MULTI_CONFIG)
58+
set(CMAKE_CONFIGURATION_TYPES "Profile;Sanitize;Debug;DRelease;Release;None" CACHE STRING "" FORCE)
59+
string(APPEND COMPILE_FLAGS "$<$<CONFIG:Profile>:${PROFILE_FLAGS}> $<$<CONFIG:Sanitize>:${SANITIZE_FLAGS}> $<$<CONFIG:Debug>:${DEBUG_FLAGS}> $<$<CONFIG:DRelease>:${DRELEASE_FLAGS}> $<$<CONFIG:Release>:${RELEASE_FLAGS}>")
60+
else()
61+
set_property(CACHE PM_BUILD_TYPE PROPERTY HELPSTRING "Choose the type of build")
62+
set_property(CACHE PM_BUILD_TYPE PROPERTY STRINGS "Profile;Sanitize;Debug;DRelease;Release;None")
63+
if(PM_BUILD_TYPE STREQUAL "Profile")
64+
list(APPEND COMPILE_FLAGS "${PROFILE_FLAGS}")
65+
elseif(PM_BUILD_TYPE STREQUAL "Sanitize")
66+
list(APPEND COMPILE_FLAGS "${SANITIZE_FLAGS}")
67+
elseif(PM_BUILD_TYPE STREQUAL "Debug")
68+
list(APPEND COMPILE_FLAGS "${DEBUG_FLAGS}")
69+
elseif(PM_BUILD_TYPE STREQUAL "DRelease")
70+
list(APPEND COMPILE_FLAGS "${DRELEASE_FLAGS}")
71+
elseif(PM_BUILD_TYPE STREQUAL "None")
72+
message("PM_BUILD_TYPE is None. Not compiling.")
73+
else() #Release build
74+
message("PM_BUILD_TYPE not detected or invalid value, defaulting to Release build.")
75+
set(PM_BUILD_TYPE Release CACHE STRING "" FORCE)
76+
list(APPEND COMPILE_FLAGS "${RELEASE_FLAGS}")
77+
endif()
78+
message("PythonMonkey build type is: ${PM_BUILD_TYPE}")
79+
list(JOIN COMPILE_FLAGS " " COMPILE_FLAGS)
7180
endif()
72-
include_directories(${PYTHON_INCLUDE_DIRS})
73-
include_directories(${SPIDERMONKEY_INCLUDE_DIR})
81+
82+
if(NOT PM_BUILD_TYPE STREQUAL "None")
83+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")
84+
85+
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
86+
if(APPLE)
87+
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
88+
find_package(SpiderMonkey REQUIRED)
89+
set(PYTHON_MAJOR $ENV{Python_VERSION_MAJOR})
90+
set(PYTHON_MINOR $ENV{Python_VERSION_MINOR})
91+
set(PYTHONLIBS_VERSION_STRING ${Python_VERSION})
92+
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS})
93+
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
94+
elseif(UNIX)
95+
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
96+
set(Python_FIND_VIRTUALENV FIRST) # (require cmake >= v3.15 and this is the default) use the Python version configured by pyenv if available
97+
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
98+
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS})
99+
find_package(SpiderMonkey REQUIRED)
100+
elseif(WIN32)
101+
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
102+
set(Python_FIND_VIRTUALENV FIRST) # (require cmake >= v3.15 and this is the default) use the Python version configured by pyenv if available
103+
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
104+
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS})
105+
find_package(SpiderMonkey REQUIRED)
106+
endif()
107+
message("${CMAKE_SYSTEM_NAME} - Using Python:${Python_VERSION} - Libraries:${Python_LIBRARIES} - IncludeDirs: ${Python_INCLUDE_DIRS}")
108+
include_directories(${Python_INCLUDE_DIRS})
109+
include_directories(${SPIDERMONKEY_INCLUDE_DIR})
110+
# Add compiled folder directories
111+
add_subdirectory(src)
112+
endif(NOT PM_BUILD_TYPE STREQUAL "None")
74113

75114
# Add doxygen if this is the main app
76-
find_package(Doxygen)
77-
if(Doxygen_FOUND)
115+
option(BUILD_DOCS "Build documentation" OFF)
116+
if(BUILD_DOCS)
117+
find_package(Doxygen)
118+
if(Doxygen_FOUND)
78119
add_subdirectory(cmake/docs)
79-
else()
120+
else()
80121
message(STATUS "Doxygen not found. Not building docs.")
122+
endif()
81123
endif()
82124

83125
endif()
84-
85-
# Add compiled folder directories
86-
add_subdirectory(src)
87-
88-
pythonmonkey_add_external("uncrustify")
89-
pythonmonkey_add_external("autopep8")
90-
add_subdirectory(cmake/format)

0 commit comments

Comments
 (0)