Skip to content

Commit b928b96

Browse files
committed
Restore native packaging project and fix CI solution path
1 parent 56d225e commit b928b96

File tree

6 files changed

+58
-108
lines changed

6 files changed

+58
-108
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
run: dotnet --info
2424

2525
- name: Restore dependencies
26-
run: dotnet restore MLXSharp.sln
26+
run: dotnet restore MLXSharp.slnx
2727

2828
- name: Build C# projects (initial validation)
29-
run: dotnet build MLXSharp.sln --configuration Release --no-restore
29+
run: dotnet build MLXSharp.slnx --configuration Release --no-restore
3030

3131
- name: Install CMake
3232
run: brew install cmake
@@ -41,7 +41,7 @@ jobs:
4141
ls -la src/MLXSharp.Native/runtimes/osx-arm64/native/
4242
4343
- name: Rebuild solution with native libraries
44-
run: dotnet build MLXSharp.sln --configuration Release --no-restore
44+
run: dotnet build MLXSharp.slnx --configuration Release --no-restore
4545

4646
- name: Setup Python for HuggingFace
4747
uses: actions/setup-python@v5
@@ -66,7 +66,7 @@ jobs:
6666
ls -la "$TEST_OUTPUT/runtimes/osx-arm64/native/"
6767
6868
- name: Run tests
69-
run: dotnet test MLXSharp.sln --configuration Release --no-build --logger "trx;LogFileName=TestResults.trx" --results-directory artifacts/test-results
69+
run: dotnet test MLXSharp.slnx --configuration Release --no-build --logger "trx;LogFileName=TestResults.trx" --results-directory artifacts/test-results
7070
env:
7171
MLXSHARP_MODEL_PATH: ${{ github.workspace }}/models/Qwen1.5-0.5B-Chat-4bit
7272

@@ -78,22 +78,42 @@ jobs:
7878
cp src/MLXSharp.Native/runtimes/osx-arm64/native/libmlxsharp.dylib artifacts/native/
7979
8080
- name: Pack MLXSharp library
81-
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages \
82-
-p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib
81+
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib
8382

8483
- name: Pack MLXSharp.SemanticKernel library
85-
run: dotnet pack src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj --configuration Release --output artifacts/packages \
86-
-p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib
84+
run: dotnet pack src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib
8785

8886
- name: Verify package contains native libraries
8987
run: |
9088
echo "Checking package contents..."
91-
if unzip -l artifacts/packages/*.nupkg | grep -q "runtimes/osx-arm64/native/libmlxsharp.dylib"; then
92-
echo "✓ Native library found in package"
93-
else
94-
echo "✗ ERROR: Native library NOT found in package!"
95-
echo "Package contents:"
96-
unzip -l artifacts/packages/*.nupkg
89+
shopt -s nullglob
90+
packages=(artifacts/packages/*.nupkg)
91+
if [ ${#packages[@]} -eq 0 ]; then
92+
echo "✗ ERROR: No packages were produced"
93+
exit 1
94+
fi
95+
96+
missing=0
97+
for package in "${packages[@]}"; do
98+
echo "Inspecting ${package}"
99+
filename=$(basename "${package}")
100+
case "${filename}" in
101+
MLXSharp.*.nupkg)
102+
if unzip -l "${package}" | grep -q "runtimes/osx-arm64/native/libmlxsharp.dylib"; then
103+
echo " ✓ Native library found"
104+
else
105+
echo " ✗ Native library NOT found"
106+
unzip -l "${package}"
107+
missing=1
108+
fi
109+
;;
110+
*)
111+
echo " ↷ Skipping native check for ${filename}"
112+
;;
113+
esac
114+
done
115+
116+
if [ $missing -ne 0 ]; then
97117
exit 1
98118
fi
99119

MLXSharp.sln

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

MLXSharp.slnx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Solution>
2+
<Configurations>
3+
<Platform Name="Any CPU" />
4+
<Platform Name="x64" />
5+
<Platform Name="x86" />
6+
</Configurations>
7+
<Folder Name="/src/">
8+
<Project Path="src/MLXSharp.Native/MLXSharp.Native.csproj" />
9+
<Project Path="src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj" />
10+
<Project Path="src/MLXSharp.Tests/MLXSharp.Tests.csproj" />
11+
<Project Path="src/MLXSharp/MLXSharp.csproj" />
12+
</Folder>
13+
</Solution>

README.md

Lines changed: 5 additions & 4 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.
@@ -19,8 +18,8 @@ The design mirrors the packaging approach from projects such as [LLamaSharp](htt
1918
├── extern/mlx # Git submodule with the official MLX sources
2019
├── native/ # Native wrapper scaffold (CMake project)
2120
├── src/MLXSharp/ # Managed library with Microsoft.Extensions.AI adapters
21+
├── src/MLXSharp.Native/ # Native runtime packaging project with stub binaries
2222
├── src/MLXSharp.SemanticKernel/ # Semantic Kernel integration (separate package)
23-
├── src/MLXSharp.Native/ # NuGet-ready container for native binaries
2423
└── src/MLXSharp.Tests/ # Integration tests covering DI and Semantic Kernel
2524
```
2625

@@ -81,10 +80,12 @@ dotnet add package MLXSharp
8180

8281
This package contains:
8382
- 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
83+
- Native assets in `runtimes/{rid}/native/`:
84+
- `runtimes/linux-x64/native/libmlxsharp.so.b64` - Base64-encoded stub that `MlxNativeLibrary` expands for CI/testing
8685
- `runtimes/osx-arm64/native/libmlxsharp.dylib` - built in CI on macOS
8786

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

9091
Semantic Kernel integration:

src/MLXSharp.Native/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MLXSharp.Native
22

3-
This package mirrors the layout that MLXSharp expects when resolving native binaries.
4-
It ships the `libmlxsharp` stub that our managed layer uses during development and in automated tests.
5-
The Linux stub lives as a Base64-encoded payload (`libmlxsharp.so.b64`) so we can keep Git history free of binary blobs.
6-
`MlxNativeLibrary` expands the encoded payload to `libmlxsharp.so` automatically the first time the native backend loads.
7-
Drop the macOS build of the wrapper into `runtimes/osx-arm64/native/` before publishing a release build.
3+
This helper project mirrors the runtime layout that MLXSharp expects when probing for native binaries.
4+
It ships the stubbed `libmlxsharp` artefacts that our managed layer exercises during development and CI runs.
5+
The Linux build lives as a Base64-encoded payload (`libmlxsharp.so.b64`) so Git history stays free of large binary blobs.
6+
`MlxNativeLibrary` expands that payload to `libmlxsharp.so` on demand, while macOS builds should drop the compiled
7+
`libmlxsharp.dylib` into `runtimes/osx-arm64/native/` before packing a release.
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)