Skip to content

feat!: Remove TOOLCHAIN logic and replace with CMake presets#162

Merged
codygunton merged 13 commits into
masterfrom
phated/toolchain-updates
Mar 2, 2023
Merged

feat!: Remove TOOLCHAIN logic and replace with CMake presets#162
codygunton merged 13 commits into
masterfrom
phated/toolchain-updates

Conversation

@phated

@phated phated commented Feb 17, 2023

Copy link
Copy Markdown

Description

Before these changes, Barretenberg was forcing specific C and C++ Compilers through the -DTOOLCHAIN variable. This is a flawed design because it doesn't allow consumers to set the CC or CXX environment variables to pick their compilers. Being able to set those values is extremely important for cross-compiling.

This PR removes all of that TOOLCHAIN logic and instead leverages CMake Presets to provide the defaults we expect (such as clang, clang-15, gcc, gcc-10 and clang from Homebrew). Shoutout to @adr1anh for sharing the idea for presets which massively helped with this transition plan.

It also updates the bootstrap.sh file to detect and print which preset should be used. If you use cmake commands directly, you'll need to start using the related preset commands.

I've also updated the dockerfiles and docs to all reference these preset commands.

The cmake/toolchains directory still exists, but the files have been re-done as proper CMake Cross-Compile Toolchain files which are really just supposed to set the target name and architecture, but can include extras like the i386 file.

I've tested this quite extensively on my Arm Mac but I need feedback for Linux, the dockerfiles, and the compare_honk_bench stuff (because it was non-standard).

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • There are no circuit changes, OR specifications in /markdown/specs have been updated.
  • There are no circuit changes, OR a cryptographer has been assigned for review.
  • I've updated any terraform that needs updating (e.g. environment variables) for deployment.
  • The branch has been rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.
  • New functions, classes, etc. have been documented according to the doxygen comment format. Classes and structs must have @brief describing the intended functionality.
  • If existing code has been modified, such documentation has been added or updated.

Comment thread README.md
Comment thread cpp/dockerfiles/Dockerfile.arm64-linux-gcc
Comment thread cpp/CMakePresets.json
@dbanks12

Copy link
Copy Markdown

Looks good to me. Just looking for clarification on a couple of things mentioned in my comments.

@charlielye charlielye left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skimmed. But looks like a great step in the right direction 👍

@adr1anh adr1anh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adr1anh

adr1anh commented Mar 2, 2023

Copy link
Copy Markdown

To address @codygunton's issue with GCC12, it seems like we can instead set the generator to Ninja in the CMakePresets.json rather than the VSCode workspace settings.

    {
      "name": "default",
      "displayName": "Build with Clang",
      "description": "Build with globally installed Clang",
      "binaryDir": "build",
      "generator": "Ninja",
      "environment": {
        "CC": "clang",
        "CXX": "clang++"
      }
    },

When testing on the mainframe, my build were being parallelized after performing this change.

On another note, switching configure preset requires the CMake cache to be rebuilt. The option is "CMake: Delete cache and reconfigure" in VSCode. This could be solved by having a separate build folder for each configuration, though that might be more annoying to setup. (i.e. build-gcc build-gcc, with build being the folder for the default configuration with clang.)

@adr1anh

adr1anh commented Mar 2, 2023

Copy link
Copy Markdown

I've added a commit which sets the generator in the default preset to Ninja. The second commit tells CMake to generate a compile_commands.json file that helps the clangd language server understand how the file being edited is compiled. It required an extra argument in the config to suppress a warning from a GCC-specific compile flag.

EDIT: I had to modify the docker files to download ninja as well.

@codygunton

Copy link
Copy Markdown

VS Code integration is still kind of funky, e.g. building with wasm preset using CMake Tools is extremely slow, but it works for most common workflow, so I'm going to merge.

@codygunton codygunton merged commit 09db0be into master Mar 2, 2023
@codygunton codygunton deleted the phated/toolchain-updates branch March 2, 2023 19:47
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 22, 2023
…otocol/barretenberg#162)

* feat: Add CMake presets to project

* fix!: Remove toolchain file and make bootstrap pick correct preset

* fix!: Rework toolchain files to be proper cross-compile files

* chore: Update dockerfiles to use presets

* chore: Rework compare_honk_bench to work with presets (need to double check)

* chore: Update docs to use presets throughout

* chore: Remove docs about parallel command since presets enable maximum jobs

* chore: Rework toolchain docs to call out cross-compiling

* Ignore CMakeUserPresets.json as per adrian

* Add CMake Tools VS Code plugin config.

* Set ninja as the default generator

* Export compile commands used for clangd
- add clangd setting to ignore GCC-specific flags

* add ninja to docker images

---------

Co-authored-by: codygunton <codygunton@gmail.com>
Co-authored-by: adr1anh <adrian.hamelink@gmail.com>
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 24, 2023
…otocol/barretenberg#162)

* feat: Add CMake presets to project

* fix!: Remove toolchain file and make bootstrap pick correct preset

* fix!: Rework toolchain files to be proper cross-compile files

* chore: Update dockerfiles to use presets

* chore: Rework compare_honk_bench to work with presets (need to double check)

* chore: Update docs to use presets throughout

* chore: Remove docs about parallel command since presets enable maximum jobs

* chore: Rework toolchain docs to call out cross-compiling

* Ignore CMakeUserPresets.json as per adrian

* Add CMake Tools VS Code plugin config.

* Set ninja as the default generator

* Export compile commands used for clangd
- add clangd setting to ignore GCC-specific flags

* add ninja to docker images

---------

Co-authored-by: codygunton <codygunton@gmail.com>
Co-authored-by: adr1anh <adrian.hamelink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants