Skip to content

Commit d756700

Browse files
committed
worflow
1 parent 43114da commit d756700

File tree

1 file changed

+79
-32
lines changed

1 file changed

+79
-32
lines changed

.github/workflows/ci.yml

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,27 @@ on:
66
pull_request:
77

88
jobs:
9+
dotnet-build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 9.0.x
21+
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
25+
- name: Build managed projects
26+
run: dotnet build --configuration Release --no-restore
27+
928
native-linux:
29+
needs: dotnet-build
1030
runs-on: ubuntu-latest
1131
steps:
1232
- name: Checkout repository
@@ -36,8 +56,39 @@ jobs:
3656
name: native-linux-x64
3757
path: artifacts/native/linux-x64/libmlxsharp.so
3858

39-
build-test:
40-
needs: native-linux
59+
native-macos:
60+
needs: dotnet-build
61+
runs-on: macos-latest
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
with:
66+
submodules: recursive
67+
68+
- name: Install CMake
69+
run: brew install cmake
70+
71+
- name: Configure native build
72+
run: cmake -S native -B native/build/macos -DCMAKE_BUILD_TYPE=Release
73+
74+
- name: Build native library
75+
run: cmake --build native/build/macos --target mlxsharp --config Release
76+
77+
- name: Package native artifact
78+
run: |
79+
mkdir -p artifacts/native/osx-arm64
80+
cp native/build/macos/libmlxsharp.dylib artifacts/native/osx-arm64/
81+
82+
- name: Upload native artifact
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: native-osx-arm64
86+
path: artifacts/native/osx-arm64/libmlxsharp.dylib
87+
88+
package-test:
89+
needs:
90+
- native-linux
91+
- native-macos
4192
runs-on: macos-latest
4293
steps:
4394
- name: Checkout repository
@@ -59,21 +110,6 @@ jobs:
59110
- name: Build C# projects (initial validation)
60111
run: dotnet build --configuration Release --no-restore
61112

62-
- name: Install CMake
63-
run: brew install cmake
64-
65-
- name: Build native stub library
66-
run: |
67-
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
68-
cmake --build native/build --target mlxsharp --config Release
69-
mkdir -p src/MLXSharp/runtimes/osx-arm64/native
70-
cp native/build/libmlxsharp.dylib src/MLXSharp/runtimes/osx-arm64/native/
71-
echo "Native library built:"
72-
ls -la src/MLXSharp/runtimes/osx-arm64/native/
73-
74-
- name: Rebuild solution with native libraries
75-
run: dotnet build --configuration Release --no-restore
76-
77113
- name: Setup Python for HuggingFace
78114
uses: actions/setup-python@v5
79115
with:
@@ -89,6 +125,28 @@ jobs:
89125
echo "Model files:"
90126
ls -la models/Qwen1.5-0.5B-Chat-4bit/
91127
128+
- name: Download macOS native library
129+
uses: actions/download-artifact@v4
130+
with:
131+
name: native-osx-arm64
132+
path: artifacts/native/osx-arm64
133+
134+
- name: Download Linux native library
135+
uses: actions/download-artifact@v4
136+
with:
137+
name: native-linux-x64
138+
path: artifacts/native/linux-x64
139+
140+
- name: Stage native libraries in project
141+
run: |
142+
mkdir -p src/MLXSharp/runtimes/osx-arm64/native
143+
cp artifacts/native/osx-arm64/libmlxsharp.dylib src/MLXSharp/runtimes/osx-arm64/native/
144+
mkdir -p src/MLXSharp/runtimes/linux-x64/native
145+
cp artifacts/native/linux-x64/libmlxsharp.so src/MLXSharp/runtimes/linux-x64/native/
146+
147+
- name: Build C# projects with native libraries
148+
run: dotnet build --configuration Release --no-restore
149+
92150
- name: Copy native library to test output
93151
run: |
94152
TEST_OUTPUT="src/MLXSharp.Tests/bin/Release/net9.0"
@@ -106,25 +164,14 @@ jobs:
106164
mkdir -p artifacts/test-results
107165
mkdir -p artifacts/packages
108166
mkdir -p artifacts/native
109-
cp src/MLXSharp/runtimes/osx-arm64/native/libmlxsharp.dylib artifacts/native/
110-
111-
- name: Download Linux native library
112-
uses: actions/download-artifact@v4
113-
with:
114-
name: native-linux-x64
115-
path: artifacts/native/linux-x64
116-
117-
- name: Stage Linux native library in project
118-
run: |
119-
mkdir -p src/MLXSharp/runtimes/linux-x64/native
120-
cp artifacts/native/linux-x64/libmlxsharp.so src/MLXSharp/runtimes/linux-x64/native/
167+
cp artifacts/native/osx-arm64/libmlxsharp.dylib artifacts/native/
121168
cp artifacts/native/linux-x64/libmlxsharp.so artifacts/native/
122169
123170
- name: Pack MLXSharp library
124-
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so
171+
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/artifacts/native/osx-arm64/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so
125172

126173
- name: Pack MLXSharp.SemanticKernel library
127-
run: dotnet pack src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/native/build/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so -p:MLXSharpSkipLinuxNativeValidation=true
174+
run: dotnet pack src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/artifacts/native/osx-arm64/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so -p:MLXSharpSkipLinuxNativeValidation=true
128175

129176
- name: Verify package contains native libraries
130177
run: |
@@ -195,7 +242,7 @@ jobs:
195242

196243
release:
197244
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
198-
needs: build-test
245+
needs: package-test
199246
runs-on: ubuntu-latest
200247
permissions:
201248
contents: write

0 commit comments

Comments
 (0)