From 069b4b7800c6873815b82d17fcc0ea3b3336be2a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 14 Mar 2024 09:20:59 +0100 Subject: [PATCH 1/6] Add CI support * copy GitHub actions from develop * copy testme.sh from develop Signed-off-by: Steffen Jaeckel --- .github/workflows/deploy.yml | 47 ++++++++ .github/workflows/main.yml | 216 +++++++++++++++++++++++++++++++++ testme.sh | 225 +++++++++++++++++++++-------------- 3 files changed, 401 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 000000000..a06ac73c5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,47 @@ +############################################################################# +# # +# Packagecloud deployment via GH actions for LibTomMath # +# (https://github.com/libtom/libtommath.git) # +# # +############################################################################# + +name: Deploy + +on: + workflow_dispatch + +jobs: + deploy-to-packagecloud: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-20.04, ubuntu-22.04 ] + steps: + - uses: actions/checkout@v2 + - name: set Ubuntu codename + run: | + echo "ubuntu_codename="$(lsb_release -sc) >> "$GITHUB_ENV" + - name: install dependencies + run: | + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null + echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${{ env.ubuntu_codename }} main" | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null + sudo apt-get update -qq + sudo apt-get install -y cmake gcc + - name: build packages + run: | + mkdir -p build + cd build + cmake -DBUILD_SHARED_LIBS=Off -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="/usr" .. + make -j$(nproc) + cpack -G DEB + cmake -DBUILD_SHARED_LIBS=On -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="/usr" .. + make -j$(nproc) + cpack -G DEB + - name: push deb packages to packagecloud.io + uses: computology/packagecloud-github-action@v0.6 + with: + PACKAGE-NAME: build/packages/ubuntu/${{ env.ubuntu_codename }}/*.deb + PACKAGECLOUD-USERNAME: libtom + PACKAGECLOUD-REPONAME: packages + PACKAGECLOUD-DISTRO: ubuntu/${{ env.ubuntu_codename }} + PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..24f881f3d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,216 @@ +############################################################################# +# # +# GitHub Actions test-suite for LibTomMath # +# (https://github.com/libtom/libtommath.git) # +# # +############################################################################# + +name: CI + +# Tests restricted to the following branches of LTM. +on: + push: + branches: + - master + - develop + - /^release\/.*$/ + - /^support\/.*$/ + - /^ci\/.*$/ + pull_request: + branches: + - master + - develop + - /^release\/.*$/ + - /^support\/.*$/ + - /^ci\/.*$/ + +jobs: + Docs: + runs-on: ubuntu-20.04 + container: texlive/texlive:latest-full + steps: + - uses: actions/checkout@v3 + - name: generate PDF + run: | + make docs V=1 + cp doc/bn.pdf bn-${{ github.run_id }}.pdf + - name: upload PDF + uses: actions/upload-artifact@v3 + with: + name: bn-${{ github.run_id }}.pdf + path: bn-${{ github.run_id }}.pdf + Testme: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-20.04 ] + # The environment given to the programs in the build + # We have only one program and the variable $BUILDOPTIONS + # has only the options to that program: testme.sh + + config: + # Check c89 <-> c99 roundtrip + - { BUILDOPTIONS: '--c89-c99-roundtrip', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + # Check source code format + - { BUILDOPTIONS: '--format', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'astyle' } + # Check public symbols of dynamic libraries + - { BUILDOPTIONS: '--symbols', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'libtool-bin' } + # Run always with valgrind (no sanitizer, but debug info) + - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --with-valgrind', SANITIZER: '', COMPILE_DEBUG: '1', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + # Alternative big-int version of mp_log(_n) + - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --cflags=-DS_MP_WORD_TOO_SMALL_C="" --with-valgrind', SANITIZER: '', COMPILE_DEBUG: '1', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + # Shared library build + - { BUILDOPTIONS: '--with-cc=gcc --make-option=-f --make-option=makefile.shared', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '1', CONV_WARNINGS: '', OTHERDEPS: 'libtool-bin' } + # GCC for the 32-bit architecture (no valgrind) + - { BUILDOPTIONS: '--with-cc=gcc --with-m32', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'libc6-dev-i386 gcc-multilib' } + # Alternative big-int version of mp_log(_n) for the 32-bit architecture (no valgrind) + - { BUILDOPTIONS: '--with-cc=gcc --with-m32 --cflags=-DS_MP_WORD_TOO_SMALL_C="" ', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'libc6-dev-i386 gcc-multilib' } + # clang for the 32-bit architecture (no valgrind) + - { BUILDOPTIONS: '--with-cc=clang-10 --with-m32', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10 gcc-multilib' } + # RSA superclass with tests (no sanitizer, but debug info) + - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --cflags=-DLTM_NOTHING --cflags=-DSC_RSA_1_WITH_TESTS --limit-valgrind', SANITIZER: '', COMPILE_DEBUG: '1', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + + # Test "autotuning", the automatic evaluation and setting of the Toom-Cook cut-offs. + #- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --limit-valgrind --make-option=tune' + #- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_32BIT --limit-valgrind --make-option=tune' + #- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --limit-valgrind --make-option=tune' + #- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_16BIT --limit-valgrind --make-option=tune' + #- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_32BIT --limit-valgrind --make-option=tune' + - { BUILDOPTIONS: '--with-cc=clang-10 --limit-valgrind --make-option=tune', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10' } + + # GCC for the x86-64 architecture testing against a different Bigint-implementation + # with 333333 different inputs. + #- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --limit-valgrind' + # ... and a better random source. + - { BUILDOPTIONS: '--with-cc=gcc --test-vs-mtest=333333 --mtest-real-rand --limit-valgrind', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + + # clang for the x86-64 architecture testing against a different Bigint-implementation + # with 333333 different inputs + - { BUILDOPTIONS: '--with-cc=clang-10 --test-vs-mtest=333333 --limit-valgrind', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10' } + # ... and a better random source. + - { BUILDOPTIONS: '--with-cc=clang-10 --test-vs-mtest=333333 --mtest-real-rand --limit-valgrind', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10' } + + # GCC for the x64_32 architecture (32-bit longs and 32-bit pointers) + # TODO: Probably not possible to run anything in x32 in GH actions + # but needs to be checked to be sure. + - { BUILDOPTIONS: '--with-cc=gcc --with-mx32', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'libc6-dev-x32 gcc-multilib' } + + # GCC for the x86-64 architecture (64-bit longs and 64-bit pointers) + - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + - { BUILDOPTIONS: '--with-cc=gcc-10 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'gcc-10' } + - { BUILDOPTIONS: '--with-cc=gcc-8 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'gcc-8' } + - { BUILDOPTIONS: '--with-cc=gcc-7 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'gcc-7' } + + # clang for x86-64 architecture (64-bit longs and 64-bit pointers) + - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'relaxed', OTHERDEPS: 'clang-10 llvm-10' } + - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } + - { BUILDOPTIONS: '--with-cc=clang-10 --cflags=-DMP_USE_MEMOPS --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } + - { BUILDOPTIONS: '--with-cc=clang-10 --c89 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } + - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind --cflags=-DMP_PREC=MP_MIN_PREC', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10' } + - { BUILDOPTIONS: '--with-cc=clang-12 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-12 llvm-12' } + - { BUILDOPTIONS: '--with-cc=clang-9 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-9 llvm-9' } + - { BUILDOPTIONS: '--with-cc=clang-8 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-8 llvm-8' } + - { BUILDOPTIONS: '--with-cc=clang-7 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-7 llvm-7' } + - { BUILDOPTIONS: '--with-cc=clang-6.0 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-6.0 llvm-6.0' } + # Link time optimization + - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '1', CONV_WARNINGS: '', OTHERDEPS: '' } + #- { BUILDOPTIONS: '--with-cc=clang-7 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '1', CONV_WARNINGS: '', OTHERDEPS: '' } + + # GCC for the x86-64 architecture with restricted limb sizes + # formerly started with the option "--with-low-mp" to testme.sh + # but testing all three in one run took to long and timed out. + - { BUILDOPTIONS: '--with-cc=gcc --cflags=-DMP_16BIT --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + - { BUILDOPTIONS: '--with-cc=gcc --cflags=-DMP_32BIT --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + # Alternative big-int version of mp_log(_n) + - { BUILDOPTIONS: '--with-cc=gcc --cflags=-DMP_16BIT --cflags=-DS_MP_WORD_TOO_SMALL_C="" --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + - { BUILDOPTIONS: '--with-cc=gcc --cflags=-DMP_32BIT --cflags=-DS_MP_WORD_TOO_SMALL_C="" --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } + + # clang for the x86-64 architecture with restricted limb sizes + - { BUILDOPTIONS: '--with-cc=clang --cflags=-DMP_16BIT --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang llvm' } + - { BUILDOPTIONS: '--with-cc=clang --cflags=-DMP_32BIT --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang llvm' } + steps: + - uses: actions/checkout@v3 + - name: install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y valgrind ${{ matrix.config.OTHERDEPS }} + sudo apt-cache search gcc | grep '^gcc-[0-9\.]* ' + sudo apt-cache search clang | grep compiler + - name: run tests + env: + SANITIZER: ${{ matrix.config.SANITIZER }} + COMPILE_DEBUG: ${{ matrix.config.COMPILE_DEBUG }} + COMPILE_LTO: ${{ matrix.config.COMPILE_LTO }} + CONV_WARNINGS: ${{ matrix.config.CONV_WARNINGS }} + COMMIT_MESSAGE: ${{ github.event.commits[0].message }} + PR_NUMBER: ${{ github.event.number }} + # The actual script the jobs run. + run: | + ./testme.sh ${{ matrix.config.BUILDOPTIONS }} + # In case of a CI error a success might get signaled + # even without any test run. This file also keeps any notes + # printed from the tests which might come handy from time + # to time. + # Valgrid will print its output to stderr which will not show up + # in test_*.log. testme.sh accepts one additional option to + # valgrind and "--valgrind-options=--log-fd=1" sends the output + # of Valgrind to stdout instead. + - name: regular logs + if: ${{ !failure() }} + run: | + cat test_*.log || true + # Compilation failures are in gcc_errors_*.log + # Failed tests in test_*.log + # Files do not exist in case of success + - name: error logs + if: ${{ failure() }} + run: | + cat test_*.log || true + cat valgrind_test.log || true + cat gcc_errors_*.log || true + + amalgam: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: install dependencies + run: | + make amalgamated_timing + + CMake: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-20.04, ubuntu-22.04 ] + build_type: [ '', -DCMAKE_BUILD_TYPE=Debug, -DCMAKE_BUILD_TYPE=Release, -DCMAKE_BUILD_TYPE=RelWithDebInfo, -DCMAKE_BUILD_TYPE=MinSizeRel ] + cc: [ clang, gcc ] + config: + # Static library build + - { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=Off' } + # Shared library build + - { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=On' } + steps: + - uses: actions/checkout@v3 + - name: install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y cmake gcc clang llvm + - name: build + run: | + mkdir build + cd build + CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} .. + make -j$(nproc) + - name: test + run: | + cd build + CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} -DBUILD_TESTING=On .. + make -j$(nproc) + ctest + - name: test (in demo folder) + run: | + mkdir -p demo/build + cd demo/build + CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} .. + make -j$(nproc) + ctest diff --git a/testme.sh b/testme.sh index 40fa32d50..089e42a70 100755 --- a/testme.sh +++ b/testme.sh @@ -20,71 +20,73 @@ TEST_CFLAGS="" _help() { - echo "Usage options for $(basename $0) [--with-cc=arg [other options]]" - echo - echo "Executing this script without any parameter will only run the default" - echo "configuration that has automatically been determined for the" - echo "architecture you're running." - echo - echo " --with-cc=* The compiler(s) to use for the tests" - echo " This is an option that will be iterated." - echo - echo " --test-vs-mtest=* Run test vs. mtest for '*' operations." - echo " Only the first of each options will be" - echo " taken into account." - echo - echo "To be able to specify options a compiler has to be given with" - echo "the option --with-cc=compilername" - echo "All other options will be tested with all MP_xBIT configurations." - echo - echo " --with-{m64,m32,mx32} The architecture(s) to build and test" - echo " for, e.g. --with-mx32." - echo " This is an option that will be iterated," - echo " multiple selections are possible." - echo " The mx32 architecture is not supported" - echo " by clang and will not be executed." - echo - echo " --cflags=* Give an option to the compiler," - echo " e.g. --cflags=-g" - echo " This is an option that will always be" - echo " passed as parameter to CC." - echo - echo " --make-option=* Give an option to make," - echo " e.g. --make-option=\"-f makefile.shared\"" - echo " This is an option that will always be" - echo " passed as parameter to make." - echo - echo " --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT." - echo - echo " --mtest-real-rand Use real random data when running mtest." - echo - echo " --with-valgrind" - echo " --with-valgrind=* Run in valgrind (slow!)." - echo - echo " --with-travis-valgrind Run with valgrind on Travis on specific branches." - echo - echo " --valgrind-options Additional Valgrind options" - echo " Some of the options like e.g.:" - echo " --track-origins=yes add a lot of extra" - echo " runtime and may trigger the 30 minutes" - echo " timeout." - echo - echo "Godmode:" - echo - echo " --all Choose all architectures and gcc and clang" - echo " as compilers but does not run valgrind." - echo - echo " --format Runs the various source-code formatters" - echo " and generators and checks if the sources" - echo " are clean." - echo - echo " -h" - echo " --help This message" - echo - echo " -v" - echo " --version Prints the version. It is just the number" - echo " of git commits to this file, no deeper" - echo " meaning attached" + cat << EOF +Usage options for $(basename $0) [--with-cc=arg [other options]] + +Executing this script without any parameter will only run the default +configuration that has automatically been determined for the +architecture you're running. + + --with-cc=* The compiler(s) to use for the tests + This is an option that will be iterated. + + --test-vs-mtest=* Run test vs. mtest for '*' operations. + Only the first of each options will be + taken into account. + +To be able to specify options a compiler has to be given with +the option --with-cc=compilername +All other options will be tested with all MP_xBIT configurations. + + --with-{m64,m32,mx32} The architecture(s) to build and test + for, e.g. --with-mx32. + This is an option that will be iterated, + multiple selections are possible. + The mx32 architecture is not supported + by clang and will not be executed. + + --cflags=* Give an option to the compiler, + e.g. --cflags=-g + This is an option that will always be + passed as parameter to CC. + + --make-option=* Give an option to make, + e.g. --make-option="-f makefile.shared" + This is an option that will always be + passed as parameter to make. + + --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT. + + --mtest-real-rand Use real random data when running mtest. + + --with-valgrind + --with-valgrind=* Run in valgrind (slow!). + + --limit-valgrind Run with valgrind on CI only on specific branches. + + --valgrind-options Additional Valgrind options + Some of the options like e.g.: + --track-origins=yes add a lot of extra + runtime and may trigger the 30 minutes + timeout. + +Godmode: + + --all Choose all architectures and gcc and clang + as compilers but does not run valgrind. + + --format Runs the various source-code formatters + and generators and checks if the sources + are clean. + + -h + --help This message + + -v + --version Prints the version. It is just the number + of git commits to this file, no deeper + meaning attached +EOF exit 0 } @@ -103,11 +105,30 @@ _die() fi } +_fixup_cflags() { + compiler_version=$(echo "$1="$($1 -dumpversion)) + case "$compiler_version" in + clang*=4.2.1) + # one of my versions of clang complains about some stuff in stdio.h and stdarg.h ... + TEST_CFLAGS="-Wno-typedef-redefinition" + ;; + gcc*=9) + # gcc 9 seems to sometimes think that variables are uninitialized, but they are. + TEST_CFLAGS="-Wno-maybe-uninitialized" + ;; + *) + TEST_CFLAGS="" + ;; + esac + echo $compiler_version +} + _make() { echo -ne " Compile $1 $2" suffix=$(echo ${1}${2} | tr ' ' '_') - CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS > /dev/null 2>gcc_errors_${suffix}.log + _fixup_cflags "$1" + CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS 2>gcc_errors_${suffix}.log errcnt=$(wc -l < gcc_errors_${suffix}.log) if [[ ${errcnt} -gt 1 ]]; then echo " failed" @@ -195,6 +216,9 @@ VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 " #VALGRIND_OPTS="" VALGRIND_BIN="" CHECK_FORMAT="" +CHECK_SYMBOLS="" +C89="" +C89_C99_ROUNDTRIP="" TUNE_CMD="./etc/tune -t -r 10 -L 3" alive_pid=0 @@ -217,6 +241,12 @@ do "--with-m64" | "--with-m32" | "--with-mx32") ARCHFLAGS="$ARCHFLAGS ${1:6}" ;; + --c89) + C89="1" + ;; + --c89-c99-roundtrip) + C89_C99_ROUNDTRIP="1" + ;; --with-cc=*) COMPILERS="$COMPILERS ${1#*=}" ;; @@ -235,8 +265,8 @@ do fi start_alive_printing ;; - --with-travis-valgrind*) - if [[ ("$TRAVIS_BRANCH" == "develop" && "$TRAVIS_PULL_REQUEST" == "false") || "$TRAVIS_BRANCH" == *"valgrind"* || "$TRAVIS_COMMIT_MESSAGE" == *"valgrind"* ]] + --limit-valgrind*) + if [[ ("$GITHUB_BASE_REF" == "develop" && "$PR_NUMBER" == "") || "$GITHUB_REF_NAME" == *"valgrind"* || "$COMMIT_MESSAGE" == *"valgrind"* ]] then if [[ ${1#*d} != "" ]] then @@ -268,6 +298,9 @@ do --format) CHECK_FORMAT="1" ;; + --symbols) + CHECK_SYMBOLS="1" + ;; --all) COMPILERS="gcc clang" ARCHFLAGS="-m64 -m32 -mx32" @@ -291,6 +324,35 @@ function _check_git() { git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 ) } +[[ "$C89" == "1" ]] && make c89 + +if [[ "$C89_C99_ROUNDTRIP" == "1" ]] +then + make c89 + make c99 + _check_git "make c89; make c99" + exit $? +fi + +if [[ "$CHECK_SYMBOLS" == "1" ]] +then + make -f makefile.shared + cat << EOF + + +The following list shows the discrepancy between +the shared library and the Windows dynamic library. +To fix this error, one of the following things +has to be done: +* the script which generates tommath.def has to be modified + (function generate_def() in helper.pl). +* The exported symbols are really different for some reason + This has to be manually investigated. + +EOF + exit $(comm -3 <(nm -D --defined-only .libs/libtommath.so | cut -d' ' -f3 | grep -v '^_' | sort) <(tail -n+9 tommath.def | tr -d ' ' | sort) | tee /dev/tty | wc -l) +fi + if [[ "$CHECK_FORMAT" == "1" ]] then make astyle @@ -307,7 +369,7 @@ fi # default to CC environment variable if no compiler is defined but some other options if [[ "$COMPILERS" == "" ]] && [[ "$ARCHFLAGS$MAKE_OPTIONS$CFLAGS" != "" ]] then - COMPILERS="$CC" + COMPILERS="${CC:-cc}" # default to CC environment variable and run only default config if no option is given elif [[ "$COMPILERS" == "" ]] then @@ -336,7 +398,7 @@ _banner if [[ "$TEST_VS_MTEST" != "" ]] then make clean > /dev/null - _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent" + _make "${compilers[0]}" "${archflags[0]} $CFLAGS" "mtest_opponent" echo _make "gcc" "$MTEST_RAND" "mtest" echo @@ -357,15 +419,6 @@ do echo "Skipped compiler $i, file not found" continue fi - compiler_version=$(echo "$i="$($i -dumpversion)) - if [ "$compiler_version" == "clang=4.2.1" ] - then - # one of my versions of clang complains about some stuff in stdio.h and stdarg.h ... - TEST_CFLAGS="-Wno-typedef-redefinition" - else - TEST_CFLAGS="" - fi - echo $compiler_version for a in "${archflags[@]}" do @@ -376,17 +429,15 @@ do fi if [[ "$VALGRIND_BIN" != "" ]] then - _runvalgrind "$i $a" "$CFLAGS" + _runvalgrind "$i" "$a $CFLAGS" [ "$WITH_LOW_MP" != "1" ] && continue - _runvalgrind "$i $a" "-DMP_8BIT $CFLAGS" - _runvalgrind "$i $a" "-DMP_16BIT $CFLAGS" - _runvalgrind "$i $a" "-DMP_32BIT $CFLAGS" + _runvalgrind "$i" "$a -DMP_16BIT $CFLAGS" + _runvalgrind "$i" "$a -DMP_32BIT $CFLAGS" else - _runtest "$i $a" "$CFLAGS" + _runtest "$i" "$a $CFLAGS" [ "$WITH_LOW_MP" != "1" ] && continue - _runtest "$i $a" "-DMP_8BIT $CFLAGS" - _runtest "$i $a" "-DMP_16BIT $CFLAGS" - _runtest "$i $a" "-DMP_32BIT $CFLAGS" + _runtest "$i" "$a -DMP_16BIT $CFLAGS" + _runtest "$i" "$a -DMP_32BIT $CFLAGS" fi done done From aeebd863b4e49affdb874480fb240a0a914828c9 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 14 Mar 2024 09:24:17 +0100 Subject: [PATCH 2/6] Copy cmake support from develop Signed-off-by: Steffen Jaeckel --- CMakeLists.txt | 319 ++++++++++++++++++++++++++++++++++++++++++++ demo/CMakeLists.txt | 66 +++++++++ helper.pl | 31 ++++- sources.cmake | 167 +++++++++++++++++++++++ 4 files changed, 579 insertions(+), 4 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 demo/CMakeLists.txt create mode 100644 sources.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..4077189fa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,319 @@ +# SPDX-License-Identifier: Unlicense +# +# LibTomMath, a free open source portable number theoretic multiple-precision +# integer (MPI) library written entirely in C. +# + +cmake_minimum_required(VERSION 3.10) + +project(libtommath + VERSION 1.2.0 + DESCRIPTION "A free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C." + HOMEPAGE_URL "https://www.libtom.net/LibTomMath" + LANGUAGES C) + +# package release version +# bump if re-releasing the same VERSION + patches +# set to 1 if releasing a new VERSION +set(PACKAGE_RELEASE_VERSION 1) + +#----------------------------------------------------------------------------- +# Include cmake modules +#----------------------------------------------------------------------------- +include(GNUInstallDirs) +include(CheckIPOSupported) +include(CMakePackageConfigHelpers) +# default is "No tests" +option(BUILD_TESTING "" OFF) +include(CTest) +include(sources.cmake) + +#----------------------------------------------------------------------------- +# Options +#----------------------------------------------------------------------------- +option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF) + +#----------------------------------------------------------------------------- +# Add support for ccache if desired +#----------------------------------------------------------------------------- +find_program(CCACHE ccache) + +if(CCACHE) + option(ENABLE_CCACHE "Enable ccache." ON) +endif() + +# use ccache if installed +if(CCACHE AND ENABLE_CCACHE) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) +endif() + +#----------------------------------------------------------------------------- +# Compose CFLAGS +#----------------------------------------------------------------------------- + +# Some information ported from makefile_include.mk + + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE "Release") +endif() + +# We only differentiate between MSVC and GCC-compatible compilers +if(MSVC) + set(LTM_C_FLAGS -W3) +elseif(WATCOM) + set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3) +else() + set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow + -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align + -Wstrict-prototypes -Wpointer-arith -Wsystem-headers) + set(CMAKE_C_FLAGS_DEBUG "-g3") + set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2") + set(CMAKE_C_FLAGS_MINSIZEREL "-Os") +endif() + +# What compiler do we have and what are their...uhm... peculiarities +if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang") + list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header) + # Clang requires at least '-O1' for dead code elimination + set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}") +endif() +if(CMAKE_C_COMPILER MATCHES "mingw") + list(APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast) +endif() +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + list(APPEND LTM_C_FLAGS -Wno-nullability-completeness) +endif() +if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN") + list(APPEND LTM_C_FLAGS -no-undefined) +endif() + +# TODO: coverage (lgcov) + +# If the user set the environment variables at generate-time, append them +# in order to allow overriding our defaults. +# ${LTM_CFLAGS} means the user passed it via sth like: +# $ cmake -DLTM_CFLAGS="foo" +list(APPEND LTM_C_FLAGS ${LTM_CFLAGS}) +list(APPEND LTM_LD_FLAGS ${LTM_LDFLAGS}) + +#----------------------------------------------------------------------------- +# library target +#----------------------------------------------------------------------------- +add_library(${PROJECT_NAME} + ${SOURCES} + ${HEADERS} +) + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +target_compile_options(${PROJECT_NAME} BEFORE PRIVATE + ${LTM_C_FLAGS} +) +target_link_options(${PROJECT_NAME} BEFORE PRIVATE + ${LTM_LD_FLAGS} +) + +set(PUBLIC_HEADERS tommath.h) +set(C89 False CACHE BOOL "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install") +if(C89) + list(APPEND PUBLIC_HEADERS tommath_c89.h) +endif() + +set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME tommath + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + PUBLIC_HEADER "${PUBLIC_HEADERS}" +) + +option(COMPILE_LTO "Build with LTO enabled") +if(COMPILE_LTO) + check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO) + if(COMPILER_SUPPORTS_LTO) + set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + message(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.") + endif() +endif() + +#----------------------------------------------------------------------------- +# demo target +#----------------------------------------------------------------------------- + +if(BUILD_TESTING) + enable_testing() + add_subdirectory(demo) +endif() + +#----------------------------------------------------------------------------- +# Install/export targets and files +#----------------------------------------------------------------------------- +set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake") +set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake") +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") + +install(TARGETS ${PROJECT_NAME} + EXPORT ${TARGETS_EXPORT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} +) + +# Install libtommath.pc for pkg-config if we build a shared library +if(BUILD_SHARED_LIBS) + # Let the user override the default directory of the pkg-config file (usually this shouldn't be required to be changed) + set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files") + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + @ONLY + ) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR} + ) +endif() + +# generate package version file +write_basic_package_version_file( + ${PROJECT_VERSION_FILE} + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +# Windows uses a different help sytem. +if((NOT WIN32) AND (NOT CMAKE_HOST_WIN32)) +# install manpage (not gzipped, some BSD's do not want it compressed?) +install(FILES ${CMAKE_SOURCE_DIR}/doc/tommath.3 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man3/ +) +endif() + +# install version file +install(FILES ${PROJECT_VERSION_FILE} + DESTINATION ${CONFIG_INSTALL_DIR} +) + +# build directory package config +export(EXPORT ${TARGETS_EXPORT_NAME} + FILE ${PROJECT_CONFIG_FILE} +) + +# installed package config +install(EXPORT ${TARGETS_EXPORT_NAME} + DESTINATION ${CONFIG_INSTALL_DIR} + FILE ${PROJECT_CONFIG_FILE} +) + +# add to CMake registry +export(PACKAGE ${PROJECT_NAME}) + +#--------------------------------------------------------------------------------------- +# Create release packages +#--------------------------------------------------------------------------------------- + +# determine distribution and architecture +find_program(LSB_RELEASE lsb_release) +find_program(SYSCTL sysctl) +find_program(UNAME uname) + +if(UNAME) + execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) +elseif(SYSCTL) + execute_process(COMMAND sysctl -b hw.machine_arch OUTPUT_VARIABLE MACHINE_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) +else() + string(TOLOWER ${CMAKE_SYSTEM_NAME} MACHINE_ARCH) +endif() + +if(LSB_RELEASE) + execute_process(COMMAND lsb_release -si OUTPUT_VARIABLE LINUX_DISTRO OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND lsb_release -sc OUTPUT_VARIABLE LINUX_DISTRO_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND lsb_release -sr OUTPUT_VARIABLE LINUX_DISTRO_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(TOLOWER ${LINUX_DISTRO} LINUX_DISTRO) + if(LINUX_DISTRO_CODENAME STREQUAL "n/a") + set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_VERSION}/) + else() + set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_CODENAME}/) + endif() +else() + set(DISTRO_PACK_PATH ${CMAKE_SYSTEM_NAME}/) +endif() + +# make sure untagged versions get a different package name +execute_process(COMMAND git describe --exact-match --tags ERROR_QUIET RESULT_VARIABLE REPO_HAS_TAG) +if(REPO_HAS_TAG EQUAL 0) + set(PACKAGE_NAME_SUFFIX "") +else() + set(PACKAGE_NAME_SUFFIX "-git") + message(STATUS "Use -git suffix") +endif() + +# default CPack generators +set(CPACK_GENERATOR TGZ STGZ) + +# extra CPack generators +if(LINUX_DISTRO STREQUAL "debian" OR LINUX_DISTRO STREQUAL "ubuntu" OR LINUX_DISTRO STREQUAL "linuxmint") + list(APPEND CPACK_GENERATOR DEB) +elseif(LINUX_DISTRO STREQUAL "fedora" OR LINUX_DISTRO STREQUAL "opensuse" OR LINUX_DISTRO STREQUAL "centos") + list(APPEND CPACK_GENERATOR RPM) +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + list(APPEND CPACK_GENERATOR FREEBSD) +endif() + +set(LTM_DEBIAN_SHARED_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}") + +# general CPack config +set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH}) +message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}") +if(BUILD_SHARED_LIBS) + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}") + set(CPACK_DEBIAN_PACKAGE_NAME "${LTM_DEBIAN_SHARED_PACKAGE_NAME}") +else() + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel") + set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev") +endif() +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LibTomMath") +set(CPACK_PACKAGE_VENDOR "libtom projects") +set(CPACK_PACKAGE_CONTACT "libtom@googlegroups.com") +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") +set(PACKAGE_NAME_TRAILER ${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${MACHINE_ARCH}) +set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PACKAGE_NAME_TRAILER}) + +# deb specific CPack config +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) +set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION}) +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +if(BUILD_SHARED_LIBS) + set(CPACK_DEBIAN_PACKAGE_SECTION "libs") +else() + set(CPACK_DEBIAN_PACKAGE_SECTION "devel") + set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTM_DEBIAN_SHARED_PACKAGE_NAME}) + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) + set(CPACK_COMPONENTS_ALL Libraries) +endif() + +# rpm specific CPack config +set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION}) +set(CPACK_RPM_PACKAGE_ARCHITECTURE ${MACHINE_ARCH}) +set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}") +set(CPACK_RPM_PACKAGE_LICENSE "The Unlicense") + +# FreeBSD specific CPack config +set(CPACK_FREEBSD_PACKAGE_MAINTAINER "gahr@FreeBSD.org") +set(CPACK_FREEBSD_PACKAGE_ORIGIN "math/libtommath") +set(CPACK_FREEBSD_PACKAGE_CATEGORIES "math") + +include(CPack) diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 000000000..c44b7c23e --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: Unlicense +# +# LibTomMath, a free open source portable number theoretic multiple-precision +# integer (MPI) library written entirely in C. +# + +cmake_minimum_required(VERSION 3.10) + +set(LTM_TEST test-ltm) + +# This file can be included from the top level or used stand-alone +if(PROJECT_NAME) + set(LIBRARY_NAME ${PROJECT_NAME}) +else() + # Define an independent project and all the necessary stuff around + project(${LTM_TEST} + LANGUAGES C) + set(LIBRARY_NAME libtommath) + find_package(${LIBRARY_NAME}) + include(CTest) + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release") + endif() +endif() + +#----------------------------------------------------------------------------- +# Compose CFLAGS etc. +#----------------------------------------------------------------------------- + +if(NOT MSVC) + set(CMAKE_C_FLAGS_DEBUG "-g3 -O1") +endif() + +#----------------------------------------------------------------------------- +# demo target +#----------------------------------------------------------------------------- + +add_executable(${LTM_TEST} + ${CMAKE_CURRENT_SOURCE_DIR}/shared.c + ${CMAKE_CURRENT_SOURCE_DIR}/test.c +) + +target_include_directories(${LTM_TEST} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + $<$:${CMAKE_CURRENT_SOURCE_DIR}/..> +) + +target_link_libraries(${LTM_TEST} PRIVATE + ${LIBRARY_NAME} +) + +target_compile_options(${LTM_TEST} PRIVATE + $<$,SHARED_LIBRARY>:-DLTM_TEST_DYNAMIC> + ${LTM_C_FLAGS} +) +target_link_options(${LTM_TEST} BEFORE PUBLIC + ${LTM_LD_FLAGS} +) + +#----------------------------------------------------------------------------- +# CTest +#----------------------------------------------------------------------------- +add_test(NAME ${LTM_TEST} COMMAND ${LTM_TEST}) + +find_program(MEMORYCHECK_COMMAND valgrind) +set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full") diff --git a/helper.pl b/helper.pl index 9553f8788..6366d046b 100755 --- a/helper.pl +++ b/helper.pl @@ -222,11 +222,32 @@ sub patch_file { return $content; } +sub make_sources_cmake { + my ($src_ref, $hdr_ref) = @_; + my @sources = @{ $src_ref }; + my @headers = @{ $hdr_ref }; + my $output = "# SPDX-License-Identifier: Unlicense +# Autogenerated File! Do not edit. + +set(SOURCES\n"; + foreach my $sobj (sort @sources) { + $output .= $sobj . "\n"; + } + $output .= ")\n\nset(HEADERS\n"; + foreach my $hobj (sort @headers) { + $output .= $hobj . "\n"; + } + $output .= ")\n"; + return $output; +} + sub process_makefiles { my $write = shift; my $changed_count = 0; - my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } bsd_glob("*.c"); - my @all = bsd_glob("*.{c,h}"); + my @headers = bsd_glob("*.h"); + my @sources = bsd_glob("*.c"); + my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } @sources; + my @all = sort(@sources, @headers); my $var_o = prepare_variable("OBJECTS", @o); (my $var_obj = $var_o) =~ s/\.o\b/.obj/sg; @@ -245,10 +266,12 @@ sub process_makefiles { } # update OBJECTS + HEADERS in makefile* - for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw /) { + for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw sources.cmake /) { my $old = read_file($m); my $new = $m eq 'makefile.msvc' ? patch_file($old, $var_obj) - : patch_file($old, $var_o); + : $m eq 'sources.cmake' ? make_sources_cmake(\@sources, \@headers) + : patch_file($old, $var_o); + if ($old ne $new) { write_file($m, $new) if $write; warn "changed: $m\n"; diff --git a/sources.cmake b/sources.cmake new file mode 100644 index 000000000..a2df090a8 --- /dev/null +++ b/sources.cmake @@ -0,0 +1,167 @@ +# SPDX-License-Identifier: Unlicense +# Autogenerated File! Do not edit. + +set(SOURCES +bn_cutoffs.c +bn_deprecated.c +bn_mp_2expt.c +bn_mp_abs.c +bn_mp_add.c +bn_mp_add_d.c +bn_mp_addmod.c +bn_mp_and.c +bn_mp_clamp.c +bn_mp_clear.c +bn_mp_clear_multi.c +bn_mp_cmp.c +bn_mp_cmp_d.c +bn_mp_cmp_mag.c +bn_mp_cnt_lsb.c +bn_mp_complement.c +bn_mp_copy.c +bn_mp_count_bits.c +bn_mp_decr.c +bn_mp_div.c +bn_mp_div_2.c +bn_mp_div_2d.c +bn_mp_div_d.c +bn_mp_dr_is_modulus.c +bn_mp_dr_reduce.c +bn_mp_dr_setup.c +bn_mp_error_to_string.c +bn_mp_exch.c +bn_mp_expt_n.c +bn_mp_exptmod.c +bn_mp_exteuclid.c +bn_mp_fread.c +bn_mp_from_sbin.c +bn_mp_from_ubin.c +bn_mp_fwrite.c +bn_mp_gcd.c +bn_mp_get_double.c +bn_mp_get_i32.c +bn_mp_get_i64.c +bn_mp_get_l.c +bn_mp_get_mag_u32.c +bn_mp_get_mag_u64.c +bn_mp_get_mag_ul.c +bn_mp_grow.c +bn_mp_incr.c +bn_mp_init.c +bn_mp_init_copy.c +bn_mp_init_i32.c +bn_mp_init_i64.c +bn_mp_init_l.c +bn_mp_init_multi.c +bn_mp_init_set.c +bn_mp_init_size.c +bn_mp_init_u32.c +bn_mp_init_u64.c +bn_mp_init_ul.c +bn_mp_invmod.c +bn_mp_is_square.c +bn_mp_iseven.c +bn_mp_isodd.c +bn_mp_kronecker.c +bn_mp_lcm.c +bn_mp_log_n.c +bn_mp_lshd.c +bn_mp_mod.c +bn_mp_mod_2d.c +bn_mp_mod_d.c +bn_mp_montgomery_calc_normalization.c +bn_mp_montgomery_reduce.c +bn_mp_montgomery_setup.c +bn_mp_mul.c +bn_mp_mul_2.c +bn_mp_mul_2d.c +bn_mp_mul_d.c +bn_mp_mulmod.c +bn_mp_neg.c +bn_mp_or.c +bn_mp_pack.c +bn_mp_pack_count.c +bn_mp_prime_fermat.c +bn_mp_prime_frobenius_underwood.c +bn_mp_prime_is_prime.c +bn_mp_prime_miller_rabin.c +bn_mp_prime_next_prime.c +bn_mp_prime_rabin_miller_trials.c +bn_mp_prime_rand.c +bn_mp_prime_strong_lucas_selfridge.c +bn_mp_radix_size.c +bn_mp_radix_smap.c +bn_mp_rand.c +bn_mp_read_radix.c +bn_mp_reduce.c +bn_mp_reduce_2k.c +bn_mp_reduce_2k_l.c +bn_mp_reduce_2k_setup.c +bn_mp_reduce_2k_setup_l.c +bn_mp_reduce_is_2k.c +bn_mp_reduce_is_2k_l.c +bn_mp_reduce_setup.c +bn_mp_root_n.c +bn_mp_rshd.c +bn_mp_sbin_size.c +bn_mp_set.c +bn_mp_set_double.c +bn_mp_set_i32.c +bn_mp_set_i64.c +bn_mp_set_l.c +bn_mp_set_u32.c +bn_mp_set_u64.c +bn_mp_set_ul.c +bn_mp_shrink.c +bn_mp_signed_rsh.c +bn_mp_sqr.c +bn_mp_sqrmod.c +bn_mp_sqrt.c +bn_mp_sqrtmod_prime.c +bn_mp_sub.c +bn_mp_sub_d.c +bn_mp_submod.c +bn_mp_to_radix.c +bn_mp_to_sbin.c +bn_mp_to_ubin.c +bn_mp_ubin_size.c +bn_mp_unpack.c +bn_mp_xor.c +bn_mp_zero.c +bn_prime_tab.c +bn_s_mp_add.c +bn_s_mp_balance_mul.c +bn_s_mp_div_3.c +bn_s_mp_exptmod.c +bn_s_mp_exptmod_fast.c +bn_s_mp_get_bit.c +bn_s_mp_invmod_fast.c +bn_s_mp_invmod_slow.c +bn_s_mp_karatsuba_mul.c +bn_s_mp_karatsuba_sqr.c +bn_s_mp_log.c +bn_s_mp_log_2expt.c +bn_s_mp_log_d.c +bn_s_mp_montgomery_reduce_fast.c +bn_s_mp_mul_digs.c +bn_s_mp_mul_digs_fast.c +bn_s_mp_mul_high_digs.c +bn_s_mp_mul_high_digs_fast.c +bn_s_mp_prime_is_divisible.c +bn_s_mp_rand_jenkins.c +bn_s_mp_rand_platform.c +bn_s_mp_reverse.c +bn_s_mp_sqr.c +bn_s_mp_sqr_fast.c +bn_s_mp_sub.c +bn_s_mp_toom_mul.c +bn_s_mp_toom_sqr.c +) + +set(HEADERS +tommath.h +tommath_class.h +tommath_cutoffs.h +tommath_private.h +tommath_superclass.h +) From eaad123e5c385ebf34817cc5fde9564cf9aee550 Mon Sep 17 00:00:00 2001 From: Adrian Antonana Date: Mon, 9 Dec 2019 13:48:43 +0100 Subject: [PATCH 3/6] git: ignore cmake build directories (cherry picked from commit f993147b0ea0bdc6d80a3e043a7bdfd03f86f83e) --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d39d2758f..71250b883 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,7 @@ test_*.txt doc/pics/*.ps callgraph.txt + +# cmake build directories +build*/ + From c81b6b98e2bb0a3dc3583dbc92f9e6bfa7d157a6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 14 Mar 2024 09:36:10 +0100 Subject: [PATCH 4/6] Fix CI * there's no c89-c99 rountrip support on master * there's no proper symbol hiding on master * amalgamation works differently on master Signed-off-by: Steffen Jaeckel --- .github/workflows/main.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 24f881f3d..3f16d2699 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,12 +49,8 @@ jobs: # has only the options to that program: testme.sh config: - # Check c89 <-> c99 roundtrip - - { BUILDOPTIONS: '--c89-c99-roundtrip', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } # Check source code format - { BUILDOPTIONS: '--format', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'astyle' } - # Check public symbols of dynamic libraries - - { BUILDOPTIONS: '--symbols', SANITIZER: '', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'libtool-bin' } # Run always with valgrind (no sanitizer, but debug info) - { BUILDOPTIONS: '--with-cc=gcc --with-m64 --with-valgrind', SANITIZER: '', COMPILE_DEBUG: '1', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: '' } # Alternative big-int version of mp_log(_n) @@ -105,7 +101,6 @@ jobs: - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'relaxed', OTHERDEPS: 'clang-10 llvm-10' } - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } - { BUILDOPTIONS: '--with-cc=clang-10 --cflags=-DMP_USE_MEMOPS --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } - - { BUILDOPTIONS: '--with-cc=clang-10 --c89 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: 'strict', OTHERDEPS: 'clang-10 llvm-10' } - { BUILDOPTIONS: '--with-cc=clang-10 --with-m64 --limit-valgrind --cflags=-DMP_PREC=MP_MIN_PREC', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-10 llvm-10' } - { BUILDOPTIONS: '--with-cc=clang-12 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-12 llvm-12' } - { BUILDOPTIONS: '--with-cc=clang-9 --with-m64 --limit-valgrind', SANITIZER: '1', COMPILE_DEBUG: '0', COMPILE_LTO: '0', CONV_WARNINGS: '', OTHERDEPS: 'clang-9 llvm-9' } @@ -169,14 +164,6 @@ jobs: cat valgrind_test.log || true cat gcc_errors_*.log || true - amalgam: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: install dependencies - run: | - make amalgamated_timing - CMake: runs-on: ${{ matrix.os }} strategy: From d4a322d223b9103aaf0df065c2246a1bda416390 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 14 Mar 2024 09:52:22 +0100 Subject: [PATCH 5/6] Fixup ad5bb6230250ff1222451dc13cd80175dd145f00 Signed-off-by: Steffen Jaeckel --- bn_deprecated.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bn_deprecated.c b/bn_deprecated.c index f197a800e..477bc291d 100644 --- a/bn_deprecated.c +++ b/bn_deprecated.c @@ -203,7 +203,7 @@ MP_GET_MAG(mp_get_mag_ull, unsigned long long) MP_INIT_INT(mp_init_ll, mp_set_i64, long long) #endif #ifdef BN_MP_SET_LL_C -MP_SET_SIGNED(mp_set_ll, mp_set_i64, long long, unsigned long long) +MP_SET_SIGNED(mp_set_ll, mp_set_i64, long long, long long) #endif #ifdef BN_MP_INIT_ULL_C MP_INIT_INT(mp_init_ull, mp_set_u64, unsigned long long) @@ -226,7 +226,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) return MP_VAL; } e = mp_log_n(a, (int)base, &c_); - *c = c_; + *c = (uint32_t)c_; return e; } #endif From c81d0694f8be0c2e2dfe27b8b3829f00633c35b2 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 14 Mar 2024 10:00:28 +0100 Subject: [PATCH 6/6] Bump version [skip ci] Signed-off-by: Steffen Jaeckel --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4077189fa..90b07a832 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10) project(libtommath - VERSION 1.2.0 + VERSION 1.2.1 DESCRIPTION "A free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C." HOMEPAGE_URL "https://www.libtom.net/LibTomMath" LANGUAGES C)