Skip to content

Commit 1165e80

Browse files
committed
fix for cpp version compatibility
1 parent 1ab3b2a commit 1165e80

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

.github/workflows/python-release.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,28 @@ jobs:
9191
9292
- name: Build wheel
9393
uses: PyO3/maturin-action@v1
94+
env:
95+
# Set C++14 standard for cross-compilation compatibility
96+
CXXFLAGS: "-std=c++14"
97+
CXX_aarch64_unknown_linux_gnu: "aarch64-linux-gnu-g++"
98+
CXXFLAGS_aarch64_unknown_linux_gnu: "-std=c++14"
9499
with:
95100
command: build
96101
args: --release --out dist --interpreter python3.10
97102
working-directory: python/pecos-rslib
98103
target: ${{ matrix.architecture == 'aarch64' && (matrix.os == 'macos-latest' && 'aarch64-apple-darwin' || 'aarch64-unknown-linux-gnu') || (matrix.os == 'macos-latest' && 'x86_64-apple-darwin' || '') }}
99104
manylinux: auto
100105
before-script-linux: |
106+
# Install dependencies and ensure modern C++ compiler
101107
if command -v yum &> /dev/null; then
102-
yum install -y openssl-devel
108+
yum install -y openssl-devel gcc-c++ libstdc++-devel
109+
# For manylinux, install newer gcc if needed
110+
if [ "${{ matrix.architecture }}" = "aarch64" ]; then
111+
yum install -y devtoolset-10-gcc-c++ || true
112+
source /opt/rh/devtoolset-10/enable 2>/dev/null || true
113+
fi
103114
elif command -v apt-get &> /dev/null; then
104-
apt-get update && apt-get install -y libssl-dev pkg-config
115+
apt-get update && apt-get install -y libssl-dev pkg-config g++ libstdc++-11-dev
105116
else
106117
echo "No supported package manager found"
107118
exit 1

crates/pecos-cppsparsesim/build.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
fn main() {
22
// Build C++ source files
3-
cc::Build::new()
3+
let mut build = cc::Build::new();
4+
build
45
.cpp(true)
56
.file("src/sparsesim.cpp")
67
.file("src/cxx_shim.cpp")
7-
.include("src")
8-
.std("c++14")
9-
.compile("sparsesim");
8+
.include("src");
9+
10+
// Use C++14 or newer to avoid issues with older cross-compilers
11+
// that don't fully support C++11 type traits like is_trivially_move_constructible
12+
let target = std::env::var("TARGET").unwrap_or_default();
13+
14+
// For cross-compilation (especially aarch64), we need at least C++14
15+
// to ensure type traits are available
16+
if target.contains("aarch64") || target.contains("arm") {
17+
// Try C++17 first, fall back to C++14
18+
if !build.is_flag_supported("-std=c++17").unwrap_or(false) {
19+
build.std("c++14");
20+
} else {
21+
build.std("c++17");
22+
}
23+
} else {
24+
build.std("c++14");
25+
}
26+
27+
build.compile("sparsesim");
1028

11-
// Generate cxx bridge code
12-
cxx_build::bridge("src/lib.rs")
13-
.file("src/cxx_shim.cpp")
14-
.std("c++14")
15-
.compile("cppsparsesim-bridge");
29+
// Generate cxx bridge code with same C++ standard
30+
let mut bridge = cxx_build::bridge("src/lib.rs");
31+
bridge.file("src/cxx_shim.cpp");
32+
33+
// Match the same C++ standard for cxx bridge
34+
if target.contains("aarch64") || target.contains("arm") {
35+
if !bridge.is_flag_supported("-std=c++17").unwrap_or(false) {
36+
bridge.std("c++14");
37+
} else {
38+
bridge.std("c++17");
39+
}
40+
} else {
41+
bridge.std("c++14");
42+
}
43+
44+
bridge.compile("cppsparsesim-bridge");
1645

1746
// Tell cargo to rerun if source files change
1847
println!("cargo:rerun-if-changed=src/lib.rs");

crates/pecos-ldpc-decoders/build_ldpc.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,26 @@ fn build_cxx_bridge(ldpc_dir: &Path) -> Result<()> {
191191
let mut build = cxx_build::bridge("src/bridge.rs");
192192
build
193193
.file("src/bridge.cpp")
194-
.std("c++17")
195194
.include(&src_cpp_dir)
196195
.include(&include_dir)
197196
.include(include_dir.join("robin_map"))
198197
.include(include_dir.join("rapidcsv"))
199198
.include("include");
199+
200+
// Use C++17 when available, fall back to C++14 for older compilers
201+
// This helps with cross-compilation where older toolchains may not fully support C++17
202+
let target = env::var("TARGET").unwrap_or_default();
203+
if target.contains("aarch64") || target.contains("arm") {
204+
// For ARM targets, check what's supported
205+
if !build.is_flag_supported("-std=c++17").unwrap_or(false) {
206+
build.std("c++14");
207+
} else {
208+
build.std("c++17");
209+
}
210+
} else {
211+
// For other targets, use C++17
212+
build.std("c++17");
213+
}
200214

201215
// Report ccache/sccache configuration
202216
report_cache_config();

0 commit comments

Comments
 (0)