Skip to content

Commit 821b67c

Browse files
authored
Merge pull request #2 from managedcode/codex/fix-msbuild-project-specification-error
Fix mac native packaging in CI
2 parents 79abc9d + d6875fb commit 821b67c

File tree

10 files changed

+56
-135
lines changed

10 files changed

+56
-135
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 10 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
2727

2828
- name: Build C# projects (initial validation)
29-
run: dotnet build MLXSharp.sln --configuration Release --no-restore
29+
run: dotnet build --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 --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 --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

@@ -86,12 +86,34 @@ jobs:
8686
- name: Verify package contains native libraries
8787
run: |
8888
echo "Checking package contents..."
89-
if unzip -l artifacts/packages/*.nupkg | grep -q "runtimes/osx-arm64/native/libmlxsharp.dylib"; then
90-
echo "✓ Native library found in package"
91-
else
92-
echo "✗ ERROR: Native library NOT found in package!"
93-
echo "Package contents:"
94-
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
95117
exit 1
96118
fi
97119

MLXSharp.sln

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

MLXSharp.slnx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.SemanticKernel/MLXSharp.SemanticKernel.csproj" />
9+
<Project Path="src/MLXSharp.Tests/MLXSharp.Tests.csproj" />
10+
<Project Path="src/MLXSharp/MLXSharp.csproj" />
11+
</Folder>
12+
</Solution>

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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +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-
<MLXSharpMacNativeBinary Condition="'$(MLXSharpMacNativeBinary)' == ''">$(MSBuildProjectDirectory)..\..\native\build\libmlxsharp.dylib</MLXSharpMacNativeBinary>
19-
<MLXSharpMacNativeDestination>..\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>
2013
<MLXSharpSkipMacNativeValidation Condition="'$(MLXSharpSkipMacNativeValidation)' == ''">false</MLXSharpSkipMacNativeValidation>
2114
</PropertyGroup>
2215

@@ -37,9 +30,9 @@
3730
Text="libmlxsharp.dylib is missing. Build the native library or supply MLXSharpMacNativeBinary before packing." />
3831
</Target>
3932

40-
<!-- Include native binaries from MLXSharp.Native project into this package -->
33+
<!-- Include native binaries embedded in this project -->
4134
<ItemGroup>
42-
<None Include="..\MLXSharp.Native\runtimes\**\*.*"
35+
<None Include="runtimes\**\*.*"
4336
Pack="true"
4437
PackagePath="runtimes/%(RecursiveDir)%(Filename)%(Extension)"
4538
CopyToOutputDirectory="PreserveNewest"
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)