Skip to content

build: link the c++ runtime and the rust archive for every target - #133

Merged
HaoZeke merged 8 commits into
developfrom
land/fp-build-link-r4
Nov 27, 2026
Merged

HaoZeke merged 8 commits into
developfrom
land/fp-build-link-r4

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Links the C++ runtime and the Rust archive correctly for every target the meson build supports, in seven commits.

  • zstd and chemfiles link the C++ runtime, and the chemfiles scan matches the linked string ABI.
  • The Rust archive links with the meson compiler, cross compilers are kept when linking libstdc++, and meson's C link args are forwarded to cargo.
  • Android links libc++. armv7-linux-androideabi has no android component, so it now matches as an NDK target too, and a Linux host no longer puts its libstdc++ directory on LIBRARY_PATH for an Android cargo target.
  • scripts/check_cross_cmake.sh writes its cc and cxx wrappers from quoted heredocs, so the scratch path is not expanded into them. READCON_CROSS_INVOKED passes that path at run time, and test_cross_check_heredoc_does_not_interpolate_the_scratch_path covers it.

Note

Medium Risk
Touches native linking, CMake toolchains, and libstdc++ ABI selection for chemfiles—high impact on build portability but guarded by new CI checks and fail-fast probes.

Overview
Builds with zstd or chemfiles now emit explicit C++ runtime link metadata (libstdc++ on Linux, libc++ on Apple/Android), including a host-only scripts/libstdcxx.cmake wired through HOST_CMAKE_TOOLCHAIN_FILE so clang-as-c++ can link chemfiles-sys without host libstdc++ leaking into cross CMake configures.

Chemfiles C++ shim ABI is chosen at build time: new support/chemfiles_link.rs inspects the linked libchemfiles (via nm / DEP_CHEMFILES_*), sets _GLIBCXX_USE_CXX11_ABI when needed, and rejects conflicting CXXFLAGS overrides; the chosen ABI is exposed as READCON_CHEMFILES_STRING_ABI.

Meson → cargo integration is tightened: Meson writes compiler and c_link_args files; meson_cargo_build.py strips ccache wrappers, forwards the real CC/target linker, adds C++ runtime flags (with Android androideabi handling), and applies non-soname link args to the staticlib. CI adds jobs/scripts for clang chemfiles link, meson+ccache, and cross CMake compiler selection.

Reviewed by Cursor Bugbot for commit af109df. Bugbot is set up for automated code reviews on this repo. Configure here.

clang does not search gcc's libstdc++ directory, so chemfiles
configure fails with "cannot find -lstdc++" and the scan cannot
see <string>. name the runtime, search the directory g++ reports
before project(), and compile the scan with g++.
the prebuilt gcc 4.8 archive uses the old std::string, so an atom
is 80 bytes. the scan was built with the compiler default, 128
bytes, and indexing the frame aborted. nm of the linked library
selects the macro. both markers, or a cxxflags override, fail
the build.
cargo used its own linker while meson linked consumers with the
compiler it found. pass that compiler, not a ccache prefix, as cc
and as the linker for the cargo target.
a global cmake toolchain file makes cmake-rs skip the c and
c++ compiler it found. set the file for the host build only,
and leave the msvc linker as link.exe.
c_link_args never reached the rust archive. pass each one as
a link-arg, including the ones that are not -l.
the ndk uses libc++, so a linux stdc++ link does not apply
to android.
armv7-linux-androideabi has no android component, so meson still
asked for libstdc++ and the host g++ directory. match androideabi,
and keep that directory off an android library path. quote the
cross-check heredoc so it does not expand the scratch path.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8e1f0d1. Configure here.

Comment thread meson.build
]
if _needs_cxx
_stdcxx_dirs = _cxx_libdir != '' ? [_cxx_libdir] : []
_rust_sys_deps += cc.find_library('stdc++', dirs: _stdcxx_dirs, required: true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Host libstdc++ used for Linux cross

Medium Severity

The meson wrap still probes the build-machine g++ for libstdc++ whenever host_machine is Linux, and the cargo helper prepends that directory to LIBRARY_PATH for every non-Android target. build.rs already skips that path on cross compiles, so a Linux-to-Linux cross can still pick the wrong-architecture runtime.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e1f0d1. Configure here.

Comment thread build.rs
chemfiles_link::CppStdlib::Libcxx
} else {
chemfiles_link::CppStdlib::Libstdcxx
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android ABI fallback assumes libstdc++

Medium Severity

When the C++ stdlib preprocessor probe fails, cpp_stdlib() treats Android like libstdc++ even though this change links Android with libc++. That sends the chemfiles shim down the nm ABI path, which then fatals because NDK archives have neither __cxx11 nor ERKSs symbols.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e1f0d1. Configure here.

Comment thread build.rs
}
chemfiles_link::AbiChoice::Cxx11 => {
println!("cargo:rustc-env=READCON_CHEMFILES_STRING_ABI=cxx11");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cxx11 string ABI is not forced

Medium Severity

The chemfiles shim defines _GLIBCXX_USE_CXX11_ABI=0 for the old COW archive but does not define =1 when nm selects cxx11. A toolchain whose default libstdc++ ABI is still the gcc4-compatible string then compiles an 80-byte Atom against a 128-byte archive, which this change exists to prevent.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e1f0d1. Configure here.

Comment thread meson.build
elif host_machine.system() == 'android'
if _needs_cxx
_rust_sys_deps += cc.find_library('c++', required: true)
endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinGW meson wrap omits libstdc++

Low Severity

build.rs links stdc++ for windows-gnu when zstd or chemfiles is on, but the meson wrap's Windows branch never adds that library. MinGW consumers of the static archive then drop the C++ runtime that the new link logic is supposed to name on every target.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e1f0d1. Configure here.

ruff 0.15.2 puts the cargo helper calls on one line and wraps
the link-arg extend. no behavior change.
@HaoZeke
HaoZeke merged commit 4439cab into develop Nov 27, 2026
34 checks passed
@HaoZeke
HaoZeke deleted the land/fp-build-link-r4 branch November 27, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant