From 7156d217b2eeacfbcb77a1c9d5ac5746efa95a46 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 16 Jan 2024 13:48:36 -0500 Subject: [PATCH] build!: replace `configure.py` with a sample INI file --- .github/workflows/ci.yml | 22 +++-- .gitignore | 9 +- configure.py | 106 --------------------- doc/setup.md | 84 ++++++++++------- doc/troubleshooting.md | 6 +- examples/README.md | 4 +- meson/build-iguana.ini | 53 +++++++++++ meson/resolve-dependencies.py | 118 ++++++++++++++++++++++++ src/iguana/algorithms/example/README.md | 4 +- 9 files changed, 243 insertions(+), 163 deletions(-) delete mode 100755 configure.py create mode 100644 meson/build-iguana.ini create mode 100755 meson/resolve-dependencies.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57095676b..619b5246d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,8 +86,8 @@ jobs: matrix: binding: [ cpp, python ] include: - - { binding: cpp, configure_opts: '' } - - { binding: python, configure_opts: '--python' } + - { binding: cpp, extra_build_opts: '' } + - { binding: python, extra_build_opts: '-Dpython=True' } steps: ### setup - uses: actions/checkout@v4 @@ -125,10 +125,20 @@ jobs: if: ${{ inputs.runner == 'macos-latest' }} - run: tree ### build iguana - - name: configure - run: ./configure.py --hipo hipo --fmt fmt --examples --no-documentation ${{ matrix.configure_opts }} - - name: build - run: ./install-iguana.sh + - name: meson setup + run: | + meson setup \ + $(meson/resolve-dependencies.py --cli --hipo hipo --fmt fmt) \ + -Dbuildtype release \ + -Dprefix $(pwd)/iguana \ + -Dexamples True \ + -Ddocumentation False \ + ${{ matrix.extra_build_opts }} \ + build + - name: dump build options + run: meson configure build | cat + - run: meson compile -C build + - run: meson install -C build ### dump info about this build - name: dump build log if: always() diff --git a/.gitignore b/.gitignore index f96637794..32fc63eda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,9 @@ -# build artifacts -*.ini -install-iguana.sh +# common build artifacts +/*.ini /build*/ /iguana /install*/ -# local dependency builds -/fmt -/hipo - # doxygen artifacts /doc/api diff --git a/configure.py b/configure.py deleted file mode 100755 index b45f15b49..000000000 --- a/configure.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 - -from configparser import ConfigParser -import argparse, os, sys, textwrap, subprocess - -# constants -SYSTEM_ASSUMPTION = 'assume system installation' -SEPARATOR = '-'*50 -PKGCONFIG_RELOCATABLE = True -LIBDIR = 'lib' - -# parse user options -class Formatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter): pass -parser = argparse.ArgumentParser( - usage = f'{sys.argv[0]} [OPTION]...', - description = textwrap.dedent(''' - description: - Generate a configuration file with build settings for iguana - '''), - formatter_class = Formatter -) -parser_deps = parser.add_argument_group('dependency installation paths') -parser_deps.add_argument( '--hipo', default=SYSTEM_ASSUMPTION, type=str, help='path to `hipo` installation') -parser_deps.add_argument( '--fmt', default=SYSTEM_ASSUMPTION, type=str, help='path to `fmt` installation') -parser_build = parser.add_argument_group('build settings') -parser_build.add_argument( '--prefix', default='iguana', type=str, help='iguana installation prefix') -parser_build.add_argument( '--debug', default=False, action=argparse.BooleanOptionalAction, help='enable debugging symbols or not; optimization level is 0 if this is used, otherwise it is 3 (see also --buildtype)') -parser_build.add_argument( '--examples', default=False, action=argparse.BooleanOptionalAction, help='build examples or not') -parser_build.add_argument( '--documentation', default=False, action=argparse.BooleanOptionalAction, help='generate API documentation or not') -parser_build = parser.add_argument_group('bindings') -parser_build.add_argument( '--python', default=False, action=argparse.BooleanOptionalAction, help='generate Python bindings or not') -parser_build = parser.add_argument_group('advanced settings') -parser_build.add_argument( '--build', default='build-iguana', type=str, help='iguana buildsystem directory') -parser_build.add_argument( '--ini', default='build-iguana.ini', type=str, help='name of the output config INI file') -parser_build.add_argument( '--buildtype', default='release', type=str, help='specify meson built-in option `buildtype`') -args = parser.parse_args() - -# get prefix and source absolute paths -installDir = os.path.realpath(args.prefix) -sourceDir = os.path.dirname(os.path.realpath(__file__)) - -# set dependency paths -cmake_prefix_path = set() -cmake_deps = set() -pkg_config_path = set() -pkg_config_deps = set() -if(args.hipo != SYSTEM_ASSUMPTION): - pkg_config_path.add(os.path.realpath(args.hipo) + '/lib/pkgconfig') - pkg_config_deps.add('hipo') -if(args.fmt != SYSTEM_ASSUMPTION): - pkg_config_path.add(os.path.realpath(args.fmt) + '/lib/pkgconfig') - pkg_config_deps.add('fmt') - -# set the buildtype -buildtype = 'debug' if args.debug else args.buildtype - -# return an array of strings for meson's INI parsing -def meson_string_array(arr): - contents = ','.join(map(lambda s: f'\'{s}\'', arr)) - return f'[{contents}]' - -# generate the INI file -config = ConfigParser(allow_no_value=True) -config.add_section('built-in options') -if(len(cmake_prefix_path) > 0): - config.set('built-in options', '; path to dependencies: ' + ','.join(cmake_deps)) - config.set('built-in options', 'cmake_prefix_path', meson_string_array(cmake_prefix_path)) -if(len(pkg_config_path) > 0): - config.set('built-in options', '; path to dependencies: ' + ','.join(pkg_config_deps)) - config.set('built-in options', 'pkg_config_path', meson_string_array(pkg_config_path)) -config.set('built-in options', '; constant settings (do not edit)') -config.set('built-in options', 'libdir', f'\'{LIBDIR}\'') # make all systems use LIBDIR -config.set('built-in options', 'pkgconfig.relocatable', f'{PKGCONFIG_RELOCATABLE}') -config.set('built-in options', '; build settings') -config.set('built-in options', 'prefix', f'\'{installDir}\'') -config.set('built-in options', 'buildtype', f'\'{buildtype}\'') -config.set('built-in options', 'examples', f'{args.examples}') -config.set('built-in options', 'documentation', f'{args.documentation}') -config.set('built-in options', '; bindings') -config.set('built-in options', 'bind_python', f'{args.python}') - -# write the INI file -with open(args.ini, 'w') as fp: - config.write(fp) -print(f'Wrote build configuration file {args.ini}:') -print(SEPARATOR) -with open(args.ini, 'r') as fp: - print(fp.read()) -print(SEPARATOR) - -# generate the installation script -installScript = 'install-iguana.sh' -with open(installScript, 'w') as fp: - fp.write(textwrap.dedent(f'''\ - #!/bin/bash - set -e - meson setup --native-file {args.ini} {args.build} {sourceDir} - meson install -C {args.build} - ''')) -os.chmod(installScript, 0o744) -print(f''' -Generated installation script {installScript} -To proceed with iguana installation, run: - - ./{installScript} -''') diff --git a/doc/setup.md b/doc/setup.md index 70ca261ca..c7da4f0ce 100644 --- a/doc/setup.md +++ b/doc/setup.md @@ -22,7 +22,7 @@ The following sections list the dependencies and how to obtain them. > git checkout 1.0.0 # checkout the tag '1.0.0' > ``` -### :large_orange_diamond: `meson`: Build system used by `iguana` +### :large_orange_diamond: `meson`: Build system used by Iguana - Likely available in your package manager, but the latest version is preferred and may be installed with `pip`: ```bash @@ -49,58 +49,74 @@ cmake --install build-hipo ## Building and Installing -- For convenience, a configuration script is provided. -- Advanced users who want more control may skip to the "Using Meson Directly" section. +Iguana uses [`meson`](https://mesonbuild.com/) as its build system. From here, +we'll assume that you are in a working directory, which may be any directory. +- it does not have to be your analysis working directory, since we are only +_building_ Iguana at this time +- you may also just use the top-level source code directory (`.`) -### :large_blue_diamond: Using the Configuration Script +We'll also assume the Iguana source code directory (this repository) is found at +``` +/path/to/iguana +``` -First, configure your `iguana` build using `configure.py`: +### Set build options +It's recommended to create an INI file to set the build options that you want +to use. Copy the example INI file [`meson/build-iguana.ini`](meson/build-iguana.ini) to +your working directory: ```bash -./configure.py --help +cp /path/to/iguana/meson/build-iguana.ini ./my-iguana.ini # you may choose any file name ``` -The `--help` option will print the usage guide. -Unless the dependencies are installed in one of the system default locations, you will need to specify the path to each of them, _e.g._, +Then edit it, setting your preferred options; in particular, you'll need to set +the dependency resolution options. Use [`meson/resolve-dependencies.py`](meson/resolve-dependencies.py) +to help you: ```bash -./configure.py --hipo /path/to/hipo_installation --fmt /path/to/fmt_installation +/path/to/iguana/meson/resolve-dependencies.py --help # prints the usage guide ``` -This will generate a configuration file (`build-iguana.ini`, by default) with the build settings, along with an installation script (`install-iguana.sh`). -Inspect both of them, and if they look correct, proceed with building and installing `iguana` by running: +See the [note on dependency resolution](dependency_resolution.md) for more guidance. + +### Configure your build +Next, start an Iguana build directory; let's call it `build-iguana` (you may choose any name): ```bash -./install-iguana.sh +meson setup --native-file my-iguana.ini build-iguana /path/to/iguana ``` > [!TIP] -> You may edit the configuration file (`build-iguana.ini`, by default) to -> change any settings, and rebuild `iguana` with `./install-iguana.sh`. -> - this procedure is preferred if you just want to change some settings -> - re-running `configure.py` will _overwrite_ your configuration file - -> [!TIP] -> If you have trouble and want to try a clean build, wipe your build directory (`build-iguana/`, by default). The safest -> way to do this is: +> If you _already_ have an Iguana build directory, and you have just changed options in your INI file, add the `--reconfigure` option. +> Alternatively, run > ```bash -> meson setup --wipe build-iguana +> meson configure build-iguana -D