Skip to content

Setting up CLion on MacOS for Authservice development

Ryan Richard edited this page Jun 9, 2020 · 14 revisions

Update March 25, 2020: The new MacOS command line tools v11.4 that just recently came out cannot compile the version of Boost that Authservice uses. As a workaround, you can download and install Command_Line_Tools_for_Xcode_11.3.1.dmg from the Apple Developer web site.

You can see which version of the command line tools you have installed using pkgutil --pkg-info=com.apple.pkg.CLTools_Executables. E.g.:

% pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 11.3.1.0.1.1576735732
volume: /
location: /
install-time: 1591727491
groups: com.apple.FindSystemFiles.pkg-group

Setup Instructions

First install CLion and Bazel.

  1. Install CLion, e.g. brew cask install clion.
  2. Install the same version of bazel that we use for Authservice compilation. See here for latest version.
    pushd /tmp
      BAZEL_VERSION=0.29.1
      curl -LO https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh
      chmod +x bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh
      ./bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh
      bazel --version
    popd
    

To finish setting up CLion:

  1. Launch Clion
  2. Answer all of the first-time prompts
  3. When you get to the "Welcome to CLion" dialog box, pull down the Configure menu and choose Preferences.
  4. In the Preferences dialog box, search for "plugins".
  5. Install the Bazel plugin.
  6. Quit CLion.
  7. Start CLion.
  8. On the Welcome to CLion dialog box, choose Import Bazel Project.
  9. For the workspace, choose /Users/pivotal/workspace/authservice
  10. For the Select Project View, choose Create from Scratch
  11. For the project data directory, again choose the directory where you cloned the repo, e.g. /Users/pivotal/workspace/authservice For the project name, enter authservice For infer name from, choose the Workspace radio button
  12. As a workaround for a an issue for handling dynamic linking on MacOS, follow these directions. Please be careful to not commit and push that workaround, as it causes linux builds to fail. Hopefully we can find a better way to handle this in the future so that no workaround is required.
  13. If the project sync fails complaining that the bazel command does not exist, then open the CLion Preferences and choose Bazel Settings. Change the Bazel Binary Location to /usr/local/bin/bazel, then click Save.
  14. Click the Sync Project button to re-run Bazel.
  15. If CLion did not auto-detect that this project uses git for source control, then open the CLion Preferences, click on Version Control, click the '+' button, click on the Project radio button, choose git, click OK, click OK.
  16. Add some commonly used run configurations:
    1. Click "Add Configuration..." on the toolbar.
    2. Click '+' and choose Bazel Command.
    3. Name: Build and Run All Tests
    4. Target expression: //test/...
    5. Bazel command: test
    6. Bazel flags:
      --incompatible_depset_is_not_iterable=false
      --verbose_failures
      --strategy=TestRunner=standalone
      --test_output=all
      
    7. Click Apply
    8. Click '+' and choose Bazel Command.
    9. Name: Build All Prod Code
    10. Target expression: //src/...
    11. Bazel command: build
    12. Bazel flags:
      --incompatible_depset_is_not_iterable=false
      --verbose_failures
      
    13. Click OK
  17. Run both of the new targets that you just created to compile and run tests
  18. Adjust the auto-format settings to conform to the project's preferred settings. Open the CLion Preferences dialog, unfold Editor, unfold Code Style, choose C/C++, switch the Scheme to "Project", click on "Set from..." and choose "Google". Note that you must quit and restart CLion for this change to take effect, even though CLion will not tell you that.
  19. Optional: If you are using git-duet with rubymine-git-wrapper, then open the CLion Preferences dialog box, unfold Version Control, choose Git, change the Path to Git executable to be the path to the executable, e.g. /usr/local/bin/rubymine-git-wrapper. This will enable making commits in the CLion UI using the appropriate git-duet settings.

Note: The first time that you run unit tests in CLion, a dialog box will appear that says "Please update 'Google Test' past ba96d0b...". This has already been done, so you can ignore this warning.