First class IRDL with Elixir macros #406
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build precompiled NIFs | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "*" | |
pull_request: | |
branches: ["main"] | |
paths-ignore: | |
- "*.md" | |
- "**/*.md" | |
- "LICENSE*" | |
concurrency: | |
group: precompiled-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
PRE_BUILT_RELEASE_GITHUB_TOKEN: ${{ secrets.PRE_BUILT_RELEASE_GITHUB_TOKEN }} | |
jobs: | |
generate_id: | |
name: Generate ID of release | |
runs-on: ubuntu-latest | |
outputs: | |
formatted_date: ${{ steps.date.outputs.formatted_date }} | |
steps: | |
- name: Get current date | |
id: date | |
run: echo "formatted_date=$(date +'%Y-%m-%d-%H%M')" >> $GITHUB_OUTPUT | |
build_release: | |
needs: [generate_id] | |
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) | |
runs-on: ${{ matrix.job.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
nif: ["2.16"] | |
job: | |
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 } | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Elixir | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: "1.14.0" # Define the elixir version [required] | |
otp-version: "24.1" # Define the OTP version [required] | |
- name: Set up Zig | |
uses: goto-bus-stop/setup-zig@v1 | |
with: | |
version: 0.11.0 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Restore dependencies cache | |
uses: actions/cache@v3 | |
with: | |
path: deps | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install dependencies | |
run: mix deps.get | |
- uses: seanmiddleditch/gha-setup-ninja@master | |
- name: Install pre-build LLVM | |
run: | | |
python3 -m pip install -r dev-requirements.txt | |
echo "LLVM_CONFIG_PATH=$(python3 -c 'import mlir;print(mlir.__path__[0])')/bin/llvm-config" >> "$GITHUB_ENV" | |
- name: Production compile | |
env: | |
MIX_ENV: prod | |
run: | | |
BEAVER_BUILD_CMAKE=1 mix compile | |
- name: Run patchelf | |
env: | |
MIX_ENV: prod | |
run: | | |
set -u | |
find _build/${MIX_ENV}/lib/beaver/native_install/lib -name "*.so*" -maxdepth 1 -type f | while read sofile; do | |
echo "==> before replace needed" | |
patchelf --print-needed $sofile | |
patchelf --replace-needed libMLIRBeaver.so.17 libMLIRBeaver.so $sofile | |
echo "==> after" | |
patchelf --print-needed $sofile | |
echo "==> before set rpath" | |
patchelf --print-rpath $sofile | |
patchelf --set-rpath '$ORIGIN:$ORIGIN/lib:$ORIGIN/../../..' --force-rpath \ | |
$sofile | |
echo "==> after" | |
patchelf --print-rpath $sofile | |
done | |
- name: Tar production native libraries | |
id: tar | |
env: | |
MIX_ENV: prod | |
run: | | |
set -u | |
ls _build/${MIX_ENV}/lib/beaver/native_install/lib | |
LIB_FINAL_SO=$(ls _build/${MIX_ENV}/lib/beaver/native_install/lib | grep -E "libbeaver.+so") | |
LIB_FINAL_NAME=${LIB_FINAL_SO}.tar.gz | |
tar --dereference -cvzf ${LIB_FINAL_NAME} \ | |
-C $PWD/_build/${MIX_ENV}/lib/beaver/native_install/lib $(cd $PWD/_build/${MIX_ENV}/lib/beaver/native_install/lib && ls *.so) \ | |
-C $PWD/_build/${MIX_ENV}/lib/beaver/native_install/lib $(cd $PWD/_build/${MIX_ENV}/lib/beaver/native_install/lib && ls *.dylib) \ | |
-C $PWD/_build/${MIX_ENV}/lib/beaver/native_install $(cd $PWD/_build/${MIX_ENV}/lib/beaver/native_install && ls *.ex) | |
echo "LIB_FINAL_NAME=${LIB_FINAL_NAME}" >> $GITHUB_OUTPUT | |
- name: Purge artifacts | |
run: | | |
python3 -m pip uninstall -y mlir | |
mix clean | |
- name: Start mock server in the background | |
run: | | |
python3 -m http.server --directory . &> /dev/null & | |
- name: Replace test config | |
run: | | |
cp config/release-test.exs config/test.exs | |
- name: Run download task | |
env: | |
MIX_ENV: test | |
run: | | |
# run a force build to generate metadata of rustler_precompiled | |
mix compile --force || true | |
mix rustler_precompiled.download Beaver.MLIR.CAPI --only-local --print | |
- name: Run tests with prebuilt | |
run: | | |
mix clean | |
mix test --exclude vulkan --exclude todo | |
- name: Publish archives and packages | |
uses: softprops/action-gh-release@v1 | |
if: ${{ github.repository == 'beaver-lodge/beaver' && env.PRE_BUILT_RELEASE_GITHUB_TOKEN != null }} | |
with: | |
files: | | |
${{ steps.tar.outputs.LIB_FINAL_NAME }} | |
repository: beaver-lodge/beaver-prebuilt | |
token: ${{ secrets.PRE_BUILT_RELEASE_GITHUB_TOKEN }} | |
tag_name: ${{ needs.generate_id.outputs.formatted_date }} | |
- name: Test dev compile | |
if: ${{ github.repository == 'beaver-lodge/beaver' && env.PRE_BUILT_RELEASE_GITHUB_TOKEN != null }} | |
run: | | |
rm config/dev.exs | |
echo 'import Config' >> config/dev.exs | |
echo 'config :beaver, :prebuilt_base_url, "https://github.com/beaver-lodge/beaver-prebuilt/releases/download/${{ needs.generate_id.outputs.formatted_date }}"' >> config/dev.exs | |
mix compile |