From afaf8b9f95a54e4021318deb305c1a2aea1a839b Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Fri, 27 Nov 2026 16:51:37 -0500 Subject: [PATCH] Add Meson build system and CI workflows Signed-off-by: Jamie Snape --- .editorconfig | 7 +- .gitattributes | 3 + .github/workflows/actions.lock | 5 + .github/workflows/meson-format.yml | 96 ++++++ .github/workflows/meson.yml | 513 +++++++++++++++++++++++++++++ Brewfile | 1 + QUALITY_DECLARATION.md | 33 +- README.md | 1 + examples/meson.build | 60 ++++ meson.build | 182 ++++++++++ meson.options | 49 +++ src/BUILD.bazel | 59 +--- src/Export.h.in | 51 +++ src/meson.build | 129 ++++++++ 14 files changed, 1117 insertions(+), 72 deletions(-) create mode 100644 .github/workflows/meson-format.yml create mode 100644 .github/workflows/meson.yml create mode 100644 examples/meson.build create mode 100644 meson.build create mode 100644 meson.options create mode 100644 src/Export.h.in create mode 100644 src/meson.build diff --git a/.editorconfig b/.editorconfig index a1f924e..3dfb714 100644 --- a/.editorconfig +++ b/.editorconfig @@ -63,5 +63,8 @@ indent_size = 4 [Brewfile] indent_size = 4 -[dep5] -indent_size = 1 +[*.build] +indent_size = 4 + +[*.options] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes index 6a3e148..3fb201e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -43,6 +43,7 @@ * text=auto *.bazel text diff=python linguist-language=starlark whitespace-4 +*.build text diff=python linguist-language=meson whitespace-4 *.cc text diff=cpp linguist-language=c++ whitespace-2 *.cff text linguist-documentation whitespace-2 *.cfg text whitespace-2 @@ -50,12 +51,14 @@ *.cmake.in text whitespace-2 *.css text diff=css linguist-documentation whitespace=trailing-space *.h text diff=cpp linguist-language=c++ whitespace-2 +*.h.in text diff=cpp linguist-language=c++ whitespace-2 *.html text diff=html linguist-documentation whitespace=trailing-space *.imp text linguist-language=json whitespace-2 *.json text whitespace-2 *.license text linguist-documentation whitespace-0 *.lock text linguist-generated *.md text diff=markdown whitespace-md +*.options text diff=python linguist-language=meson whitespace-4 *.pc.in text whitespace-2 *.txt text *.xml text diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 9f7f7e4..20e2c86 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -31,6 +31,11 @@ workflows: - 'actions/checkout@v7.0.1' '.github/workflows/markdownlint.yml': - 'actions/checkout@v7.0.1' + '.github/workflows/meson-format.yml': + - 'actions/checkout@v7.0.1' + '.github/workflows/meson.yml': + - 'actions/cache@v6.1.0' + - 'actions/checkout@v7.0.1' '.github/workflows/reuse.yml': - 'actions/checkout@v7.0.1' - 'fsfe/reuse-action@v6.0.0' diff --git a/.github/workflows/meson-format.yml b/.github/workflows/meson-format.yml new file mode 100644 index 0000000..86aae3d --- /dev/null +++ b/.github/workflows/meson-format.yml @@ -0,0 +1,96 @@ +# +# meson-format.yml +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +--- +name: meson-format + +on: # yamllint disable-line rule:truthy + push: + branches: + - main + paths: + - '**/meson.build' + - '**/meson.options' + - meson.format + - .github/workflows/meson-format.yml + pull_request: + branches: + - main + paths: + - '**/meson.build' + - '**/meson.options' + - meson.format + - .github/workflows/meson-format.yml + schedule: + - cron: '55 7 * * *' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + meson-format: + name: meson-format + runs-on: ubuntu-latest + container: ubuntu:26.04 + timeout-minutes: 20 + steps: + - name: setup + run: | + apt-get -qq -o APT::Acquire::Retries=4 update \ + || (sleep 15; apt-get -qq -o APT::Acquire::Retries=4 update) + apt-get -qq -o APT::Acquire::Retries=4 -o Dpkg::Use-Pty=0 \ + upgrade + apt-get -qq -o APT::Acquire::Retries=4 -o Dpkg::Use-Pty=0 \ + --no-install-recommends install \ + ca-certificates \ + git \ + meson + apt-get -qq -o Dpkg::Use-Pty=0 autoremove + rm -rf /var/lib/apt/lists/* + env: + DEBIAN_FRONTEND: noninteractive + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: meson format + run: | + shopt -s globstar nullglob + meson format --check-diff -- **/meson.build **/meson.options + shell: bash diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml new file mode 100644 index 0000000..6dd0417 --- /dev/null +++ b/.github/workflows/meson.yml @@ -0,0 +1,513 @@ +# +# meson.yml +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +--- +name: meson + +on: # yamllint disable-line rule:truthy + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: '30 5 * * *' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + meson-almalinux: + name: meson almalinux amd64 + runs-on: ubuntu-latest + container: almalinux:10 + timeout-minutes: 30 + steps: + - name: setup + run: | + dnf makecache -q --refresh || (sleep 15; dnf makecache -q --refresh) + dnf install -q -y \ + ca-certificates \ + dnf-plugins-core \ + gcc-c++ \ + git \ + glibc-langpack-en \ + meson \ + ninja-build \ + pkgconf + dnf config-manager --set-enabled crb + dnf clean all + rm -rf /var/cache/yum + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-alpine: + name: meson alpine linux amd64 + runs-on: ubuntu-latest + container: alpine:3 + timeout-minutes: 30 + steps: + - name: setup + run: | + (apk add -q --no-cache \ + ca-certificates \ + g++ \ + git \ + meson \ + ninja \ + pkgconf) || (sleep 15; apk add -q --no-cache \ + ca-certificates \ + g++ \ + git \ + meson \ + ninja \ + pkgconf) + shell: sh + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: sh + + meson-arch: + name: meson arch linux amd64 + runs-on: ubuntu-latest + container: archlinux:latest + timeout-minutes: 30 + steps: + - name: setup + run: | + pacman --needed --noconfirm --noprogressbar -S -u -y \ + ca-certificates \ + gcc \ + git \ + meson \ + ninja \ + pkgconf + rm -rf \ + /var/cache/pacman/pkg/* \ + /var/lib/pacman/sync/* + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-fedora: + name: meson fedora linux amd64 + runs-on: ubuntu-latest + container: fedora:44 + timeout-minutes: 30 + steps: + - name: setup + run: | + dnf makecache -q --refresh || (sleep 15; dnf makecache -q --refresh) + dnf install -q -y \ + ca-certificates \ + gcc-c++ \ + git \ + glibc-langpack-en \ + meson \ + ninja-build \ + pkgconf + dnf clean all + rm -rf /var/cache/yum + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-macos: + name: meson macos arm64 + runs-on: macos-26 + timeout-minutes: 30 + steps: + - name: setup + run: | + brew update -q || (sleep 15; brew update -q) + brew install -q \ + git \ + meson \ + ninja + env: + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_NO_ANALYTICS: 1 + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + shell: zsh -efuo pipefail {0} + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=disabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: zsh -efuo pipefail {0} + + meson-opensuse: + name: meson opensuse leap amd64 + runs-on: ubuntu-latest + container: opensuse/leap:16.1 + timeout-minutes: 30 + steps: + - name: setup + run: | + zypper -n -q ref || (sleep 15; zypper -n -q ref) + zypper -n -q in --no-recommends \ + ca-certificates \ + gcc-c++ \ + git \ + meson \ + ninja \ + pkgconf + zypper -n -q cc -a + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-ubuntu: + name: meson ubuntu amd64 + runs-on: ubuntu-latest + container: ubuntu:26.04 + timeout-minutes: 30 + steps: + - name: setup + run: | + apt-get -qq -o APT::Acquire::Retries=4 update \ + || (sleep 15; apt-get -qq -o APT::Acquire::Retries=4 update) + apt-get -qq -o APT::Acquire::Retries=4 -o Dpkg::Use-Pty=0 \ + --no-install-recommends install \ + ca-certificates \ + g++ \ + git \ + meson \ + ninja-build \ + pkgconf + apt-get -qq -o Dpkg::Use-Pty=0 autoremove + rm -rf /var/lib/apt/lists/* + env: + DEBIAN_FRONTEND: noninteractive + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-ubuntu-arm64: + name: meson ubuntu arm64 + runs-on: ubuntu-26.04-arm + container: ubuntu:26.04 + timeout-minutes: 30 + steps: + - name: setup + run: | + apt-get -qq -o APT::Acquire::Retries=4 update \ + || (sleep 15; apt-get -qq -o APT::Acquire::Retries=4 update) + apt-get -qq -o APT::Acquire::Retries=4 -o Dpkg::Use-Pty=0 \ + --no-install-recommends install \ + ca-certificates \ + g++ \ + git \ + meson \ + ninja-build \ + pkgconf + apt-get -qq -o Dpkg::Use-Pty=0 autoremove + rm -rf /var/lib/apt/lists/* + env: + DEBIAN_FRONTEND: noninteractive + shell: bash + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + meson setup \ + --prefix "$(pwd)/_build/install" \ + -Db_lto=true \ + -Dopenmp=enabled \ + -Dwerror=true \ + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "$(pwd)" + meson dist --no-tests -C _build + shell: bash + + meson-windows: + name: meson windows x64 + runs-on: windows-latest + timeout-minutes: 30 + steps: + - name: cache + uses: actions/cache@v6.1.0 + with: + path: | + ~\AppData\Local\Microsoft\WinGet\Links + ~\AppData\Local\Microsoft\WinGet\SourceData + key: ${{ runner.os }}-${{ runner.arch }}-winget-${{ hashFiles('.github/workflows/*.yml') }} # yamllint disable-line rule:line-length + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-winget- + - name: setup + run: | + Install-Module -Force -Name Microsoft.WinGet.Client + Repair-WinGetPackageManager -Force -Latest + $package = Get-WinGetPackage -Id Git.Git ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id Git.Git ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id Git.Git ` + -MatchOption Equals -Mode Silent + } + $package = Get-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -Mode Silent + } + $package = Get-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -Mode Silent + } + Add-Content $env:GITHUB_PATH ( + [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + ` + [System.Environment]::GetEnvironmentVariable("Path", "User")) + shell: pwsh + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + $PSNativeCommandUseErrorActionPreference = $true + meson setup ` + --vsenv ` + --prefix "${PWD}/_build/install" ` + -Db_lto=true ` + -Ddefault_library=static ` + -Dopenmp=disabled ` + -Dwerror=true ` + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "${PWD}" + meson dist --no-tests -C _build + shell: pwsh + + meson-windows-arm64: + name: meson windows arm64 + runs-on: windows-11-arm + timeout-minutes: 30 + steps: + - name: cache + uses: actions/cache@v6.1.0 + with: + path: | + ~\AppData\Local\Microsoft\WinGet\Links + ~\AppData\Local\Microsoft\WinGet\SourceData + key: ${{ runner.os }}-${{ runner.arch }}-winget-${{ hashFiles('.github/workflows/*.yml') }} # yamllint disable-line rule:line-length + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-winget- + - name: setup + run: | + Install-Module -Force -Name Microsoft.WinGet.Client + Repair-WinGetPackageManager -Force -Latest + $package = Get-WinGetPackage -Id Git.Git ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id Git.Git ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id Git.Git ` + -MatchOption Equals -Mode Silent + } + $package = Get-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id mesonbuild.meson ` + -MatchOption Equals -Mode Silent + } + $package = Get-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -ErrorAction SilentlyContinue + if (-not $package) { + Install-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -Mode Silent + } elseif ($package.IsUpdateAvailable) { + Update-WinGetPackage -Id Ninja-build.Ninja ` + -MatchOption Equals -Mode Silent + } + Add-Content $env:GITHUB_PATH ( + [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + ` + [System.Environment]::GetEnvironmentVariable("Path", "User")) + shell: pwsh + - name: checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: build test package + run: | + $PSNativeCommandUseErrorActionPreference = $true + meson setup ` + --vsenv ` + --prefix "${PWD}/_build/install" ` + -Db_lto=true ` + -Ddefault_library=static ` + -Dopenmp=disabled ` + -Dwerror=true ` + _build + meson compile -C _build + meson test --print-errorlogs -C _build + meson install -C _build + git config --global --add safe.directory "${PWD}" + meson dist --no-tests -C _build + shell: pwsh diff --git a/Brewfile b/Brewfile index cfb0e0b..37ce979 100644 --- a/Brewfile +++ b/Brewfile @@ -49,6 +49,7 @@ brew 'jsonlint' brew 'lcov' brew 'llvm' brew 'markdownlint-cli' +brew 'meson' brew 'ninja' brew 'pkgconf', conflicts_with: ['pkg-config'] brew 'python' diff --git a/QUALITY_DECLARATION.md b/QUALITY_DECLARATION.md index 8ac3dfe..37ec3ce 100644 --- a/QUALITY_DECLARATION.md +++ b/QUALITY_DECLARATION.md @@ -68,8 +68,8 @@ requirement listed in the Package Requirements for Quality Level 2 in ### Version Scheme [1.i] `AVO2 Library` uses [Semantic Versioning 2.0.0](https://semver.org/), and is -at version `1.0.1`. The version is declared in `CMakeLists.txt` and -`MODULE.bazel`. +at version `1.0.1`. The version is declared in `CMakeLists.txt`, +`MODULE.bazel`, and `meson.build`. ### Version Stability [1.ii] @@ -147,6 +147,13 @@ and on a daily schedule: the Dockerfile with hadolint. - [`.github/workflows/markdownlint.yml`](.github/workflows/markdownlint.yml): lints Markdown files with markdownlint. +- [`.github/workflows/meson-format.yml`](.github/workflows/meson-format.yml): + enforces Meson file formatting with `meson format`. +- [`.github/workflows/meson.yml`](.github/workflows/meson.yml): builds and + tests with Meson on AlmaLinux, Alpine Linux, Arch Linux, Fedora, openSUSE, + Ubuntu (amd64 and arm64), macOS (arm64), and Windows (amd64 and + arm64). Meson builds enable LTO (`-Db_lto=true`), `openmp` (on Linux), and + `werror`. - [`.github/workflows/reuse.yml`](.github/workflows/reuse.yml): verifies REUSE license compliance. - [`.github/workflows/validate-cff.yml`](.github/workflows/validate-cff.yml): @@ -207,7 +214,7 @@ the project README. ### Feature Testing [4.i] A system-level simulation scenario forms the test suite, run via `ctest` -(CMake) and `bazel test` (Bazel): +(CMake), `bazel test` (Bazel), and `meson test` (Meson): - **Circle**: 250 agents initially distributed on a circle moving to their antipodal positions. @@ -277,16 +284,16 @@ None. `AVO2 Library` is built and tested continuously via GitHub Actions on the following platforms: -| Platform | Architecture | Build System | -|----------------|---------------|--------------| -| AlmaLinux | amd64 | CMake, Bazel | -| Alpine Linux | amd64 | CMake | -| Arch Linux | amd64 | CMake, Bazel | -| Fedora | amd64 | CMake, Bazel | -| openSUSE Leap | amd64 | CMake, Bazel | -| Ubuntu | amd64, arm64 | CMake, Bazel | -| macOS | arm64 | CMake, Bazel | -| Windows | amd64, arm64 | CMake, Bazel | +| Platform | Architecture | Build System | +|----------------|---------------|---------------------| +| AlmaLinux | amd64 | CMake, Bazel, Meson | +| Alpine Linux | amd64 | CMake, Meson | +| Arch Linux | amd64 | CMake, Bazel, Meson | +| Fedora | amd64 | CMake, Bazel, Meson | +| openSUSE Leap | amd64 | CMake, Bazel, Meson | +| Ubuntu | amd64, arm64 | CMake, Bazel, Meson | +| macOS | arm64 | CMake, Bazel, Meson | +| Windows | amd64, arm64 | CMake, Bazel, Meson | ## Security [7] diff --git a/README.md b/README.md index d571508..d82c8b5 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ environments with large numbers of robots and obstacles. ![Bazel](https://github.com/snape/AVO2/actions/workflows/bazel.yml/badge.svg?branch=main) ![CMake](https://github.com/snape/AVO2/actions/workflows/cmake.yml/badge.svg?branch=main) +![Meson](https://github.com/snape/AVO2/actions/workflows/meson.yml/badge.svg?branch=main) SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill diff --git a/examples/meson.build b/examples/meson.build new file mode 100644 index 0000000..b613335 --- /dev/null +++ b/examples/meson.build @@ -0,0 +1,60 @@ +# -*- mode: meson; -*- +# vi: set ft=meson: + +# +# examples/meson.build +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +examples_opt = get_option('examples') +if examples_opt.disabled() or (examples_opt.auto() and meson.is_subproject()) + subdir_done() +endif + +example_args = [ + '-DAVO_OUTPUT_TIME_AND_POSITIONS=0', +] + +exe = executable( + 'Circle', + sources: 'Circle.cc', + cpp_args: example_args, + dependencies: dep_avo, + install: false, +) + +test( + 'Circle', + exe, + is_parallel: false, + suite: 'examples', + timeout: 60, +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..47a83c4 --- /dev/null +++ b/meson.build @@ -0,0 +1,182 @@ +# -*- mode: meson; -*- +# vi: set ft=meson: + +# meson.build +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +project( + 'AVO', + 'cpp', + version: '1.0.1', + license: 'Apache-2.0', + license_files: ['LICENSE'], + default_options: [ + 'b_lto=false', + 'b_pie=true', + 'b_staticpic=true', + 'buildtype=release', + 'warning_level=1', + ], + meson_version: '>=1.1.0', +) + +cpp_compiler = meson.get_compiler('cpp') +host_os = host_machine.system() +is_msvc = cpp_compiler.get_id() == 'msvc' + +warning_flags = [] +if is_msvc + # Keep Meson's modest cross-platform warning baseline and raise only MSVC to + # /W4. Using warning_level=3 would also change GCC/Clang behavior. + warning_flags += cpp_compiler.get_supported_arguments('/W4') +else + if get_option('cpp_std') == 'none' + add_project_arguments( + cpp_compiler.get_supported_arguments('-std=c++98'), + language: 'cpp', + ) + endif + warning_flags += cpp_compiler.get_supported_arguments( + '-Wformat-security', + '-Werror=format-security', + ) +endif +add_project_arguments(warning_flags, language: 'cpp') + +hardening_compile_flags = [] +hardening_link_flags = [] +optimized_build = not get_option('debug') and get_option('optimization') != '0' + +if is_msvc + hardening_compile_flags += cpp_compiler.get_supported_arguments('/GS') + + if cpp_compiler.has_argument('/guard:cf') and cpp_compiler.has_link_argument( + '/DYNAMICBASE', + ) and cpp_compiler.has_link_argument( + '/GUARD:CF', + ) + hardening_compile_flags += ['/guard:cf'] + hardening_link_flags += ['/DYNAMICBASE', '/GUARD:CF'] + endif + + hardening_link_flags += cpp_compiler.get_supported_link_arguments( + '/NXCOMPAT', + ) +else + if optimized_build + hardening_compile_flags += cpp_compiler.get_supported_arguments( + '-D_FORTIFY_SOURCE=2', + ) + endif + + hardening_compile_flags += cpp_compiler.get_supported_arguments( + '-fcf-protection', + '-fno-common', + '-fstack-clash-protection', + ) + + if cpp_compiler.has_argument('-fstack-protector-strong') + hardening_compile_flags += ['-fstack-protector-strong'] + elif cpp_compiler.has_argument('-fstack-protector') + hardening_compile_flags += ['-fstack-protector'] + endif + + if optimized_build + hardening_link_flags += cpp_compiler.get_supported_link_arguments( + '-Wl,-Bsymbolic-functions', + ) + endif + + hardening_link_flags += cpp_compiler.get_supported_link_arguments( + '-Wl,-z,defs', + '-Wl,-z,noexecheap', + '-Wl,-z,noexecstack', + '-Wl,-z,now', + '-Wl,-z,relro', + '-Wl,-z,separate-code', + ) +endif + +add_project_arguments(hardening_compile_flags, language: 'cpp') +add_project_link_arguments(hardening_link_flags, language: 'cpp') + +if not is_msvc and cpp_compiler.has_link_argument('-Wl,--as-needed') + add_project_link_arguments('-Wl,--as-needed', language: 'cpp') +endif + +openmp_opt = get_option('openmp') +openmp_dep = dependency('openmp', required: openmp_opt, disabler: true) +openmp_deps = openmp_dep.found() ? [openmp_dep] : [] + +if host_os == 'windows' and get_option('default_library') == 'shared' + error( + 'On Windows, configure Meson with -Ddefault_library=static (or both) to match the project default.', + ) +endif + +examples_opt = get_option('examples') +examples_enabled = not ( + examples_opt.disabled() + or ( + examples_opt.auto() + and meson.is_subproject() + ) +) + +subdir('src') +subdir('examples') + +if not meson.is_subproject() + license_dir = get_option('licensedir') + if license_dir != '' + install_data( + 'LICENSE', + install_dir: license_dir / meson.project_name(), + install_tag: 'devel', + ) + endif +endif + +summary( + { + 'default_library': get_option('default_library'), + 'examples': examples_enabled, + 'hardening': ( + hardening_compile_flags.length() + hardening_link_flags.length() + ) > 0, + 'install': not meson.is_subproject(), + 'openmp': openmp_dep.found(), + 'subproject': meson.is_subproject(), + 'werror': get_option('werror'), + }, + section: 'Configuration', +) diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..ad20837 --- /dev/null +++ b/meson.options @@ -0,0 +1,49 @@ +# -*- mode: meson; -*- +# vi: set ft=meson: + +# +# meson.options +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +option( + 'examples', + type: 'feature', + value: 'auto', + description: 'Build example programs (default: enabled when top-level, disabled when a subproject)', +) + +option( + 'openmp', + type: 'feature', + value: 'disabled', + description: 'Enable OpenMP parallelization if available', +) diff --git a/src/BUILD.bazel b/src/BUILD.bazel index 62b37ac..1983593 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -42,67 +42,12 @@ package(default_package_metadata = [ "//:package_info", ]) -# REUSE-IgnoreStart genrule( name = "export", + srcs = ["Export.h.in"], outs = ["Export.h"], - cmd = """ -cat << 'EOF' > $@ -/* - * Export.h - * AVO2 Library - * - * SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Please send all bug reports to . - * - * The authors may be contacted via: - * - * Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha - * Dept. of Computer Science - * 201 S. Columbia St. - * Frederick P. Brooks, Jr. Computer Science Bldg. - * Chapel Hill, N.C. 27599-3175 - * United States of America - * - * - */ - -#ifndef AVO_EXPORT_H_ -#define AVO_EXPORT_H_ - -#ifdef AVO_STATIC_DEFINE -#define AVO_EXPORT -#else -#ifdef _WIN32 -#ifdef AVO_EXPORTS -#define AVO_EXPORT __declspec(dllexport) -#else -#define AVO_EXPORT __declspec(dllimport) -#endif -#else -#define AVO_EXPORT __attribute__((visibility("default"))) -#endif -#endif - -#endif // AVO_EXPORT_H_ -EOF -""", + cmd = "sed 's/@PREFIX@/AVO/g' $< > $@", ) -# REUSE-IgnoreEnd filegroup( name = "hdrs", diff --git a/src/Export.h.in b/src/Export.h.in new file mode 100644 index 0000000..1fafece --- /dev/null +++ b/src/Export.h.in @@ -0,0 +1,51 @@ +/* + * Export.h + * AVO2 Library + * + * SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Please send all bug reports to . + * + * The authors may be contacted via: + * + * Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha + * Dept. of Computer Science + * 201 S. Columbia St. + * Frederick P. Brooks, Jr. Computer Science Bldg. + * Chapel Hill, N.C. 27599-3175 + * United States of America + * + * + */ + +#ifndef @PREFIX@_EXPORT_H_ +#define @PREFIX@_EXPORT_H_ + +#ifdef @PREFIX@_STATIC_DEFINE +# define @PREFIX@_EXPORT +#else +# ifdef _WIN32 +# ifdef @PREFIX@_EXPORTS +# define @PREFIX@_EXPORT __declspec(dllexport) +# else +# define @PREFIX@_EXPORT __declspec(dllimport) +# endif +# else +# define @PREFIX@_EXPORT __attribute__((visibility("default"))) +# endif +#endif + +#endif /* @PREFIX@_EXPORT_H_ */ diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..0787e6f --- /dev/null +++ b/src/meson.build @@ -0,0 +1,129 @@ +# -*- mode: meson; -*- +# vi: set ft=meson: + +# src/meson.build +# AVO2 Library +# +# SPDX-FileCopyrightText: 2010 University of North Carolina at Chapel Hill +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Please send all bug reports to . +# +# The authors may be contacted via: +# +# Jur van den Berg, Jamie Snape, Stephen J. Guy, and Dinesh Manocha +# Dept. of Computer Science +# 201 S. Columbia St. +# Frederick P. Brooks, Jr. Computer Science Bldg. +# Chapel Hill, N.C. 27599-3175 +# United States of America +# +# +# + +sources = files( + 'Agent.cc', + 'KdTree.cc', + 'Line.cc', + 'Simulator.cc', + 'Vector2.cc', +) + +export_h = configure_file( + input: 'Export.h.in', + output: 'Export.h', + configuration: {'PREFIX': 'AVO'}, +) + +public_headers = files( + 'AVO.h', + 'Line.h', + 'Simulator.h', + 'Vector2.h', +) + +inc = include_directories('.') + +compile_args = [] +dep_compile_args = [] +default_library = get_option('default_library') + +# Keep inline-visibility tightening on the library target only: this is part of +# the exported ABI/symbol policy for AVO itself, not a project-wide policy that +# needs to affect example executables. +compile_args += cpp_compiler.get_supported_arguments( + '-fvisibility-inlines-hidden', +) + +if host_os == 'windows' + compile_args += ['-DNOMINMAX'] + dep_compile_args += ['-DNOMINMAX'] + + if default_library in ['shared', 'both'] + compile_args += ['-DAVO_EXPORTS'] + if default_library == 'both' + dep_compile_args += ['-DAVO_STATIC_DEFINE'] + endif + else + compile_args += ['-DAVO_STATIC_DEFINE'] + dep_compile_args += ['-DAVO_STATIC_DEFINE'] + endif +else + if default_library == 'static' + compile_args += ['-DAVO_STATIC_DEFINE'] + dep_compile_args += ['-DAVO_STATIC_DEFINE'] + endif +endif + +lib_avo = library( + 'AVO', + sources: sources, + include_directories: inc, + cpp_args: compile_args, + gnu_symbol_visibility: 'hidden', + dependencies: openmp_deps, + version: meson.project_version(), + soversion: meson.project_version().split('.')[0], + install: not meson.is_subproject(), +) + +dep_avo = declare_dependency( + link_with: lib_avo, + include_directories: inc, + compile_args: dep_compile_args, + dependencies: openmp_deps, +) + +meson.override_dependency('AVO', dep_avo) + +if not meson.is_subproject() + install_headers( + public_headers, + export_h, + subdir: 'AVO', + ) + + pkgconfig = import('pkgconfig') + pkgconfig.generate( + lib_avo, + name: 'AVO', + description: 'Reciprocal Collision Avoidance with Acceleration-Velocity Obstacles', + url: 'https://gamma.cs.unc.edu/AVO/', + version: meson.project_version(), + filebase: 'AVO', + subdirs: 'AVO', + extra_cflags: dep_compile_args, + ) +endif