Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting statically linked IOCs #75

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
## Unreleased

### New features

* base: add bitshuffle support for areaDetector. by @gustavosr8 in
https://github.com/cnpem/epics-in-docker/pull/78

* base: support building fully static IOCs when not using containers. by
@ericonr in https://github.com/cnpem/epics-in-docker/pull/75.

## v0.10.1

This bug fix release is relevant to ipmiComm users.
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ desired registry on Git tag creation.
A YAML file must be added to the repository's `.github/workflows/` directory
(e.g. `.github/workflows/build.yml`), with the following contents:

```
```yaml
name: Build image
on:
push:
Expand Down Expand Up @@ -151,3 +151,38 @@ default image with older kernels.

It can be obtained directly from the [GitHub
registry](https://github.com/cnpem/epics-in-docker/pkgs/container/lnls-alpine-3.18-epics-7).

### Building fully static IOCs

Fully static IOCs can be built using the `lnls-build-static-ioc` script
provided by this image. One way to automate this is using a
`docker-compose.yml` file and running `docker compose up`; the file should have
the following contents:

```yaml
services:
build-static-ioc:
image: ghcr.io/cnpem/lnls-alpine-3.18-epics-7:RELEASE
volumes:
- type: bind
source: ./
target: /opt/REPOSITORY
working_dir: /opt/REPOSITORY
command: lnls-build-static-ioc REPOSITORY
```

Where `RELEASE` should be the latest available version in
<https://github.com/cnpem/epics-in-docker/tags>.

This will generate a versioned tarball containing the built IOC. For this
reason, it is recommended to use git repositories with tagged releases.
Furthermore, the `target` and `working_dir` keys are where the IOC expects to
be installed, meaning files like `envPaths` will encode this information. If it
is necessary to install it elsewhere, and building it with different values for
the keys isn't possible, it will be necessary to edit `envPaths`.

For development, one can set the `SKIP_CLEAN` environment variable (under
`environment`), to skip the cleanup build steps and speed up rebuilds.

Further `CONFIG_SITE` options can be added to a
`configure/CONFIG_SITE.local.lnls-build-static-ioc` file, if necessary.
1 change: 1 addition & 0 deletions base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ENV EPICS_MODULES_PATH /opt/epics/modules
ENV EPICS_RELEASE_FILE /opt/epics/RELEASE

COPY backport-epics-base-musl.patch .
COPY epics-base-static-linking.patch .
COPY install_epics.sh .
RUN ./install_epics.sh

Expand Down
48 changes: 48 additions & 0 deletions base/epics-base-static-linking.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From: https://github.com/epics-base/epics-base/pull/413
From bbee325ad9e2d044f44a523d5336d8be927f9b48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89rico=20Nogueira?= <[email protected]>
Date: Thu, 3 Aug 2023 15:57:23 -0300
Subject: [PATCH] Support full static linking in CONFIG_COMMON.

For now, only linuxCommon has the necessary definitions for this to
work. Users must define FULL_STATIC_BUILD in CONFIG_SITE for their IOC.
We don't add a new value for STATIC_BUILD since it's used in multiple
places and would make any changes to the build system more complicated.
---
configure/CONFIG_COMMON | 4 +++-
configure/os/CONFIG.Common.linuxCommon | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure/CONFIG_COMMON b/configure/CONFIG_COMMON
index 2595231f4..f9c711980 100644
--- a/configure/CONFIG_COMMON
+++ b/configure/CONFIG_COMMON
@@ -280,7 +280,9 @@ OPT_LDFLAGS = $(OPT_LDFLAGS_$($(BUILD_CLASS)_OPT))
STATIC_CFLAGS = $(STATIC_CFLAGS_$(STATIC_BUILD))
STATIC_CXXFLAGS = $(STATIC_CXXFLAGS_$(STATIC_BUILD))
STATIC_LDFLAGS = $(STATIC_LDFLAGS_$(STATIC_BUILD))
-STATIC_LDLIBS = $(STATIC_LDLIBS_$(STATIC_BUILD))
+
+STATIC_LDLIBS_FULL_YES = YES
+STATIC_LDLIBS = $(STATIC_LDLIBS_$(if $(STATIC_LDLIBS_FULL_$(FULL_STATIC_BUILD)),FULL,$(STATIC_BUILD)))

#--------------------------------------------------
# cflags for shared library src files
diff --git a/configure/os/CONFIG.Common.linuxCommon b/configure/os/CONFIG.Common.linuxCommon
index 24b1a0c33..4eb14d32e 100644
--- a/configure/os/CONFIG.Common.linuxCommon
+++ b/configure/os/CONFIG.Common.linuxCommon
@@ -20,8 +20,10 @@ OP_SYS_LDFLAGS += -rdynamic

# Linker flags for static & shared-library builds
STATIC_LDFLAGS_YES= -Wl,-Bstatic
+STATIC_LDFLAGS_FULL= -Wl,-Bstatic
STATIC_LDFLAGS_NO=
STATIC_LDLIBS_YES= -Wl,-Bdynamic
+STATIC_LDLIBS_FULL= -Wl,-Bstatic

# Set runtime path for shared libraries if LINKER_USE_RPATH=YES
SHRLIBDIR_RPATH_LDFLAGS_YES = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
--
2.34.1

5 changes: 5 additions & 0 deletions base/install_epics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ lnls-get-n-unpack -l https://epics-controls.org/download/base/base-${EPICS_BASE_
mv base-${EPICS_BASE_VERSION} ${EPICS_BASE_PATH}

patch -d ${EPICS_BASE_PATH} -Np1 < backport-epics-base-musl.patch
patch -d ${EPICS_BASE_PATH} -Np1 < epics-base-static-linking.patch

if [ -n "$COMMANDLINE_LIBRARY" ]; then
echo "COMMANDLINE_LIBRARY = $COMMANDLINE_LIBRARY" > ${EPICS_BASE_PATH}/configure/CONFIG_SITE.local
fi

install_module base EPICS_BASE
57 changes: 57 additions & 0 deletions base/lnls-build-static-ioc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

set -eux

IOC=$1

echo "backing up configure/ files..."
# any of these files might not exist
cp -p configure/RELEASE /tmp || true
cp -p configure/CONFIG_SITE.local /tmp || true

restore_configure() {
echo "restoring configure/ files..."

# rm is necessary in case CONFIG_SITE.local didn't exist, otherwise
# we might leave a file belonging to root around
rm -f configure/CONFIG_SITE.local

cp -p /tmp/RELEASE configure/ || true
cp -p /tmp/CONFIG_SITE.local configure/ || true
}
trap restore_configure EXIT

echo "overwriting configure/ files..."
cp /opt/epics/RELEASE configure/
cat << "EOF" > configure/CONFIG_SITE.local
STATIC_BUILD=YES
FULL_STATIC_BUILD=YES
USR_LDFLAGS = -static-pie
-include $(TOP)/configure/CONFIG_SITE.local.lnls-build-static-ioc
EOF

git config --global --add safe.directory $PWD

make_skip() {
# :- is used so we don't error out if SKIP_CLEAN is undefined
if [ -z "${SKIP_CLEAN:-}" ]; then
make "$@"
fi
}

make_skip distclean
make -j$(nproc)

version=$(git describe --tags)

echo $version > $IOC-version
cat << "EOF" > /tmp/globs
.git/
*.tar.gz
O.*/
EOF
# this trick is done so the resulting tarball has a root $IOC/ directory
(cd .. && tar caf $IOC/$IOC-${version}.tar.gz -X /tmp/globs $IOC/)
rm $IOC-version

make_skip distclean
7 changes: 6 additions & 1 deletion base/musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ARG JOBS

RUN apk add --no-cache \
bash \
git \
g++ \
libevent-dev \
libevent-static \
Expand All @@ -27,6 +28,7 @@ RUN apk add --no-cache \
re2c \
readline-dev \
readline-static \
ncurses-static \
python3-dev \
py3-numpy-dev

Expand All @@ -42,8 +44,9 @@ WORKDIR /opt/epics
COPY install-functions.sh .

COPY backport-epics-base-musl.patch .
COPY epics-base-static-linking.patch .
COPY install_epics.sh .
RUN ./install_epics.sh
RUN COMMANDLINE_LIBRARY=READLINE_NCURSES ./install_epics.sh
henriquesimoes marked this conversation as resolved.
Show resolved Hide resolved

ARG PVXS_VERSION
ARG SEQUENCER_VERSION
Expand Down Expand Up @@ -71,3 +74,5 @@ COPY ipmicomm.patch .
COPY caputlog-waveform-fix.patch .
COPY install_modules.sh .
RUN NEEDS_TIRPC=YES ./install_modules.sh

COPY lnls-build-static-ioc.sh /usr/local/bin/lnls-build-static-ioc