Skip to content

Commit 228ea38

Browse files
committed
Rewrite build system in CMake
1 parent 1fdc23b commit 228ea38

File tree

6 files changed

+70
-94
lines changed

6 files changed

+70
-94
lines changed

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2+
3+
project(slurm-singularity-exec LANGUAGES CXX)
4+
5+
include(GNUInstallDirs)
6+
7+
if (NOT CMAKE_BUILD_TYPE)
8+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
9+
endif()
10+
11+
option(INSTALL_PLUGSTACK_CONF "Whether to install a plugstack config" OFF)
12+
13+
set(SLURM_SYSCONFDIR /etc/slurm CACHE STRING "Slurm sysconfdir")
14+
set(SLURM_PLUGSTACK_CONF_D ${SLURM_SYSCONFDIR}/plugstack.conf.d
15+
CACHE STRING "Slurm plugstack conf dir")
16+
set(PLUGIN_DEFAULT_ARG "" CACHE STRING "Plugin default= arg")
17+
set(PLUGIN_BIND_ARG ${SLURM_SYSCONFDIR},/var/spool/slurm,/var/run/munge
18+
CACHE STRING "Plugin bind= arg")
19+
set(PLUGIN_EXTRA_ARGS "" CACHE STRING "Plugin args= arg")
20+
21+
find_path(SLURM_INCLUDE_DIR
22+
NAMES spank.h
23+
PATH_SUFFIXES slurm
24+
REQUIRED)
25+
26+
set(target ${PROJECT_NAME})
27+
add_library(${target} SHARED main.cpp)
28+
set_target_properties(${target} PROPERTIES PREFIX "")
29+
target_compile_features(${target} PRIVATE cxx_std_17)
30+
target_include_directories(${target} PRIVATE ${SLURM_INCLUDE_DIR})
31+
target_link_libraries(${target} PRIVATE -static-libstdc++ -static-libgcc)
32+
install(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})
33+
34+
set(WRAPPER slurm-singularity-wrapper.sh)
35+
install(FILES ${WRAPPER} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}
36+
PERMISSIONS
37+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
38+
GROUP_READ GROUP_EXECUTE
39+
WORLD_READ WORLD_EXECUTE)
40+
41+
set(plugstackconf singularity-exec.conf)
42+
configure_file(${plugstackconf}.in ${plugstackconf} @ONLY)
43+
44+
if (INSTALL_PLUGSTACK_CONF)
45+
install(FILES ${CMAKE_BINARY_DIR}/${plugstackconf} DESTINATION ${SLURM_PLUGSTACK_CONF_D})
46+
endif()

Makefile

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ File | Description
2828
2929
Build this plug-in using `g++` from the GNU Compiler Collection (GCC) version 8
3030
or newer. The plug-ins are compiled against this header file `spank.h` [02].
31-
Fedora distributes this file in the `slurm-devel` RPM package [^DoUiD].
31+
Fedora distributes this file in the `slurm-devel` RPM package [^DoUiD]. CMake is
32+
available via the `cmake` package.
3233

3334
```sh
34-
# build the Singularity SPANK plug-in
35-
make
36-
# build the plug-in, and install the binary and configuration files
37-
sudo make install
35+
cmake -S . -B build # configure the project and choose a build dir
36+
cmake --build build # build the Singularity SPANK plug-in
37+
sudo cmake --install build # install the binary and configuration files
38+
# on older CMake: cmake --build build --target install
3839
```
3940

4041
By default the plug-in `singularity-exec.so` is installed to `/usr/lib64/slurm`.
@@ -56,7 +57,7 @@ mkdir /etc/slurm/plugstack.conf.d
5657
cat > /etc/slurm/plugstack.conf <<EOF
5758
include /etc/slurm/plugstack.conf.d/*.conf'
5859
EOF
59-
# reference the path to the plug-in and the wrapper script
60+
# reference the path to the plug-in and the wrapper script
6061
cat > /etc/slurm/plugstack.conf.d/singularity-exec.conf <<EOF
6162
required /usr/lib64/slurm/singularity-exec.so default= script=/usr/libexec/slurm-singularity-wrapper.sh bind= args=disabled
6263
EOF
@@ -69,10 +70,12 @@ required a restart of `slurmd`:
6970
Option | Description
7071
-----------------------|------------------------------------------------
7172
`default=<path>` | Path to the Singularity container launched by default. If this is set user require to explicitly use an empty `--singularity-container=` option to prevent the start of a container.
72-
`script=<path>` | Path to the wrapper script which consumes the input arguments and environment variables set by the plugin to launch the Singularity container.
73+
`script=<path>` | Path to the wrapper script which consumes the input arguments and environment variables set by the plugin to launch the Singularity container.
7374
`bind=<spec>` | List of paths to bind-mount into the container by default. Please reference the section about [User-defined bind paths][95] in the Singularity User Documentation [^E9F6O].
7475
`args=<string>` | List of [command-line arguments][94] passed to `singularity exec`. Disable support for this feature by setting `args=disabled`. This will prompt an error for an unrecognized option if the user adds the `--singularity-args=` option. Use an empty string `args=""` to enable support for singularity arguments without a default configuration. Supply default for all users by adding a list of options i.e. `args="--home /network/$USER"`
7576

77+
Passing `-DINSTALL_PLUGSTACK_CONF=ON` to the CMake configure command will automate the above configuration.
78+
7679
## Usage
7780

7881
The plugin adds following command-line options to `salloc`, `srun` and `sbatch`:
@@ -123,7 +126,7 @@ cat > job.sh <<EOF
123126
#SBATCH --singularity-args="--no-home"
124127
/bin/grep -i pretty /etc/os-release
125128
EOF
126-
SLURM_SINGULARITY_DEBUG=true SLURM_SINGULARITY_GLOBAL=--silent sbatch job.sh
129+
SLURM_SINGULARITY_DEBUG=true SLURM_SINGULARITY_GLOBAL=--silent sbatch job.sh
127130
```
128131

129132
## Development
@@ -146,71 +149,31 @@ Start a Vagrant box to build an RPM package:
146149
# synced from the host
147150
cd /vagrant
148151

149-
# build and install the plugin...
150-
sudo make install
152+
cmake -S . -B build # configure the project and choose a build dir
153+
cmake --build build # build the Singularity SPANK plug-in
154+
sudo cmake --install build # install the binary and configuration files
151155

152-
# ...alternativly use the RPM package described in the next section
153156
sudo systemctl enable --now munge slurmctld slurmd
154157
```
155158

156-
## Package
157-
158-
Start a Vagrant box to build an RPM package:
159-
160-
```sh
161-
./containers.sh && vagrant up el8 && vagrant ssh el8 # for example...
162-
```
163-
164-
Build an RPM package using `slurm-singularity-exec.spec`:
165-
166-
```bash
167-
# synced from the host
168-
cd /vagrant
169-
rpmdev-setuptree
170-
# prepare the source code archive from this repository
171-
tar --create \
172-
--verbose \
173-
--gzip \
174-
--exclude=.git \
175-
--transform 's,^,slurm-singularity-exec-21.08/,' \
176-
--file ~/rpmbuild/SOURCES/slurm-singularity-exec-21.08.tar.gz .
177-
# install build dependencies if required...
178-
dnf builddep -y slurm-singularity-exec.spec
179-
# build the binary package
180-
rpmbuild -bb slurm-singularity-exec.spec
181-
# list files in the package
182-
rpm -ql ~/rpmbuild/RPMS/$(uname -p)/slurm-singularity*
183-
# install the package
184-
sudo rpm --force -i ~/rpmbuild/RPMS/$(uname -p)/slurm-singularity-exec-*.rpm
185-
```
186-
187-
```bash
188-
# copy the binary package into the working-directory
189-
cp -v ~/rpmbuild/RPMS/$(uname -p)/slurm-singularity-exec-*.rpm /vagrant
190-
# install the plugin if required
191-
vagrant plugin install vagrant-rsync-back
192-
# download the backage from the Vagrant box
193-
vagrant rsync-back el8
194-
```
195-
196159
## References
197160

198-
[^bk1WA]: SPANK - Slurm Plug-in Architecture
161+
[^bk1WA]: SPANK - Slurm Plug-in Architecture
199162
<https://slurm.schedmd.com/spank.html>
200163

201-
[^AV7Wy]: Slurm SPANK Header File
164+
[^AV7Wy]: Slurm SPANK Header File
202165
<https://github.com/SchedMD/slurm/blob/master/slurm/spank.h>
203166

204-
[^oJ91o]: SingularityCE, Sylabs Inc.
167+
[^oJ91o]: SingularityCE, Sylabs Inc.
205168
<https://sylabs.io>
206169

207-
[^wtl3M]: Apptainer, Linux Foundation
170+
[^wtl3M]: Apptainer, Linux Foundation
208171
<https://apptainer.org>
209172

210-
[^E9F6O]: Apptainer Documentation
173+
[^E9F6O]: Apptainer Documentation
211174
<https://apptainer.org/documentation>
212175

213-
[^DoUiD]: Fedora Slurm RPM Package
176+
[^DoUiD]: Fedora Slurm RPM Package
214177
<https://src.fedoraproject.org/rpms/slurm>
215178

216179
[99]: singularity-exec.conf

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
extern "C"
3030
{ // SPANK include
31-
#include "spank.h"
31+
#include <slurm/spank.h>
3232
}
3333

3434
/// string_view::starts_with replacement

singularity-exec.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

singularity-exec.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Singularity Plug-in
2+
#
3+
required @CMAKE_INSTALL_FULL_LIBEXECDIR@/@[email protected] default=@PLUGIN_DEFAULT_ARG@ script=@CMAKE_INSTALL_FULL_LIBEXECDIR@/@WRAPPER@ bind=@PLUGIN_BIND_ARG@ args="@PLUGIN_EXTRA_ARGS@"

0 commit comments

Comments
 (0)