Skip to content

cmake: recognise AppleClang and arm64 - #71887

Merged
tchaikov merged 6 commits into
ceph:mainfrom
dvanders:wip-macos-5-cmake-apple
Oct 14, 2026
Merged

tchaikov merged 6 commits into
ceph:mainfrom
dvanders:wip-macos-5-cmake-apple

Conversation

@dvanders

Copy link
Copy Markdown
Contributor

Split out of #71232, which reviewers asked to see in smaller batches.
Based on main; independent of the other six.

Four things cmake does not currently recognise:

  • CMAKE_CXX_COMPILER_ID STREQUAL Clang does not match AppleClang, so
    the -Wsign-compare option and the C++20 version check were both skipped
    there. MATCHES "Clang" covers both.
  • BuildBoost.cmake picks its toolset the same way, and needs target-os
    and an architecture/address-model pair to build Mach-O; the
    self-built Boost.Locale also needs its iconv dependency named.
  • CMAKE_SYSTEM_PROCESSOR is arm64 on Darwin, not aarch64, so
    SIMDExt.cmake and BuildISAL.cmake treated an ARMv8 machine as 32-bit
    ARM and left the accelerated paths out.
  • getentropy() is declared in <sys/random.h> on some platforms rather
    than <unistd.h>, so HAVE_GETENTROPY came out false where the function
    exists.

The arm64 match is what turns on hardware crc32c, NEON gf-complete and the
ISA-L erasure code plugin on Apple silicon; it should be a no-op on
aarch64 Linux, which already matched.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

🤖 Generated with Claude Code

Comment thread cmake/modules/BuildISAL.cmake Resolved
Comment thread cmake/modules/BuildBoost.cmake Resolved

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks great, apart from two nits.

The probe only looked in <unistd.h>.  Darwin declares getentropy() in
<sys/random.h>, so HAVE_GETENTROPY was never set there and CryptoRandom fell
back to reading /dev/urandom even though the system call is available.

Probe both headers and expose HAVE_SYS_RANDOM_H so Crypto.cc can include the
right one.  <unistd.h> is still checked on its own, so platforms that ship a
<sys/random.h> which does not declare getentropy() are unaffected.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
CMAKE_CXX_COMPILER_ID is "AppleClang", not "Clang", for the compiler shipped
with Xcode and the Command Line Tools, so both STREQUAL tests were false there
and the whole clang branch was skipped.  That branch supplies -Wsign-compare,
a number of -Wno-* options, and -undefined dynamic_lookup, which the cls
plugins need in order to link against symbols the OSD provides at runtime.

Use MATCHES, which covers both spellings, as BuildISAL.cmake already does.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
do_build_boost() maps CMAKE_CXX_COMPILER_ID onto a b2 toolset name, and
tested for the id "Clang" exactly.  The compiler shipped with Xcode and the
Command Line Tools reports "AppleClang", so the test was false and configure
stopped at "unknown compiler: AppleClang", leaving WITH_SYSTEM_BOOST=OFF
unusable on macOS.

Use MATCHES, as src/CMakeLists.txt and BuildISAL.cmake already do.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
do_build_boost() passes binary-format=elf whenever the processor is an arm,
which is how boost.context chooses between its arm64 assembly variants.  On
Darwin that is the wrong half: it picks jump_arm64_aapcs_elf_gas.S and the
rest of the elf set, whose .type, .size and .section directives clang then
rejects, so the whole external boost build fails.

Say mach-o there instead, and leave every other arm target on elf.  With this
and the toolset fix before it, WITH_SYSTEM_BOOST=OFF works on macOS, which
matters because it is the only way to get Boost.Python built against the same
interpreter as the rest of the tree - homebrew ships it in a separate formula
built against whichever [email protected] that formula happens to pin.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
BuildBoost.cmake assembles the Boost::* imported targets itself, and the
only thing it puts in INTERFACE_LINK_LIBRARIES is Boost's own inter
component dependencies from the hardcoded list above.  Boost.Locale's
external dependency on iconv is not among them, and Boost's generated
CMake config - which does record it - is never consulted, because
BuildBoost defines Boost::locale first.

