Skip to content

Commit 56d225e

Browse files
committed
fix
1 parent 29d3a7b commit 56d225e

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ jobs:
3131
- name: Install CMake
3232
run: brew install cmake
3333

34+
- name: Build native stub library
35+
run: |
36+
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
37+
cmake --build native/build --target mlxsharp --config Release
38+
mkdir -p src/MLXSharp.Native/runtimes/osx-arm64/native
39+
cp native/build/libmlxsharp.dylib src/MLXSharp.Native/runtimes/osx-arm64/native/
40+
echo "Native library built:"
41+
ls -la src/MLXSharp.Native/runtimes/osx-arm64/native/
42+
43+
- name: Rebuild solution with native libraries
44+
run: dotnet build MLXSharp.sln --configuration Release --no-restore
45+
3446
- name: Setup Python for HuggingFace
3547
uses: actions/setup-python@v5
3648
with:
@@ -46,16 +58,6 @@ jobs:
4658
echo "Model files:"
4759
ls -la models/Qwen1.5-0.5B-Chat-4bit/
4860
49-
- name: Build native stub library
50-
run: |
51-
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
52-
cmake --build native/build --target mlxsharp --config Release
53-
mkdir -p src/MLXSharp.Native/runtimes/osx-arm64/native
54-
cp native/build/libmlxsharp.dylib src/MLXSharp.Native/runtimes/osx-arm64/native/
55-
56-
- name: Rebuild with native libraries
57-
run: dotnet build MLXSharp.sln --configuration Release --no-restore
58-
5961
- name: Copy native library to test output
6062
run: |
6163
TEST_OUTPUT="src/MLXSharp.Tests/bin/Release/net9.0"
@@ -76,10 +78,12 @@ jobs:
7678
cp src/MLXSharp.Native/runtimes/osx-arm64/native/libmlxsharp.dylib artifacts/native/
7779
7880
- name: Pack MLXSharp library
79-
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages
81+
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages \
82+
-p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib
8083

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

8488
- name: Verify package contains native libraries
8589
run: |

src/MLXSharp/MLXSharp.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
IncludeAssets="none" />
1515
</ItemGroup>
1616

17+
<PropertyGroup>
18+
<MLXSharpMacNativeBinary Condition="'$(MLXSharpMacNativeBinary)' == ''">$(MSBuildProjectDirectory)..\..\native\build\libmlxsharp.dylib</MLXSharpMacNativeBinary>
19+
<MLXSharpMacNativeDestination>..\MLXSharp.Native\runtimes\osx-arm64\native\libmlxsharp.dylib</MLXSharpMacNativeDestination>
20+
<MLXSharpSkipMacNativeValidation Condition="'$(MLXSharpSkipMacNativeValidation)' == ''">false</MLXSharpSkipMacNativeValidation>
21+
</PropertyGroup>
22+
23+
<Target Name="EnsureMacNativeBinary"
24+
BeforeTargets="Pack"
25+
Condition="'$(MSBuildProjectFullPath)' == '$(MSBuildThisFileFullPath)'">
26+
<ItemGroup>
27+
<_MacNativeSource Include="$(MLXSharpMacNativeBinary)"
28+
Condition="Exists('$(MLXSharpMacNativeBinary)')" />
29+
</ItemGroup>
30+
31+
<Copy SourceFiles="@(_MacNativeSource)"
32+
DestinationFiles="$(MLXSharpMacNativeDestination)"
33+
SkipUnchangedFiles="true"
34+
Condition="'@(_MacNativeSource)' != ''" />
35+
36+
<Error Condition="'$(MLXSharpSkipMacNativeValidation)' != 'true' and !Exists('$(MLXSharpMacNativeDestination)')"
37+
Text="libmlxsharp.dylib is missing. Build the native library or supply MLXSharpMacNativeBinary before packing." />
38+
</Target>
39+
1740
<!-- Include native binaries from MLXSharp.Native project into this package -->
1841
<ItemGroup>
1942
<None Include="..\MLXSharp.Native\runtimes\**\*.*"

0 commit comments

Comments
 (0)