Skip to content

Add public Cxxmlx target for MLX C++ sources#425

Draft
a1091150 wants to merge 2 commits into
ml-explore:mainfrom
a1091150:cxx_target
Draft

Add public Cxxmlx target for MLX C++ sources#425
a1091150 wants to merge 2 commits into
ml-explore:mainfrom
a1091150:cxx_target

Conversation

@a1091150

@a1091150 a1091150 commented Jun 19, 2026

Copy link
Copy Markdown

Proposed changes

This PR separates MLX C++ from Cmlx into a new public Cxxmlx target and exposes metal-cpp header. Allow users write custom mlx c++ extension (mlx::core::Primitive) without rewriting into swift version or fast kernel code.

Reproduce the changes

  1. Most of the changes use git mv to move files from Cmlx target to Cxxmlx target.
Source/Cmlx/mlx              -> Source/Cxxmlx/mlx
Source/Cmlx/mlx-generated    -> Source/Cxxmlx/mlx-generated
Source/Cmlx/mlx-conditional  -> Source/Cxxmlx/mlx-conditional
Source/Cmlx/fmt              -> Source/Cxxmlx/fmt
Source/Cmlx/json             -> Source/Cxxmlx/json
Source/Cmlx/metal-cpp        -> Source/Cxxmlx/metal-cpp
Source/Cmlx/CudaBuild.json   -> Source/Cxxmlx/CudaBuild.json
Source/Cmlx/vendor-README.md -> Source/Cxxmlx/vendor-README.md
  1. Modify targets in Packages.swift
  • Cmlx depens on Cxxmlx.
  1. Add public header search path and copy, so #include <mlx/mlx.h> works.
  • Copy public header files to Source/Cxxmlx/include/mlx/
  • Copy metal-cpp header files to Source/Cxxmlx/include/, Foundation, Metal, MetalFX and QuartzCore
  • Update tools/update-mlx.sh to update these public headers.
  1. Update MLX.xcodeproj

I have tried on my 3DGS private project, Linux machines have not tested yet.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

a1091150 added 2 commits June 18, 2026 10:54
Move ownership of the vendored MLX C++ sources from Cmlx into a new
public Cxxmlx target. This lets downstream C++ consumers depend on
Cxxmlx directly and include MLX headers with paths like <mlx/mlx.h>.

Cmlx now owns only the mlx-c wrapper sources and depends on Cxxmlx for
the underlying C++ implementation. Update the package manifest,
submodule path, header layout, maintenance scripts, docs, and Xcode
project settings to use Source/Cxxmlx for MLX C++ sources, generated
sources, fmt, json, and metal-cpp.
Mirror the metal-cpp Foundation, Metal, MetalFX, and QuartzCore headers into
Cxxmlx's public include directory so downstream SwiftPM targets can compile
custom MLX C++ primitives without adding unsafe header search paths.

MLX public Metal backend headers, such as mlx/backend/metal/device.h, include
Metal C++ headers like <Metal/Metal.hpp>. Since SwiftPM does not expose a
dependency target's private header search paths to consumers, Cxxmlx's public
headers need to be self-contained under publicHeadersPath.

Update tools/update-mlx.sh to refresh these metal-cpp public header mirrors
alongside the MLX C++ header mirror.
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