Skip to content

Commit ca81547

Browse files
committed
WIP
0 parents  commit ca81547

36 files changed

Lines changed: 2728 additions & 0 deletions

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/bin/
2+
**/obj/
3+
**/.vs/
4+
**/.git/
5+
**/node_modules/
6+
ssh-server-config/

.github/workflows/build-native.yml

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
name: Build Native Libraries
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- 'Native/libssh2/**'
9+
- '.github/workflows/build-native.yml'
10+
11+
jobs:
12+
build-windows:
13+
runs-on: windows-latest
14+
strategy:
15+
matrix:
16+
arch: [x64, x86]
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: recursive
21+
22+
- name: Setup vcpkg
23+
uses: lukka/run-vcpkg@v11
24+
with:
25+
vcpkgGitCommitId: 'a42af01b72c28a8e1d7b48107b33e4f286a55ef6'
26+
27+
- name: Install OpenSSL and zlib
28+
run: |
29+
vcpkg install openssl:${{ matrix.arch }}-windows zlib:${{ matrix.arch }}-windows
30+
31+
- name: Setup MSBuild
32+
uses: microsoft/setup-msbuild@v2
33+
34+
- name: Build libssh2
35+
shell: powershell
36+
run: |
37+
$arch = "${{ matrix.arch }}"
38+
$archCMake = if ($arch -eq "x64") { "x64" } else { "Win32" }
39+
40+
cd Native/libssh2
41+
mkdir build-$arch
42+
cd build-$arch
43+
44+
cmake .. `
45+
-G "Visual Studio 17 2022" `
46+
-A $archCMake `
47+
-DCMAKE_BUILD_TYPE=Release `
48+
-DBUILD_SHARED_LIBS=ON `
49+
-DENABLE_ZLIB_COMPRESSION=ON `
50+
-DCRYPTO_BACKEND=OpenSSL `
51+
-DBUILD_EXAMPLES=OFF `
52+
-DBUILD_TESTING=OFF `
53+
-DCMAKE_TOOLCHAIN_FILE="${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
54+
55+
cmake --build . --config Release
56+
57+
# Create output directory
58+
$outDir = "../../../NullOpsDevs.LibSsh/runtimes/win-$arch/native"
59+
mkdir -Force $outDir
60+
61+
# Copy the DLL
62+
Copy-Item "src/Release/libssh2.dll" $outDir
63+
64+
- name: Upload artifacts
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: libssh2-win-${{ matrix.arch }}
68+
path: NullOpsDevs.LibSsh/runtimes/win-${{ matrix.arch }}/native/
69+
70+
build-linux:
71+
runs-on: ubuntu-latest
72+
strategy:
73+
matrix:
74+
include:
75+
- arch: x64
76+
platform: linux/amd64
77+
- arch: arm64
78+
platform: linux/arm64
79+
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
submodules: recursive
83+
84+
- name: Set up QEMU
85+
uses: docker/setup-qemu-action@v3
86+
87+
- name: Set up Docker Buildx
88+
uses: docker/setup-buildx-action@v3
89+
90+
- name: Build libssh2
91+
run: |
92+
docker buildx build \
93+
--platform ${{ matrix.platform }} \
94+
--build-arg TARGETARCH=${{ matrix.arch }} \
95+
--output type=local,dest=./output \
96+
-f - . <<'EOF'
97+
FROM debian:bookworm-slim
98+
99+
RUN apt-get update && apt-get install -y \
100+
build-essential \
101+
cmake \
102+
libssl-dev \
103+
zlib1g-dev \
104+
&& rm -rf /var/lib/apt/lists/*
105+
106+
COPY Native/libssh2 /src/libssh2
107+
WORKDIR /src/libssh2
108+
109+
RUN mkdir build && cd build && \
110+
cmake .. \
111+
-DCMAKE_BUILD_TYPE=Release \
112+
-DBUILD_SHARED_LIBS=ON \
113+
-DENABLE_ZLIB_COMPRESSION=ON \
114+
-DCRYPTO_BACKEND=OpenSSL \
115+
-DBUILD_EXAMPLES=OFF \
116+
-DBUILD_TESTING=OFF && \
117+
cmake --build . --config Release && \
118+
mkdir -p /output && \
119+
cp src/libssh2.so* /output/
120+
121+
FROM scratch
122+
COPY --from=0 /output/* /
123+
EOF
124+
125+
# Create output directory
126+
mkdir -p NullOpsDevs.LibSsh/runtimes/linux-${{ matrix.arch }}/native
127+
128+
# Copy and rename library (remove version suffix)
129+
cp output/libssh2.so* NullOpsDevs.LibSsh/runtimes/linux-${{ matrix.arch }}/native/libssh2.so
130+
131+
- name: Upload artifacts
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: libssh2-linux-${{ matrix.arch }}
135+
path: NullOpsDevs.LibSsh/runtimes/linux-${{ matrix.arch }}/native/
136+
137+
build-macos:
138+
runs-on: macos-latest
139+
strategy:
140+
matrix:
141+
include:
142+
- arch: x64
143+
target: x86_64-apple-darwin
144+
- arch: arm64
145+
target: arm64-apple-darwin
146+
steps:
147+
- uses: actions/checkout@v4
148+
with:
149+
submodules: recursive
150+
151+
- name: Install dependencies
152+
run: |
153+
brew install cmake openssl zlib
154+
155+
- name: Build libssh2
156+
run: |
157+
cd Native/libssh2
158+
mkdir build-${{ matrix.arch }}
159+
cd build-${{ matrix.arch }}
160+
161+
# Set architecture-specific flags
162+
if [ "${{ matrix.arch }}" = "x64" ]; then
163+
ARCH_FLAGS="-arch x86_64"
164+
else
165+
ARCH_FLAGS="-arch arm64"
166+
fi
167+
168+
cmake .. \
169+
-DCMAKE_BUILD_TYPE=Release \
170+
-DBUILD_SHARED_LIBS=ON \
171+
-DENABLE_ZLIB_COMPRESSION=ON \
172+
-DCRYPTO_BACKEND=OpenSSL \
173+
-DBUILD_EXAMPLES=OFF \
174+
-DBUILD_TESTING=OFF \
175+
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch == 'x64' && 'x86_64' || 'arm64' }} \
176+
-DOPENSSL_ROOT_DIR=$(brew --prefix openssl)
177+
178+
cmake --build . --config Release
179+
180+
# Create output directory
181+
mkdir -p ../../../NullOpsDevs.LibSsh/runtimes/osx-${{ matrix.arch }}/native
182+
183+
# Copy the dylib
184+
cp src/libssh2*.dylib ../../../NullOpsDevs.LibSsh/runtimes/osx-${{ matrix.arch }}/native/libssh2.dylib
185+
186+
- name: Upload artifacts
187+
uses: actions/upload-artifact@v4
188+
with:
189+
name: libssh2-osx-${{ matrix.arch }}
190+
path: NullOpsDevs.LibSsh/runtimes/osx-${{ matrix.arch }}/native/
191+
192+
package:
193+
needs: [build-windows, build-linux, build-macos]
194+
runs-on: ubuntu-latest
195+
steps:
196+
- uses: actions/checkout@v4
197+
198+
- name: Download all artifacts
199+
uses: actions/download-artifact@v4
200+
with:
201+
path: artifacts
202+
203+
- name: Organize native libraries
204+
run: |
205+
mkdir -p NullOpsDevs.LibSsh/runtimes
206+
207+
# Copy all native libraries to the correct runtime folders
208+
for artifact in artifacts/libssh2-*; do
209+
platform=$(basename $artifact | sed 's/libssh2-//')
210+
echo "Processing $platform..."
211+
mkdir -p NullOpsDevs.LibSsh/runtimes/$platform/native
212+
cp -r $artifact/* NullOpsDevs.LibSsh/runtimes/$platform/native/ || true
213+
done
214+
215+
# List what we have
216+
find NullOpsDevs.LibSsh/runtimes -type f
217+
218+
- name: Setup .NET
219+
uses: actions/setup-dotnet@v4
220+
with:
221+
dotnet-version: '9.0.x'
222+
223+
- name: Build and Pack NuGet
224+
run: |
225+
dotnet build NullOpsDevs.LibSsh/NullOpsDevs.LibSsh.csproj -c Release
226+
dotnet pack NullOpsDevs.LibSsh/NullOpsDevs.LibSsh.csproj -c Release -o ./artifacts/nuget
227+
228+
- name: Upload NuGet package
229+
uses: actions/upload-artifact@v4
230+
with:
231+
name: nuget-package
232+
path: artifacts/nuget/*.nupkg
233+
234+
- name: Upload native libraries
235+
uses: actions/upload-artifact@v4
236+
with:
237+
name: native-libraries-all
238+
path: NullOpsDevs.LibSsh/runtimes/

0 commit comments

Comments
 (0)