Skip to content

Commit ff05475

Browse files
committed
Inline native runtimes into core MLXSharp project
1 parent 43e31a4 commit ff05475

File tree

8 files changed

+12
-57
lines changed

8 files changed

+12
-57
lines changed

MLXSharp.sln

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLXSharp", "src\MLXSharp\ML
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLXSharp.Tests", "src\MLXSharp.Tests\MLXSharp.Tests.csproj", "{8F2FA235-E636-4D11-A55D-450505BB8F19}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLXSharp.Native", "src\MLXSharp.Native\MLXSharp.Native.csproj", "{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}"
13-
EndProject
1412
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLXSharp.SemanticKernel", "src\MLXSharp.SemanticKernel\MLXSharp.SemanticKernel.csproj", "{BF201BBA-D607-4EF5-BF9B-766D89B43A4A}"
1513
EndProject
1614
Global
@@ -47,18 +45,6 @@ Global
4745
{8F2FA235-E636-4D11-A55D-450505BB8F19}.Release|x64.Build.0 = Release|Any CPU
4846
{8F2FA235-E636-4D11-A55D-450505BB8F19}.Release|x86.ActiveCfg = Release|Any CPU
4947
{8F2FA235-E636-4D11-A55D-450505BB8F19}.Release|x86.Build.0 = Release|Any CPU
50-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|x64.ActiveCfg = Debug|Any CPU
53-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|x64.Build.0 = Debug|Any CPU
54-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|x86.ActiveCfg = Debug|Any CPU
55-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Debug|x86.Build.0 = Debug|Any CPU
56-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
57-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|Any CPU.Build.0 = Release|Any CPU
58-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|x64.ActiveCfg = Release|Any CPU
59-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|x64.Build.0 = Release|Any CPU
60-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|x86.ActiveCfg = Release|Any CPU
61-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2}.Release|x86.Build.0 = Release|Any CPU
6248
{BF201BBA-D607-4EF5-BF9B-766D89B43A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6349
{BF201BBA-D607-4EF5-BF9B-766D89B43A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
6450
{BF201BBA-D607-4EF5-BF9B-766D89B43A4A}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -78,7 +64,6 @@ Global
7864
GlobalSection(NestedProjects) = preSolution
7965
{69BB544C-9ADD-4561-8B9D-7ACED3B46296} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8066
{8F2FA235-E636-4D11-A55D-450505BB8F19} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
81-
{F5B45C67-1810-4A04-862F-C33A7DFAE4C2} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8267
{BF201BBA-D607-4EF5-BF9B-766D89B43A4A} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8368
EndGlobalSection
8469
EndGlobal

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The design mirrors the packaging approach from projects such as [LLamaSharp](htt
88
- `IChatClient`, `IEmbeddingGenerator<string, Embedding<float)>`, and image generation helpers that adhere to the `Microsoft.Extensions.AI` abstractions.
99
- Builder-based backend configuration with a deterministic managed implementation for tests and a P/Invoke powered native backend.
1010
- Native library resolver that probes application directories, `MLXSHARP_LIBRARY`, or packaged runtimes and loads `libmlxsharp` on demand.
11-
- `MLXSharp.Native` packaging project that ships stub binaries for CI (Linux x64 today) and a placeholder `osx-arm64` folder for the production MLX wrapper.
1211
- Dependency injection extensions (`AddMlx`) in **MLXSharp** package.
1312
- Semantic Kernel integration (`AddMlxChatCompletion`) in separate **MLXSharp.SemanticKernel** package.
1413
- Integration test suite that exercises chat, embedding, image, and Semantic Kernel flows against both managed and native backends.
@@ -18,9 +17,8 @@ The design mirrors the packaging approach from projects such as [LLamaSharp](htt
1817
```
1918
├── extern/mlx # Git submodule with the official MLX sources
2019
├── native/ # Native wrapper scaffold (CMake project)
21-
├── src/MLXSharp/ # Managed library with Microsoft.Extensions.AI adapters
20+
├── src/MLXSharp/ # Managed library with Microsoft.Extensions.AI adapters + packaged runtimes
2221
├── src/MLXSharp.SemanticKernel/ # Semantic Kernel integration (separate package)
23-
├── src/MLXSharp.Native/ # NuGet-ready container for native binaries
2422
└── src/MLXSharp.Tests/ # Integration tests covering DI and Semantic Kernel
2523
```
2624

@@ -81,10 +79,12 @@ dotnet add package MLXSharp
8179

8280
This package contains:
8381
- Managed DLL with `Microsoft.Extensions.AI` implementations
84-
- Native libraries in `runtimes/{rid}/native/`:
85-
- `runtimes/linux-x64/native/libmlxsharp.so` - stub for CI/testing
82+
- Native assets in `runtimes/{rid}/native/`:
83+
- `runtimes/linux-x64/native/libmlxsharp.so.b64` - Base64-encoded stub that `MlxNativeLibrary` expands for CI/testing
8684
- `runtimes/osx-arm64/native/libmlxsharp.dylib` - built in CI on macOS
8785

86+
`MlxNativeLibrary` materialises `libmlxsharp.so` from the encoded payload on first use so Git history stays free of binary blobs while tests retain deterministic behaviour.
87+
8888
### MLXSharp.SemanticKernel [![NuGet](https://img.shields.io/nuget/v/MLXSharp.SemanticKernel.svg)](https://www.nuget.org/packages/MLXSharp.SemanticKernel)
8989

9090
Semantic Kernel integration:
@@ -99,7 +99,7 @@ This package depends on MLXSharp and adds Semantic Kernel chat completion servic
9999

100100
GitHub Actions automatically:
101101
1. Compiles native wrapper with MLX submodule
102-
2. Copies `libmlxsharp.dylib` to `src/MLXSharp.Native/runtimes/osx-arm64/native/`
102+
2. Copies `libmlxsharp.dylib` to `src/MLXSharp/runtimes/osx-arm64/native/`
103103
3. Packs managed + native together in NuGet package
104104

105105
At runtime `MlxNativeLibrary` automatically finds the right library:

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dotnet test
1616
brew install cmake
1717
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
1818
cmake --build native/build --target mlxsharp
19-
cp native/build/libmlxsharp.dylib src/MLXSharp.Native/runtimes/osx-arm64/native/
19+
cp native/build/libmlxsharp.dylib src/MLXSharp/runtimes/osx-arm64/native/
2020
```
2121

2222
Stub версія лінкується з MLX але повертає тестові дані замість реальних результатів моделі.

src/MLXSharp.Native/MLXSharp.Native.csproj

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/MLXSharp.Native/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/MLXSharp/MLXSharp.csproj

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@
77
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.1" />
88
</ItemGroup>
99

10-
<ItemGroup>
11-
<ProjectReference Include="..\MLXSharp.Native\MLXSharp.Native.csproj"
12-
ReferenceOutputAssembly="false"
13-
PrivateAssets="all"
14-
IncludeAssets="none" />
15-
</ItemGroup>
16-
1710
<PropertyGroup>
18-
<MLXProjectRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</MLXProjectRoot>
19-
<MLXSharpMacNativeBinary Condition="'$(MLXSharpMacNativeBinary)' == ''">$([System.IO.Path]::Combine('$(MLXProjectRoot)','native','build','libmlxsharp.dylib'))</MLXSharpMacNativeBinary>
20-
<MLXSharpMacNativeDestination>$([System.IO.Path]::Combine('$(MLXProjectRoot)','src','MLXSharp.Native','runtimes','osx-arm64','native','libmlxsharp.dylib'))</MLXSharpMacNativeDestination>
11+
<MLXSharpMacNativeBinary Condition="'$(MLXSharpMacNativeBinary)' == ''">$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)','..','..','native','build','libmlxsharp.dylib'))</MLXSharpMacNativeBinary>
12+
<MLXSharpMacNativeDestination>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)','runtimes','osx-arm64','native','libmlxsharp.dylib'))</MLXSharpMacNativeDestination>
2113
<MLXSharpSkipMacNativeValidation Condition="'$(MLXSharpSkipMacNativeValidation)' == ''">false</MLXSharpSkipMacNativeValidation>
2214
</PropertyGroup>
2315

@@ -38,9 +30,9 @@
3830
Text="libmlxsharp.dylib is missing. Build the native library or supply MLXSharpMacNativeBinary before packing." />
3931
</Target>
4032

41-
<!-- Include native binaries from MLXSharp.Native project into this package -->
33+
<!-- Include native binaries embedded in this project -->
4234
<ItemGroup>
43-
<None Include="..\MLXSharp.Native\runtimes\**\*.*"
35+
<None Include="runtimes\**\*.*"
4436
Pack="true"
4537
PackagePath="runtimes/%(RecursiveDir)%(Filename)%(Extension)"
4638
CopyToOutputDirectory="PreserveNewest"

src/MLXSharp.Native/runtimes/linux-x64/native/libmlxsharp.so.b64 renamed to src/MLXSharp/runtimes/linux-x64/native/libmlxsharp.so.b64

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Place the macOS arm64 build of libmlxsharp.dylib here before packing MLXSharp.Native for distribution.
1+
Place the macOS arm64 build of libmlxsharp.dylib here before packing MLXSharp for distribution.

0 commit comments

Comments
 (0)