Skip to content

Remove macOS SDK dependency from libvec native build#145066

Merged
ldematte merged 2 commits intoelastic:mainfrom
ldematte:native/darwin-libc-free
Mar 27, 2026
Merged

Remove macOS SDK dependency from libvec native build#145066
ldematte merged 2 commits intoelastic:mainfrom
ldematte:native/darwin-libc-free

Conversation

@ldematte
Copy link
Copy Markdown
Contributor

@ldematte ldematte commented Mar 27, 2026

Summary

  • Introduce minimal C++ standard library headers (tinystd/) for Darwin cross-compilation, eliminating the dependency on the macOS SDK's libc++ headers
  • Replace explicit libc function calls with compiler builtins: fmax()__builtin_fmaxf(), sqrt()__builtin_sqrt()
  • Remove unused #include <math.h>, <assert.h>, <stdio.h>, <TargetConditionals.h> from all source files
  • Update build.gradle to use -nostdinc + tinystd for Darwin/clang builds

Why?

The Darwin build currently depends on the macOS SDK for C/C++ standard library headers. This is a problem for the cross-compilation Docker pipeline (#144845), where including the proprietary SDK in a public image has licensing concerns. By providing our own minimal headers for the C++ stdlib features we actually use, we can compile for Darwin without any SDK.

The tinystd headers compile to identical machine code as the real standard library (verified with objdump --disassemble). Linux builds are unaffected — they continue to use the real libstdc++.

Source code improvements

  • fmax()__builtin_fmaxf() — fixes a subtle bug where the double variant caused unnecessary fcvt float↔double conversions on ARM
  • sqrt()__builtin_sqrt() — explicit builtin, doesn't rely on optimizer to inline
  • <cstdint><stdint.h> in vec.h — freestanding header, no C++ wrapper needed
  • Removed 2 runtime assert() calls and <assert.h> from vec_common.h

Test plan

  • ./gradlew vecAarch64SharedLibrary builds on macOS with tinystd (no SDK headers)
  • All JDKVectorLibrary* tests pass on macOS with the locally built library
  • Verified on native/docker-cross-compile branch: all 3 platforms (darwin-aarch64, linux-aarch64, linux-x64) build and pass tests
  • Codegen verified identical to SDK-built version via objdump

Prerequisite for #144845 (cross-compilation pipeline).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@elasticsearchmachine elasticsearchmachine added v9.4.0 needs:triage Requires assignment of a team area label labels Mar 27, 2026
@ldematte ldematte requested a review from a team as a code owner March 27, 2026 08:09
@ldematte ldematte added :Search Relevance/Vectors Vector search >refactoring and removed needs:triage Requires assignment of a team area label labels Mar 27, 2026
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Mar 27, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Copy Markdown
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. Looks great.

@ldematte ldematte merged commit 6fb560d into elastic:main Mar 27, 2026
36 checks passed
@ldematte ldematte deleted the native/darwin-libc-free branch March 27, 2026 13:12
mamazzol pushed a commit to mamazzol/elasticsearch that referenced this pull request Mar 30, 2026
Introduce minimal C++ standard library headers (tinystd/) for Darwin cross-compilation, eliminating the dependency on the macOS SDK's libc++ headers
Replace explicit libc function calls with compiler builtins: fmax() → __builtin_fmaxf(), sqrt() → __builtin_sqrt()
Remove unused #include <math.h>, <assert.h>, <stdio.h>, <TargetConditionals.h> from all source files
Update build.gradle to use -nostdinc + tinystd for Darwin/clang builds
ldematte added a commit that referenced this pull request Apr 2, 2026
…#144845)

This PR adds a Docker-based cross-compilation pipeline for building libvec for all three platforms from a single Linux/amd64 container, replacing the previous Mac-dependent workflow. It builds on top of #145066 (merged), which introduced the tinystd headers and builtin replacements.
mromaios pushed a commit to mromaios/elasticsearch that referenced this pull request Apr 9, 2026
…elastic#144845)

This PR adds a Docker-based cross-compilation pipeline for building libvec for all three platforms from a single Linux/amd64 container, replacing the previous Mac-dependent workflow. It builds on top of elastic#145066 (merged), which introduced the tinystd headers and builtin replacements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>refactoring :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants