Skip to content

Commit 17e30f5

Browse files
committed
Add experimental CI for release builds
1 parent 6d15cd0 commit 17e30f5

7 files changed

Lines changed: 181 additions & 12 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-linux:
8+
runs-on: ${{ matrix.runner }}
9+
container:
10+
image: almalinux:8
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
arch: [x64, arm64]
15+
include:
16+
- arch: x64
17+
runner: ubuntu-24.04
18+
- arch: arm64
19+
runner: ubuntu-24.04-arm
20+
21+
steps:
22+
- name: Install tools
23+
run: |
24+
dnf install -y epel-release
25+
dnf install -y --enablerepo powertools \
26+
gcc-toolset-14 cmake ninja-build \
27+
$(: CI requirements ) \
28+
git \
29+
$(: LLVM build requirements ) \
30+
python3 xz
31+
32+
- name: Checkout
33+
uses: actions/checkout@v6
34+
with:
35+
submodules: true
36+
37+
- name: Restore LLVM cache
38+
id: llvm-cache
39+
uses: actions/cache/restore@v5
40+
with:
41+
key: linux-${{ matrix.arch }}-llvm_22_1_8-v2
42+
path: llvm-out
43+
44+
- name: Download LLVM
45+
if: steps.llvm-cache.outputs.cache-hit != 'true'
46+
run: |
47+
ci/download_llvm.sh 22.1.8
48+
49+
- name: Build libclang
50+
if: steps.llvm-cache.outputs.cache-hit != 'true'
51+
run: |
52+
source /opt/rh/gcc-toolset-14/enable
53+
ci/build_llvm.sh
54+
55+
- name: Save LLVM cache
56+
if: steps.llvm-cache.outputs.cache-hit != 'true'
57+
uses: actions/cache/save@v5
58+
with:
59+
key: linux-${{ matrix.arch }}-llvm_22_1_8-v2
60+
path: llvm-out
61+
62+
- name: Build
63+
run: |
64+
source /opt/rh/gcc-toolset-14/enable
65+
cmake -B build -G Ninja \
66+
-D Clang_DIR=llvm-out/lib/cmake/clang \
67+
-D CMAKE_BUILD_TYPE=Release \
68+
-D MRBIND_STATIC_BUILD=ON \
69+
-D CMAKE_CXX_FLAGS="-ffunction-sections -fdata-sections" \
70+
-D CMAKE_EXE_LINKER_FLAGS="-Wl,--gc-sections -Wl,-s"
71+
cmake --build build --parallel $(nproc)
72+
73+
- name: Verify binaries
74+
run: |
75+
ls -l build/mrbind*
76+
ldd build/mrbind*
77+
78+
- name: Test
79+
run: |
80+
dnf install -y gcc-c++ findutils python38-devel
81+
export CLANG_RESOURCE_DIR="$(pwd)/llvm-out/lib/clang/22"
82+
source /opt/rh/gcc-toolset-14/enable
83+
echo g++ > examples/cxx.txt
84+
examples/c/run.sh
85+
PYTHON=python3.8 examples/python/run.sh

CMakeLists.txt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ if(WIN32 AND NOT MINGW)
2323
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
2424
endif()
2525

26-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
26+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2727
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstandalone-debug")
2828
endif()
29+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-conversion -Wno-extra-semi")
31+
endif()
2932

3033
include_directories(include src)
3134
include_directories(deps/cppdecl/include)
3235

3336

37+
option(MRBIND_STATIC_BUILD "Build the parser and the generators as static binaries." OFF)
38+
39+
3440
add_library(mrbind_common STATIC
3541
src/common/command_line_args_as_utf8.cpp
3642
src/common/command_line_parser.cpp
@@ -55,7 +61,7 @@ if(MRBIND_BUILD_PARSER)
5561
src/parser/multiplex_data.cpp
5662
)
5763

58-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GCC" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
64+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5965
set_source_files_properties(src/parser/disable_rtti.cpp PROPERTIES COMPILE_FLAGS -fno-rtti)
6066
endif()
6167

@@ -65,11 +71,19 @@ if(MRBIND_BUILD_PARSER)
6571

6672
target_include_directories(mrbind PRIVATE ${LLVM_INCLUDE_DIR} ${CLANG_INCLUDE_DIR})
6773

