Skip to content

Build libdwarf natives & JAR #4

Build libdwarf natives & JAR

Build libdwarf natives & JAR #4

name: Build libdwarf natives & JAR
on:
workflow_dispatch:
env:
# -------------------------------------------------------------------------
# Bump this tag/branch to rebuild libdwarf
# TODO: Change this to a tag once all the build issues that were recently fixed are in a tag.
LIBDWARF_VERSION: main
# -------------------------------------------------------------------------
# --------------------------------------------------------------------------- #
# L I N U X N A T I V E B U I L D #
# --------------------------------------------------------------------------- #
jobs:
build-linux:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: .cache/libdwarf
key: libdwarf-linux-${{ env.LIBDWARF_VERSION }}
- name: Install build tool-chain
run: |
sudo apt-get update -y
sudo apt-get install --no-install-recommends -y \
build-essential zlib1g-dev libzstd-dev \
autoconf automake libtool pkg-config
- name: Build shared library
run: |
git clone --depth 1 --branch "$LIBDWARF_VERSION" \
https://github.com/davea42/libdwarf-code libdwarf-code
cd ./libdwarf-code
WRAP=../jna-wrapper/src/main/resources/linux-x86-64
mkdir -p "$WRAP" ../out ../.cache/libdwarf/linux
sh autogen.sh
./configure --enable-shared \
--enable-dwarfgen --disable-static --prefix="$PWD/install"
make -j"$(nproc)"
make install
shopt -s nullglob
for so in install/lib/libdwarf*.so*; do
cp -L "$so" "$WRAP/"
cp -L "$so" ../out/
cp -L "$so" ../.cache/libdwarf/linux/
done
shopt -u nullglob
- uses: actions/upload-artifact@v4
with:
name: libdwarf-linux
path: out/*
# --------------------------------------------------------------------------- #
# W I N D O W S N A T I V E B U I L D #
# --------------------------------------------------------------------------- #
build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
env:
PYTHONIOENCODING: "utf-8"
steps:
- uses: actions/checkout@v4
- name: MSYS2 setup
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
base-devel
git
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-zlib
autoconf
automake
libtool
pkgconf
- uses: actions/cache@v4
with:
path: .cache/libdwarf
key: libdwarf-windows-${{ env.LIBDWARF_VERSION }}
- name: Fetch libdwarf sources
run: |
git clone --depth 1 --branch "$LIBDWARF_VERSION" \
https://github.com/davea42/libdwarf-code libdwarf-code
- name: Build libdwarf
run: |
set -euo pipefail
cd libdwarf-code
sh autogen.sh
./configure --enable-shared \
--enable-dwarfgen --disable-static --prefix="$PWD/install"
make -j"$(nproc)"
mkdir -p ./temp
cp "$PWD"/src/lib/libdwarf/.libs/*.dll ./temp/libdwarf.dll
cp "$PWD"/src/lib/libdwarfp/.libs/*.dll ./temp/libdwarfp.dll
DLL_DIR="$PWD/temp"
WRAP=../jna-wrapper/src/main/resources/win32-x86-64
mkdir -p "$WRAP" ../out ../.cache/libdwarf/windows
shopt -s nullglob
for dll in "$DLL_DIR"/*.dll; do
cp "$dll" "$WRAP/"
cp "$dll" ../out/
cp "$dll" ../.cache/libdwarf/windows/
done
shopt -u nullglob
- uses: actions/upload-artifact@v4
with:
name: libdwarf-windows
path: out/*
# --------------------------------------------------------------------------- #
# J A V A W R A P P E R (shaded JAR) #
# --------------------------------------------------------------------------- #
build-java:
needs: [ build-linux, build-windows ]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
- name: Package shaded JAR
run: |
mvn -B -ntp -f jna-wrapper/pom.xml package -DskipTests
mkdir -p out
cp jna-wrapper/target/libdwarf*.jar out/
- uses: actions/upload-artifact@v4
with:
name: libdwarf-jar
path: out/*
# --------------------------------------------------------------------------- #
# P U B L I S H (commit only if something changed) #
# --------------------------------------------------------------------------- #
publish:
needs: [ build-linux, build-windows, build-java ]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
permissions:
contents: write # allows pushing commits
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # we are about to commit
- uses: actions/download-artifact@v4
with:
path: _artifacts
- name: Sync natives & JAR into repo
run: |
set -euo pipefail
copy_if_changed() {
local src="$1" dest="$2"
[ -e "$src" ] || return 0
mkdir -p "$(dirname "$dest")"
if [ -f "$dest" ] && cmp -s "$src" "$dest"; then
echo "Unchanged: $dest"
else
cp "$src" "$dest"
echo "Updated: $dest"
fi
}
# ----- natives (linux) -----
find _artifacts/libdwarf-linux -type f -print0 |
while IFS= read -r -d '' f; do
rel=${f#*_artifacts/libdwarf-linux/}
copy_if_changed "$f" "jna-wrapper/src/main/resources/linux-x86-64/$rel"
done
# ----- natives (windows) -----
find _artifacts/libdwarf-windows -type f -print0 |
while IFS= read -r -d '' f; do
rel=${f#*_artifacts/libdwarf-windows/}
copy_if_changed "$f" "jna-wrapper/src/main/resources/win32-x86-64/$rel"
done
# ----- shaded JAR -----
jar_src=$(ls _artifacts/libdwarf-jar/*.jar)
copy_if_changed "$jar_src" "src/libdwarf.jar"
- name: Commit & push (only when something changed)
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add src/libdwarf.jar jna-wrapper/src/main/resources || true
if git diff --cached --quiet; then
echo "Everything is up-to-date — nothing to commit."
exit 0
fi
git commit -m "Update pre-built libdwarf natives & JAR to ${LIBDWARF_VERSION}"
git push origin HEAD