diff --git a/.github/workflows/on-release.yml b/.github/workflows/on-release.yml new file mode 100644 index 0000000..efaa63f --- /dev/null +++ b/.github/workflows/on-release.yml @@ -0,0 +1,43 @@ +name: On Release + +# By default, a workflow only has read permissions. +# Add the needed permission to write release assets +permissions: + contents: write + +on: + release: + types: + - published + +jobs: + build: + name: Add Release Assets + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Amalgamate single-file poolstl.hpp + run: ./create_amalgamates.sh + working-directory: tools + + - name: Upload poolstl.hpp + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./tools/poolstl.hpp + asset_name: poolstl.hpp + asset_content_type: text/plain + +# - name: Upload poolstl_nopool.hpp +# uses: actions/upload-release-asset@v1 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# with: +# upload_url: ${{ github.event.release.upload_url }} +# asset_path: ./tools/poolstl_nopool.hpp +# asset_name: poolstl_nopool.hpp +# asset_content_type: text/plain diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bc76576..bf0fd08 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,7 @@ jobs: description: "GCC 7" gcc-version: "7" cmake-version: "3.18" + test-amalgamation: true - os: ubuntu-latest description: "GCC 13" @@ -83,6 +84,22 @@ jobs: ./poolstl_bench || ./Release/poolstl_bench.exe shell: bash + - name: Test Amalgamation + if: matrix.test-amalgamation + run: | + cd tools/ + ./create_amalgamates.sh + cd .. + rm -rf include/poolstl/* + cp tools/poolstl.hpp include/poolstl/ + mkdir -p include/poolstl/internal + cp tools/poolstl.hpp include/poolstl/internal/utils.hpp + cmake -S . -B build/ -DCMAKE_BUILD_TYPE=Debug -DPOOLSTL_TEST=ON -DPOOLSTL_TEST_COVERAGE=OFF + cmake --build build/ --config Debug + cd build/tests + ctest -C Debug --output-on-failure --verbose + shell: bash + - name: Upload Coverage to Codecov if: contains(matrix.os, 'ubuntu') uses: codecov/codecov-action@v3 diff --git a/README.md b/README.md index aa0ef62..2c5937d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ Note: All iterators must be random access. ## Installation +### Single File + +You may download a single-file amalgamated `poolstl.hpp` from the [latest Release](https://github.com/alugowski/poolSTL/releases) and simply copy into your project. + ### CMake ```cmake diff --git a/tools/amalgamate.py b/tools/amalgamate.py new file mode 100644 index 0000000..4ff142b --- /dev/null +++ b/tools/amalgamate.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +""" +Amalgamate multiple header files into one. +""" +import argparse +from pathlib import Path +import sys + + +def parse_args(): + parser = argparse.ArgumentParser() + + parser.add_argument("root", type=Path, + help="Root header file.") + + parser.add_argument("-o", "--output", type=Path, default=None, nargs='?', + help="Path to write output to.") + + parser.add_argument("-H", "--header", type=Path, default=None, nargs='?', + help="Header to use instead of the one in the root file.") + + parser.add_argument("-e", "--exclude", type=Path, default=[], nargs='*', action='extend', + help="Include files to pretend are already included.") + + return parser.parse_args() + + +seen_includes = set() + + +def process_file(out, path: Path, drop_header=False): + in_header = True + base = path.parent + out.write("\n") + with path.open("r") as infile: + for line in infile.readlines(): + if in_header and drop_header: + if line.startswith("#"): + in_header = False + else: + continue + + if line.startswith("#include"): + _, inc = line.split() + incpath = base / inc[1:-1] + + if incpath in seen_includes: + continue + + seen_includes.add(incpath) + + if inc.startswith('"'): + process_file(out, incpath, drop_header=True) + continue + + out.write(line) + + +def main(): + args = parse_args() + + for e in args.exclude: + seen_includes.add(e) + + out = sys.stdout if not args.output else args.output.open("w") + + if args.header: + out.write(args.header.read_text()) + + process_file(out, args.root, drop_header=bool(args.header)) + + +if __name__ == '__main__': + main() diff --git a/tools/amalgamate_header.hpp b/tools/amalgamate_header.hpp new file mode 100644 index 0000000..032eaf5 --- /dev/null +++ b/tools/amalgamate_header.hpp @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: BSD-2-Clause OR MIT OR BSL-1.0 +/** + * @brief Thread pool-based implementation of parallel standard library algorithms. Single-file version. + * @see https://github.com/alugowski/poolSTL + * @author Adam Lugowski + * @copyright Copyright (C) 2023 Adam Lugowski. + * Licensed under any of the following open-source licenses: + * BSD-2-Clause license, MIT license, Boost Software License 1.0 + * + * + * BSD-2-Clause license: + * + * Copyright (C) 2023 Adam Lugowski + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + * MIT License: + * + * Copyright (c) 2023 Adam Lugowski + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * + * + * Boost Software License 1.0: + * + * Permission is hereby granted, free of charge, to any person or organization + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to use, reproduce, display, distribute, execute, + * and transmit the Software, and to prepare derivative works of the Software, + * and to permit third-parties to whom the Software is furnished to do so, + * all subject to the following: + * + * The copyright notices in the Software and this entire statement, including + * the above license grant, this restriction and the following disclaimer, must + * be included in all copies of the Software, in whole or in part, and all + * derivative works of the Software, unless such copies or derivative works + * are solely in the form of machine-executable object code generated by a + * source language processor. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ diff --git a/tools/create_amalgamates.sh b/tools/create_amalgamates.sh new file mode 100755 index 0000000..58d9ca3 --- /dev/null +++ b/tools/create_amalgamates.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +python amalgamate.py ../include/poolstl/poolstl.hpp --header amalgamate_header.hpp -o poolstl.hpp + +# create a version that excludes the thread pool +python amalgamate.py ../include/poolstl/poolstl.hpp --header amalgamate_header.hpp -o poolstl_nopool.hpp -e ../include/poolstl/internal/task_thread_pool.hpp +