68-
# Clang lets you choose between large dynamic libraries, and fine-grained static libraries.
69-
# Those are the large dynamic ones. If they are not available for some reason,
70-
# we could switch to the static ones (probably conditionally here in CMake, by checking what's available).
71-
# See the git history to see some related static library names.
72-
target_link_libraries(mrbind PRIVATE LLVM clang-cpp)
74+
if(MRBIND_STATIC_BUILD)
75+
target_link_libraries(mrbind PRIVATE -static-libstdc++ -static-libgcc)
76+
if(NOT TARGET clangTooling)
77+
message(FATAL_ERROR "clangTooling is required for static builds")
78+
endif()
79+
target_link_libraries(mrbind PRIVATE clangTooling)
80+
else()
81+
# Clang lets you choose between large dynamic libraries, and fine-grained static libraries.
82+
# Those are the large dynamic ones. If they are not available for some reason,
83+
# we could switch to the static ones (probably conditionally here in CMake, by checking what's available).
84+
# See the git history to see some related static library names.
85+
target_link_libraries(mrbind PRIVATE LLVM clang-cpp)
86+
endif()
7387
endif()
7488

7589

@@ -123,6 +137,9 @@ if(MRBIND_BUILD_GENERATOR_C)
123137
mrbind_gen_common
124138
mrbind_c_interop
125139
)
140+
if(MRBIND_STATIC_BUILD)
141+
target_link_libraries(mrbind_gen_c PRIVATE -static-libstdc++ -static-libgcc)
142+
endif()
126143
endif()
127144

128145
if(MRBIND_BUILD_GENERATOR_CSHARP)
@@ -138,4 +155,7 @@ if(MRBIND_BUILD_GENERATOR_CSHARP)
138155
mrbind_gen_common
139156
mrbind_c_interop
140157
)
158+
if(MRBIND_STATIC_BUILD)
159+
target_link_libraries(mrbind_gen_csharp PRIVATE -static-libstdc++ -static-libgcc)
160+
endif()
141161
endif()

ci/build_llvm.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SRC_DIR=${1:-llvm-src/llvm}
5+
BUILD_DIR=llvm-build
6+
OUT_DIR=llvm-out
7+
8+
# triples may fail to be auto-detected correctly in some cases
9+
HOST_TRIPLE="$(uname -m)-unknown-linux-gnu"
10+
11+
cmake -G Ninja -S "$SRC_DIR" -B "$BUILD_DIR" \
12+
-DCMAKE_BUILD_TYPE=Release \
13+
-DCMAKE_INSTALL_PREFIX="$OUT_DIR" \
14+
-DCMAKE_INSTALL_LIBDIR=lib \
15+
-DLLVM_ENABLE_PROJECTS=clang \
16+
-DLLVM_TARGETS_TO_BUILD="Native" \
17+
-DLLVM_HOST_TRIPLE="$HOST_TRIPLE" \
18+
-DLLVM_DEFAULT_TARGET_TRIPLE="$HOST_TRIPLE" \
19+
-DBUILD_SHARED_LIBS=OFF \
20+
-DLLVM_BUILD_LLVM_DYLIB=OFF \
21+
-DLLVM_LINK_LLVM_DYLIB=OFF \
22+
-DLLVM_ENABLE_PIC=ON \
23+
-DLLVM_ENABLE_RTTI=OFF \
24+
-DLLVM_ENABLE_EH=OFF \
25+
-DLLVM_ENABLE_ASSERTIONS=OFF \
26+
-DLLVM_ENABLE_ZLIB=OFF \
27+
-DLLVM_ENABLE_ZSTD=OFF \
28+
-DLLVM_ENABLE_TERMINFO=OFF \
29+
-DLLVM_ENABLE_LIBXML2=OFF \
30+
-DLLVM_ENABLE_LIBEDIT=OFF \
31+
-DLLVM_ENABLE_LIBPFM=OFF \
32+
-DLLVM_ENABLE_CURL=OFF \
33+
-DLLVM_ENABLE_HTTPLIB=OFF \
34+
-DLLVM_INCLUDE_TESTS=OFF \
35+
-DLLVM_INCLUDE_EXAMPLES=OFF \
36+
-DLLVM_INCLUDE_BENCHMARKS=OFF \
37+
-DLLVM_INCLUDE_DOCS=OFF \
38+
-DCLANG_INCLUDE_TESTS=OFF \
39+
-DCLANG_INCLUDE_DOCS=OFF \
40+
-DCLANG_ENABLE_ARCMT=OFF \
41+
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
42+
"-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections" \
43+
"-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections"
44+
ninja -C "$BUILD_DIR" -j$(nproc) clangTooling
45+
46+
COMPONENTS="llvm-headers;clang-headers;clang-resource-headers;cmake-exports;clang-cmake-exports"
47+
for LIB in "$BUILD_DIR"/lib/lib*.a ; do
48+
LIBNAME="$(basename "$LIB" .a)"
49+
COMPONENTS="$COMPONENTS;${LIBNAME#lib}"
50+
done
51+
cmake -S "$SRC_DIR" -B "$BUILD_DIR" -DLLVM_DISTRIBUTION_COMPONENTS="$COMPONENTS"
52+
ninja -C "$BUILD_DIR" -j$(nproc) install-distribution

