Skip to content

Commit

Permalink
Add build for lfortran (#98)
Browse files Browse the repository at this point in the history
* Build lfortran
  • Loading branch information
mattgodbolt authored Nov 28, 2024
1 parent f269be7 commit 40b4225
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- vast
- mads
- bloaty
- lfortran
steps:
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile.lfortran
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt update -y -q && apt upgrade -y -q && apt update -y -q && \
apt install -y -q \
bison \
build-essential \
cmake \
curl \
git \
libzstd-dev \
llvm-12-dev \
ninja-build \
patchelf \
python-is-python3 \
python3 \
re2c \
unzip \
xz-utils \
zlib1g-dev

RUN mkdir -p /root
COPY lfortran /root/
COPY common.sh /root/

WORKDIR /root
54 changes: 54 additions & 0 deletions lfortran/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -euo pipefail
source common.sh

VERSION="${1}"
LAST_REVISION="${3-}"

URL="https://github.com/lfortran/lfortran.git"
if [[ "${VERSION}" == trunk ]]; then
VERSION=trunk-$(date +%Y%m%d)
BRANCH=main
REMOTE=heads/main
else
BRANCH=v"${VERSION}"
REMOTE=tags/${BRANCH}
fi

FULLNAME=lfortran-${VERSION}
OUTPUT=$2/${FULLNAME}.tar.xz
REVISION=$(get_remote_revision "${URL}" "${REMOTE}")

initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}"

git clone "${URL}" --depth=1 "--branch=${BRANCH}"

OUTPUT=$(realpath "${OUTPUT}")
DEST=$(realpath prefix)
SOURCE=$(realpath lfortran)

mkdir build
cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-Wall -Wextra -O3 -funroll-loops -DNDEBUG" \
-DWITH_LLVM=yes \
-DLFORTRAN_BUILD_ALL=yes \
-DWITH_STACKTRACE=no \
-DWITH_RUNTIME_STACKTRACE=yes \
-DCMAKE_INSTALL_PREFIX="${DEST}" \
-DCMAKE_INSTALL_LIBDIR=share/lfortran/lib \
-Bbuild \
-S"${SOURCE}"
ninja -C build
ninja -C build install

mkdir "${DEST}/lib"

# Copy all shared object dependencies into the release directory to create a hermetic build, per
# Compiler Explorer requirements. Update rpath for these objects to $ORIGIN.
cp $(ldd "${DEST}/bin/lfortran" | grep -E '=> /' | grep -Ev 'lib(pthread|c|dl|rt).so' | awk '{print $3}') "${DEST}/lib"
patchelf --set-rpath '$ORIGIN/../lib' "${DEST}/bin/lfortran"

complete "${DEST}" "${FULLNAME}" "${OUTPUT}"

0 comments on commit 40b4225

Please sign in to comment.