Skip to content

Commit

Permalink
Merge pull request #66 from stunnel/feature/static-link-musl
Browse files Browse the repository at this point in the history
link with glibc and musl
  • Loading branch information
travislee89 authored Feb 13, 2024
2 parents 8ca6cc2 + c8461b7 commit 20f8455
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 22 deletions.
86 changes: 85 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
ZSTD_VERSION: ${{ vars.ZSTD_VERSION }}
LIBSSH2_VERSION: ${{ vars.LIBSSH2_VERSION }}
ARES_VERSION: ${{ vars.ARES_VERSION }}
LIBC: glibc
STATIC_LIBRARY: 1
CONTAINER_IMAGE: debian:latest
TOKEN_READ: ${{ secrets.GITHUB_TOKEN }}
ARCHES: "x86_64 aarch64 armv7 riscv64 s390x mips64 mips64el mipsel powerpc64le powerpc"
Expand All @@ -50,6 +52,8 @@ jobs:
ZSTD_VERSION=${ZSTD_VERSION}
LIBSSH2_VERSION=${LIBSSH2_VERSION}
ARES_VERSION=${ARES_VERSION}
LIBC=${LIBC}
STATIC_LIBRARY=${STATIC_LIBRARY}
CONTAINER_IMAGE=${CONTAINER_IMAGE}
TOKEN_READ=${TOKEN_READ}
sh curl-static-cross.sh
Expand Down Expand Up @@ -77,6 +81,80 @@ jobs:
if-no-files-found: error
overwrite: true

build-Linux-musl:
name: build-Linux-musl (${{ github.ref_name }})
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Cross Build Static cURL
env:
CURL_VERSION: ${{ vars.CURL_VERSION }}
TLS_LIB: ${{ vars.TLS_LIB }}
QUICTLS_VERSION: ${{ vars.QUICTLS_VERSION }}
OPENSSL_VERSION: ${{ vars.OPENSSL_VERSION }}
NGTCP2_VERSION: ${{ vars.NGTCP2_VERSION }}
NGHTTP3_VERSION: ${{ vars.NGHTTP3_VERSION }}
NGHTTP2_VERSION: ${{ vars.NGHTTP2_VERSION }}
LIBIDN2_VERSION: ${{ vars.LIBIDN2_VERSION }}
LIBUNISTRING_VERSION: ${{ vars.LIBUNISTRING_VERSION }}
ZLIB_VERSION: ${{ vars.ZLIB_VERSION }}
BROTLI_VERSION: ${{ vars.BROTLI_VERSION }}
ZSTD_VERSION: ${{ vars.ZSTD_VERSION }}
LIBSSH2_VERSION: ${{ vars.LIBSSH2_VERSION }}
ARES_VERSION: ${{ vars.ARES_VERSION }}
LIBC: musl
CONTAINER_IMAGE: debian:latest
TOKEN_READ: ${{ secrets.GITHUB_TOKEN }}
ARCHES: "x86_64 aarch64 armv7 i686 riscv64 s390x mips64 mips64el mips mipsel powerpc64le powerpc"
run: |
ARCHES="${ARCHES}"
CURL_VERSION=${CURL_VERSION}
TLS_LIB=${TLS_LIB}
QUICTLS_VERSION=${QUICTLS_VERSION}
OPENSSL_VERSION=${OPENSSL_VERSION}
NGTCP2_VERSION=${NGTCP2_VERSION}
NGHTTP3_VERSION=${NGHTTP3_VERSION}
NGHTTP2_VERSION=${NGHTTP2_VERSION}
LIBIDN2_VERSION=${LIBIDN2_VERSION}
LIBUNISTRING_VERSION=${LIBUNISTRING_VERSION}
ZLIB_VERSION=${ZLIB_VERSION}
BROTLI_VERSION=${BROTLI_VERSION}
ZSTD_VERSION=${ZSTD_VERSION}
LIBSSH2_VERSION=${LIBSSH2_VERSION}
ARES_VERSION=${ARES_VERSION}
LIBC=${LIBC}
CONTAINER_IMAGE=${CONTAINER_IMAGE}
TOKEN_READ=${TOKEN_READ}
sh curl-static-cross.sh
- name: Set up environment
run: |
VERSION=`cat release/version.txt`
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Upload artifact (version)
uses: actions/upload-artifact@v4
with:
name: curl-version
path: release/version.txt
retention-days: 90
if-no-files-found: error
overwrite: true

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: curl-binary-linux-musl-${{ env.VERSION }}
path: release
retention-days: 90
if-no-files-found: error
overwrite: true