ci/download_llvm.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
LLVM_VERSION="${1:-22.1.0}"
5+
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz"
6+
7+
OUT_DIR="${2:-llvm-src}"
8+
9+
mkdir -p "$OUT_DIR"
10+
curl -fL "$LLVM_URL" | tar -xJ --strip-components=1 -C "$OUT_DIR"

examples/c/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ find input \( -name '*.h' -or -name '*.hpp' \) -printf "#include <%p>\n" >>c/out
6060
"${EXTRA_PARSER_FLAGS[@]}" \
6161
-- \
6262
-xc++-header \
63-
-resource-dir="$("$CLANG_CXX" -print-resource-dir)" \
63+
-resource-dir="${CLANG_RESOURCE_DIR:-$("$CLANG_CXX" -print-resource-dir)}" \
6464
-I. \
6565
"${EXTRA_PARSER_CXX_FLAGS[@]}"
6666

examples/csharp/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ find input \( -name '*.h' -or -name '*.hpp' \) -printf "#include <%p>\n" >>cshar
6565
"${EXTRA_PARSER_FLAGS[@]}" \
6666
-- \
6767
-xc++-header \
68-
-resource-dir="$("$CLANG_CXX" -print-resource-dir)" \
68+
-resource-dir="${CLANG_RESOURCE_DIR:-$("$CLANG_CXX" -print-resource-dir)}" \
6969
-I. \
7070
"${EXTRA_PARSER_CXX_FLAGS[@]}"
7171

examples/python/run.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ find input \( -name '*.h' -or -name '*.hpp' \) -printf "#include <%p>\n" >>pytho
5050
"${EXTRA_PARSER_FLAGS[@]}" \
5151
-- \
5252
-xc++-header \
53-
-resource-dir="$("$CLANG_CXX" -print-resource-dir)" \
53+
-resource-dir="${CLANG_RESOURCE_DIR:-$("$CLANG_CXX" -print-resource-dir)}" \
5454
-I. \
5555
"${EXTRA_PARSER_CXX_FLAGS[@]}"
5656

@@ -62,6 +62,8 @@ if [[ ! -d python/pybind11 ]]; then
6262
(cd python/pybind11 && git checkout d2413f5bca91a2c091b9b0801e0c1b5bf089e31d)
6363
fi
6464

65+
PYTHON=${PYTHON:-python3}
66+
6567
# Compile the Python module.
6668
# Note that the output filename must match the name passed to `-DMB_PB11_MODULE_NAME=`, minus the extension.
6769
"$CLANG_CXX" \
@@ -77,8 +79,8 @@ fi
7779
-DMB_PB11_MODULE_NAME=example \
7880
-DMB_DEFINE_IMPLEMENTATION \
7981
-DPYBIND11_COMPILER_TYPE='"_mrbind_example"' -DPYBIND11_BUILD_ABI='"_mrbind_example"' \
80-
$(pkg-config --cflags python3-embed) \
82+
$(${PYTHON}-config --cflags --embed) \
8183
"${EXTRA_CXX_FLAGS[@]}"
8284

8385
# Run a test program using the Python module.
84-
PYTHONPATH=python/output python3 python/example_consumer.py
86+
PYTHONPATH=python/output $PYTHON python/example_consumer.py

0 commit comments

Comments
 (0)