Skip to content

Commit db51f18

Browse files
committed
feat: javascript helpers extension
fix #881
1 parent 90f72e8 commit db51f18

Some content is hidden

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

75 files changed

+2347
-2284
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ jobs:
428428
run: |
429429
rm -r ../third-party/llvm-project
430430
431-
- name: Install Duktape
431+
- name: Install JerryScript
432432
uses: alandefreitas/cpp-actions/[email protected]
433433
with:
434-
source-dir: ../third-party/duktape
435-
url: https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz
434+
source-dir: ../third-party/jerryscript
435+
url: https://github.com/jerryscript-project/jerryscript/archive/refs/tags/v3.0.0.tar.gz
436436
patches: |
437-
./third-party/patches/duktape/CMakeLists.txt
438-
./third-party/patches/duktape/duktapeConfig.cmake.in
437+
./third-party/patches/jerryscript/CMakeLists.txt
438+
./third-party/patches/jerryscript/jerryscriptConfig.cmake.in
439439
build-dir: ${sourceDir}/build
440440
cc: ${{ steps.setup-cpp.outputs.cc }}
441441
cxx: ${{ steps.setup-cpp.outputs.cxx }}
@@ -547,7 +547,7 @@ jobs:
547547
-D MRDOCS_BUILD_DOCS=OFF
548548
-D CMAKE_EXE_LINKER_FLAGS="${{ steps.rmatrix.outputs.common-ldflags }}"
549549
-D LLVM_ROOT="${{ steps.rmatrix.outputs.llvm-path }}"
550-
-D duktape_ROOT="${{ steps.rmatrix.outputs.third-party-dir }}/duktape/install"
550+
-D jerryscript_ROOT="${{ steps.rmatrix.outputs.third-party-dir }}/jerryscript/install"
551551
-D LUA_ROOT="${{ steps.rmatrix.outputs.third-party-dir }}/lua/install"
552552
-D Lua_ROOT="${{ steps.rmatrix.outputs.third-party-dir }}/lua/install"
553553
-D lua_ROOT="${{ steps.rmatrix.outputs.third-party-dir }}/lua/install"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
/.roadmap
2929
/AGENTS.md
3030
# Ignore hidden OS files under golden fixtures
31-
test-files/golden-tests/**/.*
31+
/test-files/golden-tests/**/.*
32+
/.code

CMakeLists.txt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,8 @@ llvm_map_components_to_libnames(llvm_libs all)
277277
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
278278
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
279279

280-
# Duktape
281-
find_package(duktape CONFIG)
282-
if (NOT DUKTAPE_FOUND)
283-
# Duktape doesn't natively support CMake.
284-
# Some config script patches use the capitalized version.
285-
find_package(Duktape REQUIRED CONFIG)
286-
endif()
280+
# JerryScript
281+
find_package(jerryscript REQUIRED CONFIG)
287282

288283
# Lua
289284
find_package(Lua CONFIG REQUIRED)
@@ -344,10 +339,11 @@ target_include_directories(mrdocs-core
344339
)
345340
target_include_directories(mrdocs-core
346341
SYSTEM PRIVATE
347-
"$<BUILD_INTERFACE:${DUKTAPE_INCLUDE_DIRS}>"
348-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
342+
"$<BUILD_INTERFACE:${JERRYSCRIPT_INCLUDE_DIRS}>"
343+
"$<BUILD_INTERFACE:${jerryscript_ROOT}/include>"
344+
"$<BUILD_INTERFACE:/usr/local/include>"
349345
)
350-
target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY})
346+
target_link_libraries(mrdocs-core PRIVATE ${JERRYSCRIPT_LIBRARY})
351347
target_link_libraries(mrdocs-core PRIVATE Lua::lua)
352348

353349
# Clang
@@ -425,8 +421,6 @@ list(APPEND TOOL_SOURCES
425421
${CMAKE_CURRENT_BINARY_DIR}/src/tool/PublicToolArgs.cpp)
426422

427423
add_executable(mrdocs ${TOOL_SOURCES})
428-
target_compile_definitions(mrdocs PRIVATE -DMRDOCS_TOOL)
429-
430424
target_include_directories(mrdocs
431425
PUBLIC
432426
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"

CMakePresets.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
1818
"LLVM_ROOT": "$env{LLVM_ROOT}",
1919
"Clang_ROOT": "$env{LLVM_ROOT}",
20-
"duktape_ROOT": "$env{DUKTAPE_ROOT}",
21-
"Duktape_ROOT": "$env{DUKTAPE_ROOT}",
20+
"jerryscript_ROOT": "$env{JERRYSCRIPT_ROOT}",
2221
"libxml2_ROOT": "$env{LIBXML2_ROOT}",
2322
"LibXml2_ROOT": "$env{LIBXML2_ROOT}",
2423
"MRDOCS_BUILD_TESTS": "ON",

docs/modules/ROOT/pages/contribute/codebase-tour.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,3 @@ The documentation is written in AsciiDoc and can be built using the Antora tool.
5959
==== `third-party/`—Helpers for third-party libraries
6060

6161
This directory contains build scripts and configuration files for third-party libraries.
62-
63-
* `third-party/`—Third-party libraries
64-
** `third-party/llvm/`—CMake Presets for LLVM
65-
** `third-party/duktape/`—CMake scripts for Duktape
66-
** `third-party/lua/`—A bundled Lua interpreter

docs/modules/ROOT/pages/install.adoc

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ Feel free to install them anywhere you want and adjust the main Mr.Docs configur
8080
8181
[IMPORTANT]
8282
====
83-
All instructions in this document assume you are using a CMake version above 3.26.
83+
All instructions in this document assume you are using a CMake version at or above 3.13 (project minimum).
8484
Binaries are available at https://cmake.org/download/[CMake's official website,window="_blank"].
8585
====
8686
87-
=== Duktape
87+
=== JerryScript
8888
89-
Mr.Docs uses the `duktape` library for JavaScript parsing.
90-
From the `third-party` directory, you can download the `duktape` source code from the official release:
89+
Mr.Docs embeds the `JerryScript` engine for JavaScript helpers.
90+
From the `third-party` directory, download the 3.0.0 source archive from the official repository:
9191
9292
[tabs]
9393
====
@@ -96,95 +96,47 @@ Windows PowerShell::
9696
--
9797
[source,bash]
9898
----
99-
Invoke-WebRequest -Uri "https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz" -OutFile "duktape-2.7.0.tar.xz" <.>
99+
Invoke-WebRequest -Uri "https://github.com/jerryscript-project/jerryscript/archive/refs/tags/v3.0.0.tar.gz" -OutFile "jerryscript-3.0.0.tar.gz" <.>
100100
----
101101
102-
<.> Downloads the `duktape` source code.
102+
<.> Downloads the `JerryScript` source code.
103103
--
104104
105105
Unix Variants::
106106
+
107107
--
108108
[source,bash]
109109
----
110-
curl -LJO https://github.com/svaarala/duktape/releases/download/v2.7.0/duktape-2.7.0.tar.xz <.>
110+
curl -LJO https://github.com/jerryscript-project/jerryscript/archive/refs/tags/v3.0.0.tar.gz <.>
111111
----
112112
113-
<.> Downloads the `duktape` source code.
113+
<.> Downloads the `JerryScript` source code.
114114
--
115115
====
116116
117-
Then patch the Duktape source code to provide CMake support.
117+
Patch the JerryScript source with our CMake shim and install it:
118118
119119
[source,bash]
120120
----
121-
tar -xf duktape-2.7.0.tar.xz <.>
122-
cp ../mrdocs/third-party/duktape/CMakeLists.txt ./duktape-2.7.0/CMakeLists.txt <.>
123-
cp ../mrdocs/third-party/duktape/duktapeConfig.cmake.in ./duktape-2.7.0/duktapeConfig.cmake.in <.>
124-
cd duktape-2.7.0
125-
----
126-
127-
<.> Extracts the `duktape` source code.
128-
<.> Patches the source code with a `CMakeLists.txt` file to the `duktape-2.7.0` directory so that we can build it with CMake.
129-
<.> Copies the `duktapeConfig.cmake.in` file to the `duktape-2.7.0` directory so that we can install it with CMake and find it later from other CMake projects.
130-
131-
Now adjust the `duk_config.h` file to indicate we are statically building Duktape.
121+
tar -xf jerryscript-3.0.0.tar.gz <.>
122+
cp ../mrdocs/third-party/patches/jerryscript/CMakeLists.txt ./jerryscript-3.0.0/CMakeLists.txt <.>
123+
cp ../mrdocs/third-party/patches/jerryscript/jerryscriptConfig.cmake.in ./jerryscript-3.0.0/jerryscriptConfig.cmake.in <.>
124+
cd jerryscript-3.0.0
132125
133-
[tabs]
134-
====
135-
Windows PowerShell::
136-
+
137-
--
138-
[source,bash]
139-
----
140-
$content = Get-Content -Path "src\duk_config.h" <.>
141-
$content = $content -replace '#define DUK_F_DLL_BUILD', '#undef DUK_F_DLL_BUILD' <.>
142-
$content | Set-Content -Path "src\duk_config.h" <.>
143-
----
144-
145-
<.> Read the content of `duk_config.h`
146-
<.> Replace the `DUK_F_DLL_BUILD` macro with `#undef DUK_F_DLL_BUILD`
147-
<.> Write the content back to the file
148-
--
149-
150-
Unix Variants::
151-
+
152-
--
153-
[source,bash]
154-
----
155-
sed -i 's/#define DUK_F_DLL_BUILD/#undef DUK_F_DLL_BUILD/g' "src/duk_config.h" <.>
156-
----
157-
158-
<.> Disables the `DUK_F_DLL_BUILD` macro in the `duk_config.h` file to indicate we are statically building duktape.
159-
--
160-
161-
MacOS::
162-
+
163-
--
164-
[source,bash]
165-
----
166-
sed -i '' 's/#define DUK_F_DLL_BUILD/#undef DUK_F_DLL_BUILD/g' src/duk_config.h <.>
167-
----
168-
169-
<.> Disables the `DUK_F_DLL_BUILD` macro in the `duk_config.h` file to indicate we are statically building duktape.
170-
--
171-
====
172-
173-
And finally install the library with CMake:
174-
175-
[source,bash]
176-
----
177-
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release <.>
178-
cmake --build ./build --config Release <.>
179-
cmake --install ./build --prefix ./install <.>
126+
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release \
127+
-DJERRY_PROFILE=es.next -DJERRY_CMDLINE=OFF -DJERRY_TESTS=OFF -DJERRY_DEBUGGER=OFF \
128+
-DJERRY_SNAPSHOT_SAVE=OFF -DJERRY_SNAPSHOT_EXEC=OFF \
129+
-DJERRY_MEM_STATS=OFF -DJERRY_PARSER_STATS=OFF -DJERRY_LINE_INFO=OFF \
130+
-DJERRY_LTO=OFF -DJERRY_LIBC=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL
131+
cmake --build ./build --config Release
132+
cmake --install ./build --prefix ./install
180133
----
181134
182-
<.> Configures the `duktape` library with CMake.
183-
<.> Builds the `duktape` library in the `build` directory.
184-
<.> Installs the `duktape` library with CMake support in the `install` directory.
135+
<.> Extracts the `JerryScript` source code.
136+
<.> Adds CMake packaging files maintained in this repository.
185137
186-
The scripts above download the `duktape` source code, extract it, and configure it with CMake.
187-
The CMake scripts provided by MrDocs are copied to the `duktape-2.7.0` directory to facilitate the build process with CMake and provide CMake installation scripts for other projects.
138+
The build uses JerryScript's upstream default port implementation; no custom
139+
`port.c` from MrDocs is required.
188140
189141
=== Libxml2
190142
@@ -317,7 +269,7 @@ cd ../..
317269
318270
The MrDocs repository also includes a `CMakePresets.json` file that contains the parameters to configure MrDocs with CMake.
319271
320-
To specify the installation directories, you can use the `LLVM_ROOT`, `DUKTAPE_ROOT`, and `LIBXML2_ROOT` environment variables.
272+
To specify the installation directories, you can use the `LLVM_ROOT`, `JERRYSCRIPT_ROOT`, and `LIBXML2_ROOT` environment variables.
321273
To specify a generator (`-G`) and platform name (`-A`), you can use the `CMAKE_GENERATOR` and `CMAKE_GENERATOR_PLATFORM` environment variables.
322274
323275
You can also customize the presets by duplicating and editing the `CMakeUserPresets.json.example` file in the `mrdocs` directory.

docs/mrdocs.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
"title": "Path to the Addons directory",
88
"type": "string"
99
},
10+
"addons-supplemental": {
11+
"default": [],
12+
"description": "Optional list of supplemental addons directories that are loaded after the base addons (built-in or replacement). Files in later supplemental directories override files from earlier ones and from the base addons. Use this to add or override a few templates/helpers without copying the entire addons tree.",
13+
"items": {
14+
"type": "string"
15+
},
16+
"title": "Additional addons layered on top of the base addons",
17+
"type": "array"
18+
},
1019
"auto-brief": {
1120
"default": true,
1221
"description": "When set to `true`, Mr.Docs uses the first line (until the first dot, question mark, or exclamation mark) of the comment as the brief of the symbol. When set to `false`, a explicit @brief command is required.",

0 commit comments

Comments
 (0)