Skip to content

Commit ce34057

Browse files
authored
feat: reproducible standard library outputs
1 parent 99f4608 commit ce34057

File tree

17 files changed

+288
-153
lines changed

17 files changed

+288
-153
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ jobs:
104104
cd fmt
105105
cmake -S . -B ./build -D FMT_DOC=OFF -D FMT_TEST=OFF -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_CXX_COMPILER=${{ steps.setup-cpp.outputs.cxx }} -DCMAKE_C_COMPILER=${{ steps.setup-cpp.outputs.cc }}
106106
N_CORES=$(nproc 2>/dev/null || echo 1)
107-
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
107+
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
108108
cmake --install ./build --prefix ./install
109-
109+
110110
fmt_root=$(pwd)/install
111111
if [[ ${{ runner.os }} == 'Windows' ]]; then
112112
fmt_root=$(echo "$fmt_root" | sed 's/\\/\//g')
@@ -135,9 +135,9 @@ jobs:
135135
fi
136136
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_CXX_COMPILER=${{ steps.setup-cpp.outputs.cxx }} -DCMAKE_C_COMPILER=${{ steps.setup-cpp.outputs.cc }}
137137
N_CORES=$(nproc 2>/dev/null || echo 1)
138-
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
138+
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
139139
cmake --install ./build --prefix ./install
140-
140+
141141
duktape_root=$(pwd)/install
142142
if [[ ${{ runner.os }} == 'Windows' ]]; then
143143
duktape_root=$(echo "$duktape_root" | sed 's/\\/\//g')
@@ -159,12 +159,12 @@ jobs:
159159
git config --global advice.detachedHead false
160160
git clone https://github.com/GNOME/libxml2 --branch v2.12.6 --depth 1
161161
cd libxml2
162-
162+
163163
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -DLIBXML2_WITH_PROGRAMS=ON -DLIBXML2_WITH_FTP=OFF -DLIBXML2_WITH_HTTP=OFF -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_LEGACY=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_ZLIB=OFF -DLIBXML2_WITH_ICU=OFF -DLIBXML2_WITH_TESTS=OFF -DLIBXML2_WITH_HTML=ON -DLIBXML2_WITH_C14N=ON -DLIBXML2_WITH_CATALOG=ON -DLIBXML2_WITH_DEBUG=ON -DLIBXML2_WITH_ISO8859X=ON -DLIBXML2_WITH_MEM_DEBUG=OFF -DLIBXML2_WITH_MODULES=ON -DLIBXML2_WITH_OUTPUT=ON -DLIBXML2_WITH_PATTERN=ON -DLIBXML2_WITH_PUSH=ON -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_READER=ON -DLIBXML2_WITH_REGEXPS=ON -DLIBXML2_WITH_SAX1=ON -DLIBXML2_WITH_SCHEMAS=ON -DLIBXML2_WITH_SCHEMATRON=ON -DLIBXML2_WITH_THREADS=ON -DLIBXML2_WITH_THREAD_ALLOC=OFF -DLIBXML2_WITH_TREE=ON -DLIBXML2_WITH_VALID=ON -DLIBXML2_WITH_WRITER=ON -DLIBXML2_WITH_XINCLUDE=ON -DLIBXML2_WITH_XPATH=ON -DLIBXML2_WITH_XPTR=ON -DCMAKE_CXX_COMPILER=${{ steps.setup-cpp.outputs.cxx || steps.parameters.outputs.clang-bin }} -DCMAKE_C_COMPILER=${{ steps.setup-cpp.outputs.cc || steps.parameters.outputs.clang-bin }}
164164
N_CORES=$(nproc 2>/dev/null || echo 1)
165-
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
165+
cmake --build ./build --config ${{ matrix.build-type }} --parallel $N_CORES
166166
cmake --install ./build --prefix ./install
167-
167+
168168
libxml2_root=$(pwd)/install
169169
if [[ ${{ runner.os }} == 'Windows' ]]; then
170170
libxml2_root=$(echo "$libxml2_root" | sed 's/\\/\//g')
@@ -193,7 +193,7 @@ jobs:
193193
uses: actions/cache@v4
194194
with:
195195
path: ${{ steps.llvm-parameters.outputs.llvm-root }}
196-
key: llvm-${{ runner.os }}-${{ matrix.compiler }}-${{ matrix.version }}-${{ steps.llvm-parameters.outputs.llvm-build-preset }}-${{ steps.llvm-parameters.outputs.llvm-hash }}
196+
key: llvm-libcxx-${{ runner.os }}-${{ matrix.compiler }}-${{ matrix.version }}-${{ steps.llvm-parameters.outputs.llvm-build-preset }}-${{ steps.llvm-parameters.outputs.llvm-hash }}
197197

198198
- name: Install LLVM
199199
id: llvm-install
@@ -202,7 +202,7 @@ jobs:
202202
run: |
203203
# LLVM is be installed with the default compiler
204204
set -x
205-
205+
206206
# Shallow clone LLVM_HASH in ../third-party/llvm
207207
cd ..
208208
mkdir -p third-party/llvm-project
@@ -218,19 +218,56 @@ jobs:
218218
# Copy presets
219219
cp ../../mrdocs/third-party/llvm/CMakePresets.json ./llvm
220220
cp ../../mrdocs/third-party/llvm/CMakeUserPresets.json.example ./llvm/CMakeUserPresets.json
221-
221+
222222
# Build
223223
cd llvm
224224
llvm_root=$(pwd)
225225
cmake --version
226226
cmake -S . -B ./build --preset=${{ steps.llvm-parameters.outputs.llvm-build-preset }} -DCMAKE_CXX_COMPILER=${{ steps.setup-cpp.outputs.cxx }} -DCMAKE_C_COMPILER=${{ steps.setup-cpp.outputs.cc }}
227227
if [[ ${{ runner.os }} == 'Linux' ]]; then
228228
cmake --build ./build --target help
229-
fi
229+
fi
230230
N_CORES=$(nproc 2>/dev/null || echo 1)
231231
cmake --build ./build --config Release --parallel $N_CORES
232232
cmake --install ./build --prefix "$llvm_project_root"/install
233233
234+
- name: Install LibC++
235+
id: libcxx-install
236+
if: steps.llvm-cache.outputs.cache-hit != 'true'
237+
shell: bash
238+
run: |
239+
set -x
240+
cd ../third-party/llvm-project
241+
llvm_project_root=$(pwd)
242+
243+
export CXX="$llvm_project_root/install/bin/clang++"
244+
export CC="$llvm_project_root/install/bin/clang"
245+
246+
if [[ ${{ runner.os }} != 'Windows' ]]; then
247+
cmake -G Ninja \
248+
-S runtimes \
249+
-B build-libcxx \
250+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
251+
-DCMAKE_INSTALL_PREFIX="$llvm_project_root/install"
252+
253+
ninja -C build-libcxx cxx cxxabi unwind
254+
ninja -C build-libcxx install-cxx install-cxxabi install-unwind
255+
else
256+
cmake -G Ninja \
257+
-S runtimes \
258+
-B build-libcxx \
259+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
260+
-DCMAKE_INSTALL_PREFIX="$llvm_project_root/install" \
261+
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
262+
-DLIBCXXABI_ENABLE_SHARED=OFF \
263+
-DLIBCXXABI_ENABLE_STATIC=ON \
264+
-DLIBCXX_ENABLE_SHARED=OFF \
265+
-DLIBCXX_NO_VCRUNTIME=ON \
266+
-DCMAKE_CXX_FLAGS="-D__ORDER_LITTLE_ENDIAN__=1234 -D__ORDER_BIG_ENDIAN__=4321 -D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__"
267+
ninja -C build-libcxx cxx
268+
ninja -C build-libcxx install-cxx
269+
fi
270+
234271
- name: Install Node.js
235272
uses: actions/setup-node@v3
236273
with:
@@ -256,7 +293,7 @@ jobs:
256293
-D duktape_ROOT=${{ steps.duktape-install.outputs.duktape-root }}
257294
-D Duktape_ROOT=${{ steps.duktape-install.outputs.duktape-root }}
258295
-D fmt_ROOT=${{ steps.fmt-install.outputs.fmt-root }}
259-
${{ (steps.libxml2-install.outputs.libxml2-root && format('-D libxml2_ROOT={0}', steps.libxml2-install.outputs.libxml2-root)) || '' }}
296+
${{ (steps.libxml2-install.outputs.libxml2-root && format('-D libxml2_ROOT={0}', steps.libxml2-install.outputs.libxml2-root)) || '' }}
260297
${{ (steps.libxml2-install.outputs.libxml2-root && format('-D LibXml2_ROOT={0}', steps.libxml2-install.outputs.libxml2-root)) || '' }}
261298
export-compile-commands: true
262299
run-tests: true
@@ -296,27 +333,17 @@ jobs:
296333
run:
297334
shell: bash
298335
name: Releases
299-
timeout-minutes: 30
300-
runs-on: ubuntu-20.04
301-
container: ubuntu:23.04
336+
timeout-minutes: 30
337+
runs-on: ubuntu-latest
338+
container: ubuntu:20.04
302339
permissions:
303340
contents: write
304341
steps:
305-
- name: Setup C++
306-
uses: alandefreitas/cpp-actions/[email protected]
307-
id: setup-cpp
308-
with:
309-
compiler: clang
310-
version: 16
311-
check-latest: true
312-
313342
- name: Install packages
314343
uses: alandefreitas/cpp-actions/[email protected]
315344
id: package-install
316345
with:
317-
apt-get: libstdc++-12-dev asciidoctor cmake bzip2 git
318-
cc: ${{ steps.setup-cpp.outputs.cc }}
319-
cxx: ${{ steps.setup-cpp.outputs.cxx }}
346+
apt-get: build-essential asciidoctor cmake bzip2 git
320347

