Skip to content

Commit

Permalink
[CI] Build with musl libc (#203)
Browse files Browse the repository at this point in the history
* [CI] Build with musl libc

* Add note in README

* List linked libraries on for dynamic binary

* Upload musl build artifacts [skip ci]

* Upload release artifacts using GitHub CLI
  • Loading branch information
iamazeem authored Oct 4, 2024
1 parent 1df7643 commit ecbfe73
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 36 deletions.
88 changes: 73 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
release:
types: [published]

defaults:
run:
shell: bash

env:
ARTIFACT_RETENTION_DAYS: 5

Expand All @@ -24,7 +28,6 @@ jobs:
- name: Set TAG on release
if: startsWith(github.ref, 'refs/tags/v')
id: tag
shell: bash
run: |
TAG="$GITHUB_REF_NAME"
echo "TAG: $TAG"
Expand Down Expand Up @@ -96,6 +99,7 @@ jobs:
TAG: ${{ needs.tag.outputs.TAG }}
AMD64_LINUX_GCC: amd64-linux-gcc
AMD64_LINUX_CLANG: amd64-linux-clang
AMD64_LINUX_MUSL: amd64-linux-musl
AMD64_WINDOWS_MINGW: amd64-windows-mingw
AMD64_MACOSX_GCC: amd64-macosx-gcc
ARM64_MACOSX_GCC: arm64-macosx-gcc
Expand All @@ -110,7 +114,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install -y mingw-w64 rpm alien nuget
sudo apt install -y mingw-w64 rpm alien nuget musl-tools
sudo apt remove -y jq
- name: Set up macOS (AMD64 and ARM64)
Expand Down Expand Up @@ -146,7 +150,6 @@ jobs:
CC: gcc
MAKE: make
RUN_TESTS: true
shell: bash
run: |
./scripts/ci-build.sh
./scripts/ci-create-debian-package.sh
Expand All @@ -159,7 +162,19 @@ jobs:
CC: clang
MAKE: make
RUN_TESTS: true
shell: bash
run: |
./scripts/ci-build.sh
./scripts/ci-create-debian-package.sh
./scripts/ci-create-rpm-package.sh
- name: Build on Linux (${{ env.AMD64_LINUX_MUSL }})
if: runner.os == 'Linux'
env:
PREFIX: ${{ env.AMD64_LINUX_MUSL }}
CC: musl-gcc
LDFLAGS: -static
MAKE: make
RUN_TESTS: true
run: |
./scripts/ci-build.sh
./scripts/ci-create-debian-package.sh
Expand All @@ -178,7 +193,6 @@ jobs:
AR: x86_64-w64-mingw32-ar
NM: x86_64-w64-mingw32-nm
WINDRES: x86_64-w64-mingw32-windres
shell: bash
run: |
./scripts/ci-build.sh
./scripts/ci-create-nuget-package.sh
Expand All @@ -190,7 +204,6 @@ jobs:
CC: gcc-13
MAKE: make
RUN_TESTS: false
shell: bash
run: |
./scripts/ci-build.sh
./$PREFIX/bin/zsv version
Expand All @@ -202,7 +215,6 @@ jobs:
CC: gcc-13
MAKE: make
RUN_TESTS: false
shell: bash
run: |
./scripts/ci-build.sh
./$PREFIX/bin/zsv version
Expand Down Expand Up @@ -249,6 +261,17 @@ jobs:
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.zip)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
env:
ARTIFACT_NAME: zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.zip
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIR }}/${{ env.ARTIFACT_NAME }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_GCC }}.deb)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
Expand All @@ -271,6 +294,17 @@ jobs:
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.deb)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
env:
ARTIFACT_NAME: zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.deb
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIR }}/${{ env.ARTIFACT_NAME }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_GCC }}.rpm)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
Expand All @@ -293,6 +327,17 @@ jobs:
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.rpm)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
env:
ARTIFACT_NAME: zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.rpm
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIR }}/${{ env.ARTIFACT_NAME }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_WINDOWS_MINGW }}.zip)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -370,6 +415,17 @@ jobs:
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.tar.gz)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
env:
ARTIFACT_NAME: zsv-${{ env.TAG }}-${{ env.AMD64_LINUX_MUSL }}.tar.gz
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIR }}/${{ env.ARTIFACT_NAME }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error

- name: Upload (zsv-${{ env.TAG }}-${{ env.AMD64_WINDOWS_MINGW }}.tar.gz)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -417,15 +473,17 @@ jobs:
# --- Upload release artifacts ---

- name: Upload release artifacts
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
files: |
${{ env.ARTIFACT_DIR }}/*.zip
${{ env.ARTIFACT_DIR }}/*.tar.gz
${{ env.ARTIFACT_DIR }}/*.deb
${{ env.ARTIFACT_DIR }}/*.rpm
${{ env.ARTIFACT_DIR }}/*.nupkg
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for ARTIFACT in "$ARTIFACT_DIR"/*.{zip,tar.gz,deb,rpm,nupkg}; do
if [[ -f $ARTIFACT ]]; then
echo "[INF] Uploading $ARTIFACT"
gh release upload "$GITHUB_REF_NAME" "$ARTIFACT"
echo "[INF] Artifact uploaded successfully! [$ARTIFACT]"
fi
done
# --- Update homebrew tap ---

Expand Down
3 changes: 3 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"MD028": false
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ You can also download pre-built binaries and packages from
[Actions](https://github.com/liquidaty/zsv/actions) for the latest commits and
PRs but these are retained only for limited days.

> [!IMPORTANT]
>
> For [musl libc](https://www.musl-libc.org/) static build, the dynamic
> extensions are not supported!
> [!NOTE]
>
> After `v0.3.9-alpha`, all package artifacts will be properly
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -812,30 +812,30 @@ echo "* zsv configuration *"
echo "****************************************************************"

if [ "$JQ_PREFIX" != "" ]; then
echo "* - jq-prefix: $JQ_PREFIX *"
echo "* - jq-prefix: $JQ_PREFIX *"
fi

if [ "$LDFLAGS_TERMCAP" = "" ]; then
echo "* - termcap: no. \`pretty\` will use default width assumption *"
else
echo "* - termcap: yes *"
echo "* - termcap: yes *"
fi

if [ "$ZSV_BUILD_SHEET" = "1" ]; then
echo "* - build sheet feature: yes *"
echo "* ncurses library: $NCLIB *"
echo "* - build sheet feature: yes *"
echo "* ncurses library: $NCLIB *"
else
echo "* - build sheet feature: no *"
echo "* - build sheet feature: no *"
fi

if [ "$HAVE_AVX512" = "1" ]; then
echo "* - using 512-bit AVX instruction set"
echo "* - using 512-bit AVX instruction set *"
elif [ "$CFLAGS_AVX" = "-mavx2" ]; then
echo "* - using 256-bit AVX2 instruction set"
echo "* - using 256-bit AVX2 instruction set *"
elif [ "$CFLAGS_AVX" = "-mavx" ]; then
echo "* - using 128-bit + AVX instruction set"
echo "* - using 128-bit + AVX instruction set *"
else
echo "* - using 128-bit vector size, no AVX"
echo "* - using 128-bit vector size, no AVX *"
fi

echo "****************************************************************"
Expand Down
15 changes: 10 additions & 5 deletions scripts/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ echo "[INF] Building and generating artifacts"
echo "[INF] PWD: $PWD"
echo "[INF] PREFIX: $PREFIX"
echo "[INF] CC: $CC"
echo "[INF] LDFLAGS: $LDFLAGS"
echo "[INF] MAKE: $MAKE"
echo "[INF] RUN_TESTS: $RUN_TESTS"
echo "[INF] ARTIFACT_DIR: $ARTIFACT_DIR"
Expand All @@ -43,7 +44,7 @@ echo "[INF] Listing compiler version [$CC]"
# ./scripts/ci-install-libjq.sh

echo "[INF] Configuring zsv"
# CFLAGS="-I$JQ_INCLUDE_DIR" LDFLAGS="-L$JQ_LIB_DIR"
# CFLAGS="-I$JQ_INCLUDE_DIR" LDFLAGS="-L$JQ_LIB_DIR"
./configure \
--prefix="$PREFIX" \
--disable-termcap
Expand All @@ -55,10 +56,14 @@ if [ "$RUN_TESTS" = true ]; then
"$MAKE" test
echo "[INF] Tests completed successfully!"

echo "[INF] Configuring example extension and running example extension tests"
echo "[INF] (cd app/ext_example && $MAKE CONFIGFILE=../../config.mk test)"
(cd app/ext_example && "$MAKE" CONFIGFILE=../../config.mk test)
echo "[INF] Tests completed successfully!"
if [ "$CC" = "musl-gcc" ] && [ "$(echo "$LDFLAGS" | grep -- "-static")" != "" ]; then
echo "[WRN] Dynamic extensions are not supported with static musl build! Skipping tests..."
else
echo "[INF] Configuring example extension and running example extension tests"
echo "[INF] (cd app/ext_example && $MAKE CONFIGFILE=../../config.mk test)"
(cd app/ext_example && "$MAKE" CONFIGFILE=../../config.mk test)
echo "[INF] Tests completed successfully!"
fi
fi

echo "[INF] Building"
Expand Down
10 changes: 6 additions & 4 deletions scripts/ci-create-debian-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ echo "[INF] ARTIFACT_DIR: $ARTIFACT_DIR"
echo "[INF] ARCH: $ARCH"
echo "[INF] VERSION: $VERSION"

echo "[INF] Listing linked libraries"
ldd "$PREFIX/bin/zsv"
if file -b "$PREFIX/bin/zsv" | grep "dynamically linked" >/dev/null; then
echo "[INF] Listing linked libraries"
ldd "$PREFIX/bin/zsv"
fi

echo "[INF] Setting up debian package buildtree"
mkdir -p "$DEBIAN_DIR" "$PREFIX/usr"
Expand All @@ -51,7 +53,7 @@ mv -f "./$PREFIX/bin" "./$PREFIX/usr/"
echo "[INF] Creating control file [$DEBIAN_CONTROL_FILE]"

INSTALLED_SIZE="$(echo $(du -s -c $PREFIX/usr/* | grep 'total') | cut -d ' ' -f1)"
cat << EOF > "$DEBIAN_CONTROL_FILE"
cat <<EOF >"$DEBIAN_CONTROL_FILE"
Package: zsv
Version: $VERSION
Section: extras
Expand All @@ -72,7 +74,7 @@ echo "[INF] --- [$DEBIAN_CONTROL_FILE] ---"

echo "[INF] Creating preinst script [$DEBIAN_CONTROL_FILE]"

cat << EOF > "$DEBIAN_PREINST_SCRIPT"
cat <<EOF >"$DEBIAN_PREINST_SCRIPT"
#!/bin/sh
rm -rf /usr/bin/zsv
Expand Down
8 changes: 5 additions & 3 deletions scripts/ci-create-rpm-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ echo "[INF] ARTIFACT_DIR: $ARTIFACT_DIR"
echo "[INF] ARCH: $ARCH"
echo "[INF] VERSION: $VERSION"

echo "[INF] Listing linked libraries"
ldd "$PREFIX/bin/zsv"
if file -b "$PREFIX/bin/zsv" | grep "dynamically linked" >/dev/null; then
echo "[INF] Listing linked libraries"
ldd "$PREFIX/bin/zsv"
fi

echo "[INF] Setting up RPM buildtree [$RPM_DIR]"
rm -rf "$RPM_DIR"
Expand All @@ -51,7 +53,7 @@ rm -rf "./$PREFIX/lib" "./$PREFIX/include"
cp -rfa "$PREFIX/bin" "$RPM_DIR/BUILD/usr/"

echo "[INF] Creating spec file [$RPM_SPEC_PATH]"
cat << EOF > "$RPM_SPEC_PATH"
cat <<EOF >"$RPM_SPEC_PATH"
%define _build_id_links none
%define _rpmfilename $RPM_PKG
Expand Down

0 comments on commit ecbfe73

Please sign in to comment.