Skip to content

Commit

Permalink
feat(build): Add full C++ build mode
Browse files Browse the repository at this point in the history
Rather than relying on -Wc++-compat, add a full build flag that uses all
CXXFLAGS and parses the source truly as C++.
  • Loading branch information
aws-nslick committed Oct 4, 2024
1 parent 46ae064 commit b944b54
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/distcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ jobs:
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--enable-neuron
else
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--with-cuda=/usr/local/cuda
fi
Expand All @@ -139,6 +141,9 @@ jobs:
cc:
- gcc
- clang
mode:
- cxx
- c
tracing:
- lttng
- none
Expand All @@ -154,7 +159,7 @@ jobs:
cc: gcc
cc-version: 13

name: u2204/${{ matrix.sdk }}/${{matrix.cc}}-${{matrix.cc-variant}}/build+test
name: u2204/${{ matrix.sdk }}/${{matrix.cc}}-${{matrix.cc-variant}}/build+test(${{ matrix.mode }})
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -230,12 +235,14 @@ jobs:
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--with-cuda=/usr/local/cuda/
else
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--enable-neuron
fi
Expand Down Expand Up @@ -268,7 +275,10 @@ jobs:
sdk:
- cuda
- neuron
name: CodeChecker - ${{ matrix.sdk }}
mode:
- cxx
- c
name: CodeChecker - ${{ matrix.sdk }} ${{ matrix.mode }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -309,12 +319,14 @@ jobs:
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--enable-neuron
else
./configure --with-mpi=/opt/amazon/openmpi \
--with-libfabric=/opt/amazon/efa \
--enable-tests \
--enable-cxx=${{ matrix.mode == 'cxx' && 'yes' || 'no' }} \
--enable-platform-aws \
--with-cuda=/usr/local/cuda
fi
Expand All @@ -333,7 +345,7 @@ jobs:
- name: Save CodeChecker HTML output.
uses: actions/upload-artifact@v4
with:
name: CodeChecker Bug Reports for ${{ matrix.sdk }}
name: CodeChecker Bug Reports for ${{ matrix.sdk }} ${{ matrix.mode }}
path: ${{ steps.codechecker.outputs.result-html-dir }}/*.html

- name: CodeChecker Pass Or Fail?
Expand Down
26 changes: 24 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS=
# Checks for programs
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
m4_version_prereq([2.70], [], [AC_PROG_CC_STDC])
AC_PROG_CXX
AC_C_INLINE
Expand All @@ -56,12 +57,18 @@ dnl between this and AC_PROG_CC.
AS_IF([test "${ax_enable_debug}" = "no"], [
dnl Enable O3 optimization
CFLAGS="${CFLAGS} -O3"
CXXFLAGS="${CXXFLAGS} -O3"
dnl use C++17, disable exceptions, and disable runtime type information
CXXFLAGS="-std=c++17 -fno-rtti -fno-exceptions"
dnl dead code elim
CFLAGS="${CFLAGS} -ffunction-sections -fdata-sections"
CXXFLAGS="${CXXFLAGS} -ffunction-sections -fdata-sections"
dnl https://maskray.me/blog/2021-05-09-fno-semantic-interposition
CFLAGS="${CFLAGS} -fno-semantic-interposition -fvisibility=hidden"
CXXFLAGS="${CXXFLAGS} -fno-semantic-interposition -fvisibility=hidden "
LDFLAGS="${LDFLAGS} -Bsymbolic"
])
CHECK_ENABLE_SANITIZER()
Expand Down Expand Up @@ -176,10 +183,15 @@ AS_IF([test "${enable_trace}" = "yes" ],
AC_DEFINE_UNQUOTED([OFI_NCCL_TRACE], [${trace}], [Defined to 1 unit test output should include TRACE level])

picky_cflags=""
picky_cxxflags=""
AC_DEFUN([ADD_PICKY_FLAGS],[
AC_LANG_PUSH([C])
AX_CHECK_COMPILE_FLAG([$1], [picky_cflags="${picky_cflags} $1"], [], [-Werror])
AC_LANG_POP()
AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([$1], [picky_cxxflags="${picky_cxxflags} $1"], [], [-Werror -x c++])
AC_LANG_POP()
])

dnl standard and normal
Expand Down Expand Up @@ -221,17 +233,27 @@ AC_ARG_ENABLE([picky-compiler],
AS_IF([test "${enable_picky_compiler}" != "no"],
[AC_MSG_NOTICE([Adding ${picky_cflags} to CFLAGS.])
CFLAGS="${CFLAGS} ${picky_cflags}"
CXXFLAGS="${CXXFLAGS} ${picky_cxxflags}"
AS_UNSET([picky_cxxflags])
AS_UNSET([picky_cflags])])

werror_flags="-Werror"
AC_ARG_ENABLE([werror],
[AS_HELP_STRING([--enable-werror], [(Developer) Enable setting -Werror. Off by default, unless building from Git tree.])])
AS_IF([test -d "${srcdir}/.git" -a -z "${enable_werror}"],
[AC_MSG_NOTICE([Found .git directory. Adding ${werror_flags} to CFLAGS.])
CFLAGS="${werror_flags} ${CFLAGS}"],
CXXFLAGS="${CXXFLAGS} ${werror_flags} "
CFLAGS="${CFLAGS} ${werror_flags} "],
[test "${enable_werror}" = "yes"],
[AC_MSG_NOTICE([Adding ${werror_flags} to CFLAGS.])
CFLAGS="${werror_flags} ${CFLAGS}"])
CXXFLAGS="${CXXFLAGS} ${werror_flags} "
CFLAGS="${CFLAGS} ${werror_flags} "])

AC_ARG_ENABLE([cxx],
[AS_HELP_STRING([--enable-cxx], [(Developer) Treat all C code as C++ source. Off by default.])])
AS_IF([test "${enable_cxx}" = "yes"],
[AC_MSG_NOTICE([Treating all files as CXX files.])
CFLAGS="-x c++ ${CXXFLAGS}"])

AC_SUBST([NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS])

Expand Down

0 comments on commit b944b54

Please sign in to comment.