321348
- name: Clone mrdocs
322349
uses: actions/checkout@v4
@@ -344,8 +371,6 @@ jobs:
344371
mrdocs --version
345372
MRDOCS_ROOT=/usr/local
346373
echo -e "MRDOCS_ROOT=$MRDOCS_ROOT" >> $GITHUB_ENV
347-
CXX=/usr/bin/clang-16
348-
echo -e "CXX=$CXX" >> $GITHUB_ENV
349374
350375
- name: Clone Boost.URL
351376
uses: alandefreitas/cpp-actions/[email protected]
@@ -398,11 +423,6 @@ jobs:
398423
399424
- name: Generate Demos
400425
run: |
401-
CXX="${{ steps.setup-cpp.outputs.cxx }}"
402-
export CXX
403-
CC="${{ steps.setup-cpp.outputs.cc }}"
404-
export CC
405-
406426
declare -a generators=(
407427
"adoc"
408428
"xml"
@@ -443,15 +463,15 @@ jobs:
443463
id: compare-demos
444464
run: |
445465
set -x
446-
466+
447467
# Define URLs and directories
448468
LOCAL_DEMOS_DIR="./demos/"
449469
PREV_DEMOS_DIR="./demos-previous/"
450470
DIFF_DIR="./demos-diff/"
451-
471+
452472
# Create directories if they don't exist
453473
mkdir -p $PREV_DEMOS_DIR $DIFF_DIR
454-
474+
455475
# Iterate over the previous files and compare them with the corresponding local files
456476
find $PREV_DEMOS_DIR -type f | while read previous_file; do
457477
# Derive the corresponding local file path
@@ -469,7 +489,7 @@ jobs:
469489
cat "$previous_file" >> "$diff_output"
470490
fi
471491
done
472-
492+
473493
# Iterate over the local files to find new files
474494
find $LOCAL_DEMOS_DIR -type f | while read local_file; do
475495
previous_file="${PREV_DEMOS_DIR}${local_file#$LOCAL_DEMOS_DIR}"
@@ -480,7 +500,7 @@ jobs:
480500
echo "NEW CONTENT OF THE FILE IS:" >> "$diff_output"
481501
fi
482502
done
483-
503+
484504
# Check if the diff directory is empty
485505
if [[ -z $(ls -A $DIFF_DIR) ]]; then
486506
echo "No differences found."

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
/test-files/**/*.adoc
1111
/test-files/**/*.bad.xml
1212
docs/node_modules
13-
docs/build
13+
docs/build
14+
share/mrdocs/libcxx/
15+
share/mrdocs/clang/

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ elseif (LLVM_ROOT)
9292
endif()
9393
find_package(LLVM REQUIRED CONFIG)
9494
find_package(Clang REQUIRED CONFIG)
95+
96+
if (LLVM_ROOT)
97+
set(LIBCXX_DIR "${LLVM_ROOT}/include/c++/v1/")
98+
set(STDLIB_INCLUDE_DIR "${LLVM_ROOT}/lib/clang/${Clang_VERSION_MAJOR}/include/")
99+
endif()
100+
95101
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
96102
include(HandleLLVMOptions)
97103
add_definitions(${LLVM_DEFINITIONS})
@@ -337,7 +343,9 @@ if (MRDOCS_BUILD_TESTS)
337343
--unit=false
338344
--action=test
339345
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
340-
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons")
346+
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
347+
--system-includes="${LIBCXX_DIR}"
348+
--system-includes="${STDLIB_INCLUDE_DIR}")
341349
foreach (action IN ITEMS create update)
342350
add_custom_target(
343351
mrdocs-${action}-test-fixtures
@@ -347,6 +355,8 @@ if (MRDOCS_BUILD_TESTS)
347355
--action=${action}
348356
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
349357
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
358+
--system-includes="${LIBCXX_DIR}"
359+
--system-includes="${STDLIB_INCLUDE_DIR}"
350360
DEPENDS mrdocs-test
351361
)
352362
endforeach ()
@@ -492,6 +502,13 @@ if (MRDOCS_INSTALL)
492502
#-------------------------------------------------
493503
# share
494504
#-------------------------------------------------
505+
install(DIRECTORY ${LIBCXX_DIR}
506+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/libcxx
507+
FILES_MATCHING PATTERN "*")
508+
install(DIRECTORY ${STDLIB_INCLUDE_DIR}
509+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/clang
510+
FILES_MATCHING PATTERN "*")
511+
495512
foreach (share_mrdocs_dir addons)
496513
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/mrdocs/${share_mrdocs_dir}
497514
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs

docs/modules/ROOT/pages/install.adoc

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,102 @@ cmake --install ./build --prefix ../install
382382

383383
Replace 4 with the number of cores you want to use for building LLVM.
384384

385-
Return from `./third-party/llvm-project/llvm` to the parent directory to build and install MrDocs:
385+
Return from `./third-party/llvm-project/llvm` to the LLVM project directory:
386386

387387
[source,bash]
388388
----
389-
cd ../../..
389+
cd ../..
390+
----
391+
392+
=== LibC++
393+
394+
In addition to LLVM, MrDocs requires a deterministic version of the C++ standard library (LibC++) to ensure consistent behavior across various environments. This step is crucial for replicating specific compiler and library configurations.
395+
396+
**Download**:
397+
398+
Continue using the same LLVM project directory.
399+
400+
**Configure**:
401+
402+
Configure and build LibC++ using the existing structure:
403+
404+
[source,bash]
405+
----
406+
export CXX="./install/bin/clang++"
407+
export CC="./install/bin/clang"
408+
----
409+
410+
Run a command such as the following to configure LLVM:
411+
412+
[tabs]
413+
====
414+
Windows PowerShell::
415+
+
416+
--
417+
[source,bash]
418+
----
419+
cmake -G Ninja \
420+
-S runtimes \
421+
-B build-libcxx \
422+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
423+
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
424+
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
425+
-DLIBCXXABI_ENABLE_SHARED=OFF \
426+
-DLIBCXXABI_ENABLE_STATIC=ON \
427+
-DLIBCXX_ENABLE_SHARED=OFF \
428+
-DLIBCXX_NO_VCRUNTIME=ON \
429+
-DCMAKE_CXX_FLAGS="-D__ORDER_LITTLE_ENDIAN__=1234 -D__ORDER_BIG_ENDIAN__=4321 -D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__"
430+
----
431+
--
432+
433+
Unix Variants::
434+
+
435+
--
436+
[source,bash]
437+
----
438+
cmake -G Ninja \
439+
-S runtimes \
440+
-B build-libcxx \
441+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
442+
-DCMAKE_INSTALL_PREFIX="$(pwd)/install"
390443
----
444+
--
445+
====
446+
447+
**Build**:
448+
449+
Build and install the configured version of LibC++ with:
450+
451+
[tabs]
452+
====
453+
Windows PowerShell::
454+
+
455+
--
456+
[source,bash]
457+
----
458+
ninja -C build-libcxx cxx
459+
ninja -C build-libcxx install-cxx
460+
----
461+
--
462+
463+
Unix Variants::
464+
+
465+
--
466+
[source,bash]
467+
----
468+
ninja -C build-libcxx cxx cxxabi unwind
469+
ninja -C build-libcxx install-cxx install-cxxabi install-unwind
470+
----
471+
--
472+
====
473+
474+
Return from `./third-party/llvm-project` to the parent directory to build and install MrDocs:
475+
476+
[source,bash]
477+
----
478+
cd ../..
479+
----
480+
391481

392482
=== MrDocs
393483

docs/website/render.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ for (let panel of data.panels) {
5757

5858
// Create a CMakeLists.txt file for the snippet
5959
const cmakeListsPath = path.join(absSnippetsDir, 'CMakeLists.txt')
60-
fs.writeFileSync(cmakeListsPath, `cmake_minimum_required(VERSION 3.13)\nproject(${sourceBasename})\nadd_executable(${sourceBasename} ${panel.source})\n`)
60+
const cmakeListsContent = `cmake_minimum_required(VERSION 3.13)\nproject(${sourceBasename})\nadd_executable(${sourceBasename} ${panel.source})\n`
61+
fs.writeFileSync(cmakeListsPath, cmakeListsContent)
6162

6263
// Run mrdocs to generate documentation
6364
const mrdocsConfig = path.join(absSnippetsDir, 'mrdocs.yml')

0 commit comments

Comments
 (0)