build-Windows:
name: build-Windows (${{ github.ref_name }})
runs-on: ubuntu-latest
Expand Down Expand Up @@ -225,7 +303,7 @@ jobs:

release:
name: release curl (${{ github.ref_name }})
needs: [build-Linux, build-Windows, build-macOS]
needs: [build-Linux, build-Linux-musl, build-Windows, build-macOS]
runs-on: ubuntu-latest

steps:
Expand All @@ -251,6 +329,12 @@ jobs:
name: curl-binary-linux-${{ env.VERSION }}
path: release

- name: Download artifact (linux-musl)
uses: actions/download-artifact@v4
with:
name: curl-binary-linux-musl-${{ env.VERSION }}
path: release

- name: Download artifact (macos)
uses: actions/download-artifact@v4
with:
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,32 @@ Download the latest release from the [Releases page](https://github.com/stunnel/
Extract the archive and use it.
The binary is built with GitHub Actions.

### Release files

- `curl-linux-ARCH-VERSION`: binaries for Linux, linked with `glibc`
- `curl-linux-ARCH-dev-VERSION`: binaries, headers and static library archives for Linux, for development
- `curl-linux-ARCH-musl-VERSION`: binaries for Linux, linked with `musl`
- `curl-macOS-ARCH-VERSION`: binaries for macOS
- `curl-windows-ARCH-VERSION`: binaries for Windows
- `curl-windows-ARCH-dev-VERSION`: binaries, headers and library archives for Windows, for development

## Compile

This script utilizes `clang` or `qbt-musl-cross-make` for cross-compilation on Linux, `mstorsjo/llvm-mingw` for cross-compilation for Windows, providing support for the following architectures:

- Linux
- x86_64
- aarch64
- armv7
- i686
- riscv64
- s390x
- mips64
- mips64el
- mips
- mipsel
- powerpc64le
- powerpc
- x86_64(glibc and musl)
- aarch64(glibc and musl)
- armv7(glibc and musl)
- i686(musl)
- riscv64(glibc and musl)
- s390x(glibc and musl)
- mips64(glibc and musl)
- mips64el(glibc and musl)
- mips(musl)
- mipsel(glibc and musl)
- powerpc64le(glibc and musl)
- powerpc(glibc and musl)
- macOS
- x86_64
- aarch64
Expand Down Expand Up @@ -140,7 +149,7 @@ Supported Environment Variables list:
For all `VERSION` variables, leaving them blank will automatically fetch the latest version.

- `ARCHES`: The list of architectures to compile. You can set one or multiple architectures from the following options: [Compile](#Compile)
- `TLS_LIB`: The TLS library. `quictls`(default) or `openssl`(requires openssl 3.2.0 or later, and curl 8.6.0+).
- `TLS_LIB`: The TLS library. `quictls`(default) or `openssl`(requires openssl 3.2.0+, and curl 8.6.0+).
- `CURL_VERSION`: The version of cURL. If set to `dev`, will clone the latest source code from GitHub.
- `QUICTLS_VERSION`: The version of quictls.
- `OPENSSL_VERSION`: The version of OpenSSL.
Expand Down
19 changes: 14 additions & 5 deletions curl-static-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# -e BROTLI_VERSION="" \
# -e ZSTD_VERSION="" \
# -e LIBSSH2_VERSION="" \
# -e LIBC="" \
# -e STATIC_LIBRARY=1 \
# -e CONTAINER_IMAGE=debian:latest \
# debian:latest sh curl-static-cross.sh
# Supported architectures: x86_64, aarch64, armv7, i686, riscv64, s390x,
Expand Down Expand Up @@ -248,15 +250,18 @@ arch_variants() {
unset LD STRIP LDFLAGS
TARGET="${ARCH}-pc-linux-gnu"
export LDFLAGS="-L${PREFIX}/lib -L${PREFIX}/lib64";
if [ "${ARCH}" != "${ARCH_HOST}" ]; then
# If the architecture is not the same as the host, need to cross compile
libc_flag="";

if [ "${ARCH}" != "${ARCH_HOST}" ] || [ "${LIBC}" = "musl" ]; then
# If the architecture is not the same as the host, or it is Alpine, then cross compile
install_qemu "${qemu_arch}";

if [ "${ARCH}" = "mips" ] || [ "${ARCH}" = "i686" ] || [ "${ID}" = "alpine" ]; then
if [ "${LIBC}" = "musl" ] || [ "${ID}" = "alpine" ] || [ "${ARCH}" = "mips" ] || [ "${ARCH}" = "i686" ]; then
# Cross-compilation failed with atomic using clang in MIPS and i686.
# Alpine does not have a GCC cross-compile toolchain.
# Therefore, musl-cross-make is used for compilation.
install_cross_compile;
libc_flag="-musl";
else
# Uses Clang for default cross-compilation
install_cross_compile_debian;
Expand Down Expand Up @@ -765,7 +770,7 @@ install_curl() {
mkdir -p "${RELEASE_DIR}/release/bin/"

ls -l src/curl
cp -pf src/curl "${RELEASE_DIR}/release/bin/curl-linux-${arch}"
cp -pf src/curl "${RELEASE_DIR}/release/bin/curl-linux-${arch}${libc_flag}"

if [ ! -f "${RELEASE_DIR}/release/version.txt" ]; then
echo "${CURL_VERSION}" > "${RELEASE_DIR}/release/version.txt"
Expand All @@ -774,7 +779,9 @@ install_curl() {
src/curl -V >> "${RELEASE_DIR}/release/version-info.txt"
fi

XZ_OPT=-9 tar -Jcf "${RELEASE_DIR}/release/curl-linux-${ARCH}-dev-${CURL_VERSION}.tar.xz" -C "${DIR}" "curl-${ARCH}"
if [ -z "${STATIC_LIBRARY}" ]; then
XZ_OPT=-9 tar -Jcf "${RELEASE_DIR}/release/curl-linux-${ARCH}-dev-${CURL_VERSION}.tar.xz" -C "${DIR}" "curl-${ARCH}"
fi
}

_arch_match() {
Expand Down Expand Up @@ -842,6 +849,8 @@ _build_in_docker() {
-e LIBSSH2_VERSION="${LIBSSH2_VERSION}" \
-e LIBUNISTRING_VERSION="${LIBUNISTRING_VERSION}" \
-e LIBIDN2_VERSION="${LIBIDN2_VERSION}" \
-e LIBC="${LIBC}" \
-e STATIC_LIBRARY="${STATIC_LIBRARY}" \
"${container_image}" sh "${RELEASE_DIR}/${base_name}" 2>&1 | tee -a "${container_name}.log"

# Exit script after docker finishes
Expand Down
6 changes: 3 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ create_release_note() {
output_sha256=$(sha256sum release/bin/curl-linux* release/bin/curl-macos* release/bin/curl-windows* \
| sed 's#release/bin/##g' | sed 's#-# #g' | sed 's#.exe##g')
markdown_table=$(printf "%s" "${output_sha256}" |
awk 'BEGIN {print "| File | Platform | Arch | SHA256 |\n|------|------|--------|--------|"}
{printf("| %s | %s | %s | %s |\n", $2, $3, $4, $1)}')
awk 'BEGIN {print "| File | Platform | Arch | LibC | SHA256 |\n|------|------|------|--------|--------|"}
{printf("| %s | %s | %s | %s | %s |\n", $2, $3, $4, $5, $1)}')

cat > release/release.md<<EOF
# Static cURL ${CURL_VERSION} with HTTP3
Expand All @@ -45,7 +45,7 @@ ${features}
## License
This binary includes various open-source software such as curl, openssl, zlib, brotli, zstd, libidn2, libssh2, nghttp2, ngtcp2, nghttp3. Their license information has been compiled and is included in the `dev` file.
This binary includes various open-source software such as curl, openssl, zlib, brotli, zstd, libidn2, libssh2, nghttp2, ngtcp2, nghttp3. Their license information has been compiled and is included in the dev package.
## Checksums
Expand Down

0 comments on commit 20f8455

Please sign in to comment.