Skip to content

Commit

Permalink
Merge pull request #234 from minijackson/epicsSetupHook
Browse files Browse the repository at this point in the history
Switch to setup-hook based EPICS builds
  • Loading branch information
stephane-cea authored Jan 16, 2025
2 parents 39502b5 + b8e2ddd commit 98120e4
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 144 deletions.
28 changes: 28 additions & 0 deletions pkgs/build-support/epics-setup-hook/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
makeSetupHook,
stdenv,
epnixLib,
}:
makeSetupHook {
name = "epics-setup-hook";

substitutions = {
# Note that since the setup hook is going into 'nativeBuildInputs',
# the platforms are "shifted",
# which means from the point of view of the setup hook,
# the host platform is the end package's build platform,
# and the target platform is the end package's host platform.

# "build" as in Nix terminology (the build machine)
build_arch = epnixLib.toEpicsArch stdenv.hostPlatform;
# "host" as in Nix terminology (the machine which will run the generated code)
host_arch = epnixLib.toEpicsArch stdenv.targetPlatform;
};

meta = {
description = "Instructions for building EPICS tops";
maintainers = with epnixLib.maintainers; [minijackson];
hidden = true;
};
}
./epics-setup-hook.sh
114 changes: 114 additions & 0 deletions pkgs/build-support/epics-setup-hook/epics-setup-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
epicsConfigurePhase() {
runHook preConfigure

if ! [[ -v enableParallelBuilding ]]; then
enableParallelBuilding=1
fi

appendToVar makeFlags "INSTALL_LOCATION=$out"

stripDebugList+=("bin/@host_arch@" "lib/@host_arch@")

# Ensure reproducibility when running Perl scripts that generate files,
# during the build.
export PERL_HASH_SEED=0

# This variable is used as a default version revision if no VCS is found.
#
# Since fetchgit and related fetchers remove the .git directory for
# reproducibility, EPICS fallsback to either the GENVERSIONDEFAULT variable
# if set (not the default), or the current date/time, which isn't
# reproducible.
echo 'GENVERSIONDEFAULT="EPNix"' >configure/CONFIG_SITE.local

# This prevents EPICS from detecting installed libraries on the host
# system, for when Nix is compiling without sandbox (e.g.: WSL2)
echo 'GNU_DIR="/var/empty"' >>configure/CONFIG_SITE.local

if [[ "@build_arch@" != "@host_arch@" ]]; then
stripDebugList+=("bin/@build_arch@" "lib/@build_arch@")

# Tell EPICS we are compiling to the given architecture.
# "host" as in Nix terminology (the machine which will run the generated code)
echo 'CROSS_COMPILER_TARGET_ARCHS="@host_arch@"' >>configure/CONFIG_SITE.local
fi

echo "${local_config_site-}" >>configure/CONFIG_SITE.local

# Undefine the SUPPORT variable here, since there is no single "support"
# directory and this variable is a source of conflicts between RELEASE files
echo "undefine SUPPORT" >configure/RELEASE.local

echo "${local_release-}" >>configure/RELEASE.local

# set to empty if unset
: "''${EPICS_COMPONENTS=}"

# For each EPICS-specific package (e.g. asyn, StreamDevice),
# add it to the 'configure/RELEASE.local' file
IFS=: read -ra components <<<"$EPICS_COMPONENTS"
for component in "${components[@]}"; do
echo "$component" >>configure/RELEASE.local
done

echo "=============================="
echo "CONFIG_SITE.local"
echo "------------------------------"
cat "configure/CONFIG_SITE.local"
echo "=============================="
echo "RELEASE.local"
echo "------------------------------"
cat "configure/RELEASE.local"
echo "------------------------------"

runHook postConfigure
}

if [ -z "${dontUseEpicsConfigure-}" ] && [ -z "${configurePhase-}" ]; then
configurePhase=epicsConfigurePhase
fi

epicsInstallPhase() {
runHook preInstall

# Don't do a manual `make install`, `make` already installs
# everything into `INSTALL_LOCATION`.

runHook postInstall
}

if [ -z "${dontUseEpicsInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=epicsInstallPhase
fi

# Automatically create binaries directly in `bin/` that calls the ones that
# are in `bin/linux-x86_64/`
# TODO: we should probably do the same for libraries
epicsInstallProgramsHook() {
echo "Installing programs in 'bin/@host_arch@' to 'bin'..."
if [[ -d "$out/bin/@host_arch@" ]]; then
for file in "$out/bin/@host_arch@/"*; do
[[ -x "$file" ]] || continue

echo "Installing program '$(basename "$file")' to 'bin'"
makeWrapper "$file" "$out/bin/$(basename "$file")"
done
fi
}

if [ -z "${dontInstallPrograms-}" ]; then
postInstallHooks+=(epicsInstallProgramsHook)
fi

epicsInstallIocBootHook() {
if [[ -d iocBoot ]]; then
echo "Installing 'iocBoot' folder..."
cp -rafv iocBoot -t "$out"
else
echo "No 'iocBoot' folder found, skipping"
fi
}

if [ -z "${dontInstallIocBoot-}" ]; then
postInstallHooks+=(epicsInstallIocBootHook)
fi
142 changes: 0 additions & 142 deletions pkgs/build-support/mk-epics-package.nix

This file was deleted.

58 changes: 58 additions & 0 deletions pkgs/build-support/mk-epics-package/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
stdenv,
lib,
makeWrapper,
perl,
epnix,
buildPackages,
readline,
...
}: {
pname,
varname,
local_config_site ? {},
local_release ? {},
isEpicsBase ? false,
depsBuildBuild ? [],
nativeBuildInputs ? [],
buildInputs ? [],
...
} @ attrs: let
# remove non standard attributes that cannot be coerced to strings
overridable = builtins.removeAttrs attrs ["local_config_site" "local_release"];
generateConf = (buildPackages.epnixLib.formats.make {}).generate;
in
stdenv.mkDerivation (overridable
// {
strictDeps = true;

# When cross-compiling,
# epics will build every project twice,
# once "build -> build", and once "build -> host",
# so we need a compiler for the "build -> build" compilation.
depsBuildBuild = depsBuildBuild ++ [buildPackages.stdenv.cc];

nativeBuildInputs =
nativeBuildInputs
++ [
makeWrapper
perl
readline
epnix.epicsSetupHook
];

# Also add perl into the non-native build inputs
# so that shebangs gets patched
buildInputs =
buildInputs
++ [perl readline]
++ (lib.optional (!isEpicsBase) epnix.epics-base);

setupHook = ./setup-hook.sh;

local_config_site = generateConf local_config_site;
local_release = generateConf local_release;

doCheck = attrs.doCheck or true;
checkTarget = "runtests";
})
5 changes: 5 additions & 0 deletions pkgs/build-support/mk-epics-package/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Export this package in a EPNix specific "EPICS_COMPONENTS" environment variable,
# so that we are able to list every EPICS-specific packages,
# to add them in the 'configure/RELEASE.local' file
# in dependent packages.
export "EPICS_COMPONENTS=${EPICS_COMPONENTS:+${EPICS_COMPONENTS}:}@varname@=@out@"
1 change: 0 additions & 1 deletion pkgs/build-support/setup-hook.sh

This file was deleted.

4 changes: 3 additions & 1 deletion pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ in
recurseIntoAttrs {
inherit epnixLib;

mkEpicsPackage = callPackage ./build-support/mk-epics-package.nix {};
mkEpicsPackage = callPackage ./build-support/mk-epics-package {};

pythonPackagesExtensions =
prev.pythonPackagesExtensions
Expand Down Expand Up @@ -48,6 +48,8 @@ in
};
epics-base = self.epics-base7;

epicsSetupHook = callPackage ./build-support/epics-setup-hook {};

# EPICS support modules

support = recurseExtensible (_self: {
Expand Down

0 comments on commit 98120e4

Please sign in to comment.