77 paths :
88 - ' Native/libssh2/**'
99 - ' .github/workflows/build-native.yml'
10+ - ' .github/docker/**'
11+ - ' .github/scripts/**'
1012
1113jobs :
1214 build-all :
1820 - platform : win-x64
1921 dockerfile_platform : linux/amd64
2022 target_triple : x86_64-w64-mingw32
21- - platform : win-x86
22- dockerfile_platform : linux/amd64
23- target_triple : i686-w64-mingw32
2423 - platform : linux-x64
2524 dockerfile_platform : linux/amd64
2625 target_triple : x86_64-linux-gnu
@@ -46,168 +45,8 @@ jobs:
4645
4746 - name : Build libssh2
4847 run : |
49- mkdir -p output
50-
51- # Determine build configuration based on platform
52- PLATFORM="${{ matrix.platform }}"
53- TARGET_TRIPLE="${{ matrix.target_triple }}"
54-
55- if [[ "$PLATFORM" == win-* ]]; then
56- # Windows build using MinGW
57- docker buildx build \
58- --platform ${{ matrix.dockerfile_platform }} \
59- --build-arg TARGET_TRIPLE=$TARGET_TRIPLE \
60- --output type=local,dest=./output \
61- -f - . <<'EOF'
62- FROM debian:bookworm-slim
63- ARG TARGET_TRIPLE
64-
65- RUN apt-get update && apt-get install -y \
66- build-essential \
67- cmake \
68- mingw-w64 \
69- wget \
70- && rm -rf /var/lib/apt/lists/*
71-
72- # Download and build OpenSSL for Windows
73- WORKDIR /build
74- RUN wget https://www.openssl.org/source/openssl-3.0.15.tar.gz && \
75- tar xzf openssl-3.0.15.tar.gz && \
76- cd openssl-3.0.15 && \
77- ./Configure mingw64 --cross-compile-prefix=${TARGET_TRIPLE}- --prefix=/opt/openssl-${TARGET_TRIPLE} && \
78- make -j$(nproc) && \
79- make install_sw
80-
81- # Build libssh2
82- COPY Native/libssh2 /src/libssh2
83- WORKDIR /src/libssh2/build
84-
85- RUN cmake .. \
86- -DCMAKE_SYSTEM_NAME=Windows \
87- -DCMAKE_C_COMPILER=${TARGET_TRIPLE}-gcc \
88- -DCMAKE_RC_COMPILER=${TARGET_TRIPLE}-windres \
89- -DCMAKE_BUILD_TYPE=Release \
90- -DBUILD_SHARED_LIBS=ON \
91- -DENABLE_ZLIB_COMPRESSION=OFF \
92- -DCRYPTO_BACKEND=OpenSSL \
93- -DOPENSSL_ROOT_DIR=/opt/openssl-${TARGET_TRIPLE} \
94- -DBUILD_EXAMPLES=OFF \
95- -DBUILD_TESTING=OFF && \
96- cmake --build . --config Release -j$(nproc) && \
97- mkdir -p /output && \
98- cp src/libssh2.dll /output/ || cp src/libssh2-*.dll /output/libssh2.dll
99-
100- FROM scratch
101- COPY --from=0 /output/* /
102- EOF
103-
104- elif [[ "$PLATFORM" == osx-* ]]; then
105- # macOS build using osxcross
106- docker buildx build \
107- --platform ${{ matrix.dockerfile_platform }} \
108- --build-arg TARGET_TRIPLE=$TARGET_TRIPLE \
109- --output type=local,dest=./output \
110- -f - . <<'EOF'
111- FROM debian:bookworm-slim
112- ARG TARGET_TRIPLE
113-
114- RUN apt-get update && apt-get install -y \
115- build-essential \
116- cmake \
117- git \
118- wget \
119- clang \
120- libssl-dev \
121- libxml2-dev \
122- llvm-dev \
123- uuid-dev \
124- zlib1g-dev \
125- libbz2-dev \
126- && rm -rf /var/lib/apt/lists/*
127-
128- # Install osxcross
129- WORKDIR /opt
130- RUN git clone https://github.com/tpoechtrager/osxcross.git && \
131- cd osxcross && \
132- wget -nc https://github.com/joseluisq/macosx-sdks/releases/download/12.3/MacOSX12.3.sdk.tar.xz && \
133- mv MacOSX12.3.sdk.tar.xz tarballs/ && \
134- UNATTENDED=1 ./build.sh
135-
136- ENV PATH="/opt/osxcross/target/bin:$PATH"
137-
138- # Build libssh2
139- COPY Native/libssh2 /src/libssh2
140- WORKDIR /src/libssh2/build
141-
142- RUN cmake .. \
143- -DCMAKE_SYSTEM_NAME=Darwin \
144- -DCMAKE_C_COMPILER=${TARGET_TRIPLE}-clang \
145- -DCMAKE_CXX_COMPILER=${TARGET_TRIPLE}-clang++ \
146- -DCMAKE_BUILD_TYPE=Release \
147- -DBUILD_SHARED_LIBS=ON \
148- -DENABLE_ZLIB_COMPRESSION=ON \
149- -DCRYPTO_BACKEND=OpenSSL \
150- -DBUILD_EXAMPLES=OFF \
151- -DBUILD_TESTING=OFF && \
152- cmake --build . --config Release -j$(nproc) && \
153- mkdir -p /output && \
154- cp src/libssh2*.dylib /output/libssh2.dylib
155-
156- FROM scratch
157- COPY --from=0 /output/* /
158- EOF
159-
160- else
161- # Linux build
162- docker buildx build \
163- --platform ${{ matrix.dockerfile_platform }} \
164- --output type=local,dest=./output \
165- -f - . <<'EOF'
166- FROM debian:bookworm-slim
167-
168- RUN apt-get update && apt-get install -y \
169- build-essential \
170- cmake \
171- libssl-dev \
172- zlib1g-dev \
173- && rm -rf /var/lib/apt/lists/*
174-
175- COPY Native/libssh2 /src/libssh2
176- WORKDIR /src/libssh2/build
177-
178- RUN cmake .. \
179- -DCMAKE_BUILD_TYPE=Release \
180- -DBUILD_SHARED_LIBS=ON \
181- -DENABLE_ZLIB_COMPRESSION=ON \
182- -DCRYPTO_BACKEND=OpenSSL \
183- -DBUILD_EXAMPLES=OFF \
184- -DBUILD_TESTING=OFF && \
185- cmake --build . --config Release -j$(nproc) && \
186- mkdir -p /output && \
187- cp src/libssh2.so* /output/
188-
189- FROM scratch
190- COPY --from=0 /output/* /
191- EOF
192- fi
193-
194- # Create runtime directory structure
195- mkdir -p NullOpsDevs.LibSsh/runtimes/${{ matrix.platform }}/native
196-
197- # Copy library to correct location
198- if [[ "$PLATFORM" == win-* ]]; then
199- cp output/libssh2.dll NullOpsDevs.LibSsh/runtimes/${{ matrix.platform }}/native/
200- elif [[ "$PLATFORM" == osx-* ]]; then
201- cp output/libssh2.dylib NullOpsDevs.LibSsh/runtimes/${{ matrix.platform }}/native/
202- else
203- # Copy and create symlink without version suffix
204- cp output/libssh2.so* NullOpsDevs.LibSsh/runtimes/${{ matrix.platform }}/native/
205- # Find the actual .so file and create a symlink
206- cd NullOpsDevs.LibSsh/runtimes/${{ matrix.platform }}/native/
207- if [ -f libssh2.so.1 ]; then
208- ln -sf libssh2.so.1 libssh2.so
209- fi
210- fi
48+ chmod +x .github/scripts/build-native.sh
49+ .github/scripts/build-native.sh "${{ matrix.platform }}" "${{ matrix.target_triple }}" "${{ matrix.dockerfile_platform }}"
21150
21251 - name : Upload artifacts
21352 uses : actions/upload-artifact@v4
0 commit comments