glibc provides the iconv functions, so on Linux nothing notices.  Darwin
keeps them in a separate libiconv, where the omission is fatal for the
first executable to pull libboost_locale.a onto its link line, and
ceph-fuse is that executable:

  Undefined symbols for architecture arm64:
    "_iconv_open", referenced from:
        boost::locale::conv::impl::iconverter_base::do_open(...)

Ask for Iconv::Iconv, which is what Boost's own config does.  CMake's
FindIconv reports the built-in case as an empty interface target, so
this stays a no-op wherever libc already carries iconv.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
Apple's toolchain reports CMAKE_SYSTEM_PROCESSOR as "arm64", which does
not match the "aarch64|AARCH64" arm of SIMDExt.cmake but does match the
"arm|ARM" arm that follows it, since MATCHES is an unanchored regex.
Apple silicon therefore took the 32 bit ARM path: HAVE_ARM came out
right, but the only feature test run was -mfpu=neon, which Apple clang
rejects for a 64 bit target.  Everything gated on the ARMv8 results
stayed off, so on Darwin/arm64:

* crc32c_aarch64.c was never compiled and crc32c fell back to the
  portable sctp table, at 1263 MB/s against 7383 MB/s for the CRC32
  instructions,
* gf-complete was built without ARM_NEON, so jerasure and shec used the
  table based GF arithmetic,
* WITH_EC_ISA_PLUGIN, which keys off HAVE_ARMV8_SIMD, stayed off, so
  there was no ISA-L erasure code plugin at all,
* the zlib compressor was built without the ISA-L igzip sources.

Add arm64 to the ARMv8 arm of SIMDExt.cmake, and to the ARM test in
BuildISAL.cmake that adds the assembler flag the SVE sources need.

This alone builds crc32c_aarch64.c but does not select it on Darwin:
ceph_arch_aarch64_crc32 stays 0, and crc32c keeps using sctp, until
"arch/arm: probe the ARM CPU features through sysctl on Darwin" (ceph#71889)
also lands.  The 7383 MB/s above needs both.
The SVE code stays dead on Apple silicon, which has no SVE: ISA-L's
aarch64 dispatchers already special case __APPLE__ and return the NEON
implementations there, having no getauxval() to ask.

Deliberately not touched are the WITH_SPDK and WITH_UADK conditions,
which also spell only aarch64.  Both are Linux only for other reasons.

Verified on Darwin arm64 with the unit tests for crc32c, compression
and every erasure code plugin, and on a vstart memstore cluster with an
ISA-L k=2 m=1 pool: a 32 MiB object read back byte identical both with
the full acting set and with one shard's OSD stopped.

Assisted-by: claude-code:claude-opus-5
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders
dvanders force-pushed the wip-macos-5-cmake-apple branch from d92f1b4 to 0467a40 Compare October 1, 2026 22:12
@dvanders

dvanders commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@tchaikov

tchaikov commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@dvanders did you get a chance to push this branch to ceph-ci to verify that it still builds on all configured distros?

@dvanders

dvanders commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@dvanders did you get a chance to push this branch to ceph-ci to verify that it still builds on all configured distros?

Pushed to ceph-ci as wip-dvanders-macos-cmake-apple, and all builds completed: CentOS 9, Rocky 10 and Ubuntu 22.04/24.04/26.04, default and debug flavours: https://shaman.ceph.com/builds/ceph/wip-dvanders-macos-cmake-apple/. ceph-ci builds wip branches for x86_64 only; arm64 is covered by the PR's make check (arm64), which passed on this head.

@dvanders

Copy link
Copy Markdown
Contributor Author

@tchaikov the ceph-ci builds passed on all distros (results above). Could you merge this when you get a chance?

@tchaikov
tchaikov merged commit 558b794 into ceph:main Oct 14, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants