Skip to content

Commit

Permalink
Merge pull request #6454 from garlick/macos
Browse files Browse the repository at this point in the history
fix macos portability issues
  • Loading branch information
mergify[bot] authored Nov 21, 2024
2 parents d00a449 + 6e3bc87 commit 01d3650
Show file tree
Hide file tree
Showing 32 changed files with 258 additions and 54 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ EXTRA_DIST = \
NEWS.md \
scripts/requirements-dev.txt \
scripts/install-deps-deb.sh \
scripts/install-deps-rpm.sh
scripts/install-deps-rpm.sh \
scripts/install-deps-macos.sh \
scripts/configure-macos.sh

ACLOCAL_AMFLAGS = -I config

Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ AC_CHECK_HEADERS( \
xlocale.h \
endian.h \
inttypes.h \
link.h \
)

##
Expand Down Expand Up @@ -232,12 +233,15 @@ AC_REPLACE_FUNCS( \
argz_add \
envz_add \
strerrorname_np \
pipe2 \
mempcpy \
)
X_AC_CHECK_PTHREADS
X_AC_CHECK_COND_LIB(rt, clock_gettime)
X_AC_CHECK_COND_LIB(dl, dlerror)
X_AC_MALLOC
AC_CHECK_LIB(m, floor)
AC_SEARCH_LIBS(epoll, libepoll-shim)

AC_ARG_ENABLE([docs],
AS_HELP_STRING([--disable-docs], [disable building docs]))
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_future_get.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ETIMEDOUT
A timeout passed to :func:`flux_future_wait_for` expired before the future
was fulfilled.

EDEADLOCK
EDEADLOCK (or EDEADLK on BSD systems)
:func:`flux_future_wait_for` would likely deadlock due to an
improperly initialized future.

Expand Down
2 changes: 2 additions & 0 deletions doc/test/spell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ gc
tgz
tmpfiles
EDEADLOCK
EDEADLK
BSD
setpgrp
nosetpgrp
checkpointed
Expand Down
29 changes: 29 additions & 0 deletions scripts/configure-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

die() {
echo "$(basename $0): $@" >&2
exit 1
}

DEPS_SCRIPT=scripts/install-deps-macos.sh

test -f $DEPS_SCRIPT || die "please run from the top level of the source tree"
test -d macos-venv || die "please run $DEPS_SCRIPT first"

eval "$(/opt/homebrew/bin/brew shellenv)"

CPPFLAGS=-I${HOMEBREW_PREFIX}/include/lua
CPPFLAGS="-I$(brew --prefix epoll-shim)/include/libepoll-shim ${CPPFLAGS}"
LDFLAGS=-L${HOMEBREW_PREFIX}/lib

PKG_CONFIG_PATH=$(pkg-config --variable pc_path pkg-config)
PKG_CONFIG_PATH=$(brew --prefix libarchive)/lib/pkgconfig:${PKG_CONFIG_PATH}

PATH=$(brew --prefix libtool)/libexec/gnubin:$PATH

source macos-venv/bin/activate

./autogen.sh

CPPFLAGS=$CPPFLAGS LDFLAGS=$LDFLAGS PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
./configure
39 changes: 39 additions & 0 deletions scripts/install-deps-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

die() {
echo "$(basename $0): $@" >&2
exit 1
}

test -f scripts/requirements-dev.txt || die "Please run from top of source tree"

eval "$(/opt/homebrew/bin/brew shellenv)"

brew install \
autoconf \
automake \
libtool \
make \
pkg-config \
epoll-shim \
zeromq \
jansson \
lz4 \
libarchive \
hwloc \
sqlite \
[email protected] \
python3 \
cffi \
libyaml \
jq

brew link [email protected]

python3 -m venv macos-venv
source macos-venv/bin/activate

pip3 install setuptools
pip3 install -r scripts/requirements-dev.txt

echo "Now run scripts/configure-macos.sh"
4 changes: 2 additions & 2 deletions src/broker/boot_pmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <limits.h>
#include <unistd.h>
#include <jansson.h>
#include <flux/hostlist.h>
Expand Down Expand Up @@ -164,7 +164,7 @@ static int format_bind_uri (char *buf, int bufsz, attr_t *attrs, int rank)
goto overflow;
}
else {
char ipaddr[HOST_NAME_MAX + 1];
char ipaddr[_POSIX_HOST_NAME_MAX + 1];
flux_error_t error;
int flags = 0;
const char *interface = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/broker/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef _BROKER_H
#define _BROKER_H

#include <sys/param.h>
#include <limits.h>
#include <flux/optparse.h>

#include "src/common/libczmqcontainers/czmq_containers.h"
Expand All @@ -23,7 +23,7 @@ struct broker {
flux_watcher_t *w_internal;
flux_reactor_t *reactor;
optparse_t *opts;
char hostname[MAXHOSTNAMELEN + 1];
char hostname[_POSIX_HOST_NAME_MAX + 1];

struct overlay *overlay;
uint32_t rank;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/builtin/relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "builtin.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <limits.h>
#include <stdio.h>
#include <glob.h>
#include <ctype.h>
Expand Down Expand Up @@ -131,7 +131,7 @@ static int cmd_relay (optparse_t *p, int ac, char *av[])
flux_t *h;
int optindex;
char *uri;
char hostname [HOST_NAME_MAX + 1];
char hostname [_POSIX_HOST_NAME_MAX + 1];

/* If possible, initialize logging prefix as local hostname. (In the
* unlikely event gethostname(3) fails, use "unknown-host".)
Expand Down
4 changes: 4 additions & 0 deletions src/common/libflux/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <assert.h>
#include <flux/core.h>

#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
#endif

#include "src/common/libczmqcontainers/czmq_containers.h"
#include "src/common/libutil/aux.h"

Expand Down
4 changes: 4 additions & 0 deletions src/common/libflux/test/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <string.h>
#include <flux/core.h>

#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
#endif

#include "src/common/libczmqcontainers/czmq_containers.h"
#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtap/tap.h"
Expand Down
6 changes: 0 additions & 6 deletions src/common/libhostlist/hostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
/* max number of ranges that will be processed between brackets */
#define MAX_RANGES 10240 /* 10K Ranges */

/* size of internal hostname buffer (+ some slop), hostnames will probably
* be truncated if longer than MAXHOSTNAMELEN */
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif

/* max size of internal hostrange buffer */
#define MAXHOSTRANGELEN 1024

Expand Down
13 changes: 3 additions & 10 deletions src/common/libhostlist/hostrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <sys/param.h>
#include <limits.h>
#include <unistd.h>
#include <stdbool.h>

Expand All @@ -31,13 +31,6 @@
/* max number of ranges that will be processed between brackets */
#define MAX_RANGES 10240 /* 10K Ranges */

/* size of internal hostname buffer (+ some slop), hostnames will probably
* be truncated if longer than MAXHOSTNAMELEN
*/
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif

/* max size of internal hostrange buffer */
#define MAXHOSTRANGELEN 1024

Expand Down Expand Up @@ -457,7 +450,7 @@ size_t hostrange_numstr (struct hostrange * hr, size_t n, char *buf)

char * hostrange_host_tostring (struct hostrange * hr, int depth)
{
char buf[MAXHOSTNAMELEN + 16];
char buf[_POSIX_HOST_NAME_MAX + 16];
int len;

if (!hr || depth < 0) {
Expand All @@ -475,7 +468,7 @@ char * hostrange_host_tostring (struct hostrange * hr, int depth)
errno = ERANGE;
return NULL;
}
snprintf (buf+len, MAXHOSTNAMELEN+15 - len, "%0*lu",
snprintf (buf+len, sizeof (buf) - len, "%0*lu",
hr->width, hr->lo + depth);
}
return strdup (buf);
Expand Down
4 changes: 4 additions & 0 deletions src/common/libkvs/test/kvs_checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <errno.h>
#include <flux/core.h>

#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
#endif

#include "src/common/libtap/tap.h"

#include "kvs_checkpoint.h"
Expand Down
4 changes: 3 additions & 1 deletion src/common/libmissing/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ EXTRA_libmissing_la_SOURCES = \
envz.c \
macros.h \
strerrorname_np.h \
json_object_update_recursive.h
json_object_update_recursive.h \
pipe2.h \
mempcpy.h
4 changes: 3 additions & 1 deletion src/common/libmissing/argz.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#ifndef HAVE_MEMPCPY
#include "mempcpy.h"
#endif


/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
Expand Down
24 changes: 24 additions & 0 deletions src/common/libmissing/mempcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/************************************************************\
* Copyright 2024 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <errno.h>

#include "mempcpy.h"

void *mempcpy (void *dest, const void *src, size_t len)
{
return memcpy (dest, src, len) + len;
}

// vi:ts=4 sw=4 expandtab
16 changes: 16 additions & 0 deletions src/common/libmissing/mempcpy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/************************************************************\
* Copyright 2024 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#ifndef _MEMPCPY_H
#define _MEMPCPY_H 1

void *mempcpy (void *dest, const void *src, size_t len);

#endif // !_MEMPCPY
46 changes: 46 additions & 0 deletions src/common/libmissing/pipe2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/************************************************************\
* Copyright 2024 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "pipe2.h"

static int setflags (int fd, int flags)
{
int oflags;
if ((oflags = fcntl (fd, F_GETFL)) < 0
|| fcntl (fd, F_SETFL, oflags | flags) < 0)
return -1;
return 0;
}

int pipe2 (int pipefd[2], int flags)
{
int pfd[2];
if (pipe (pfd) < 0)
return -1;
if (setflags (pfd[0], flags) < 0 || setflags (pfd[1], flags) < 0) {
int saved_errno = errno;
(void)close (pfd[0]);
(void)close (pfd[1]);
errno = saved_errno;
return -1;
}
pipefd[0] = pfd[0];
pipefd[1] = pfd[1];
return 0;
}

// vi:ts=4 sw=4 expandtab
16 changes: 16 additions & 0 deletions src/common/libmissing/pipe2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/************************************************************\
* Copyright 2024 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#ifndef _PIPE2_H
#define _PIPE2_H 1

int pipe2 (int pipefd[2], int flags);

#endif // !_PIPE2_H
4 changes: 4 additions & 0 deletions src/common/liboptparse/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

#include <string.h>

#ifndef HAVE_MEMPCPY
#include "src/common/libmissing/mempcpy.h"
#endif

#ifdef VMS
# include <unixlib.h>
#endif
Expand Down
Loading

0 comments on commit 01d3650

Please sign in to comment.