Bazel IntelliJ plugin support

This eliminates the need for manually synchronizing generated files.

The plugin authors advise against checking in the .iwjb directory,
which we resolutely ignore. The recommended method is to provide a
template .bazelproject file that everyone needs to manually import and
update. However, checking in the directory is supported and no different
than checking in .idea. This allows us to version things like watchers
and run configurations, at the expense of requiring everyone to use
the same IntelliJ and Bazel plugin versions.

How it works:

- Source code and execroot paths are identical inside and outside the
  container. This requires a bind mount. To avoid conflicts with a
  local Bazel instance, a separate directory is used.

  The wrapper script injects a --output_user_root startup parameter.
  We cannot set this in .bazelrc since we cannot substitute the
  user home. This means that running bazel inside the container,
  without the wrapper, will no longer work/blow up the overlayfs.

  Did anyone do this?

- The tmpfs and other caches are eliminated.
  Forcing it hasn't been ideal anyway due to
  the excessive memory usage, and it can still be accomplished
  by mounting a tmpfs to `~/.cache/bazel-nxt` or symlinking it to
  `/dev/shm` or similar (set proper permissions!).

- The plugin configures a custom local repository that has helper
  scripts. Since we need to be on the same IntelliJ version, we can
  simply hardcode the path and bind mount it (read only).

  The alternative would be to copy the files into the container and
  override the command line option using sync_flags
  (https://github.com/bazelbuild/intellij/issues/397), but bind
  mounting seems muche easier at no disadvantage.

- IntelliJ needs a somewhat obscure custom startup option (see README)
  for BEP temp files (https://github.com/bazelbuild/intellij/issues/407).

Test Plan:
- Running tests works:

  {F16996}

- Full and partial sync works:

  {F17000}

- Updating a protobuf file triggered the watcher, which rebuilt the
  generated files. After triggering an source sync, the changes
  are visible in the IDE (I suspect that IntelliJ does not inotify-
  watch the generated files since they are outside the project directory.

X-Origin-Diff: phab/D263
GitOrigin-RevId: 39c50665575c2a0131c492385b0981b7ee2588d8
4 files changed
tree: d10f003ebe7fe9f75b4d22451a889dc91faebe88
  1. build/
  2. core/
  3. scripts/
  4. .bazelignore
  5. .bazelrc
  6. BUILD
  7. README.md
  8. WORKSPACE
README.md

Nexantic monorepo

This is the monorepo storing all of nexantic's internal projects and libraries.

Environment

We assume a Fedora 30 or 31 host system provisioned using rW, and IntelliJ as the IDE.

For better reproducibility, all builds are executed in containers.

Usage

Spinning up: scripts/create_container.sh

Spinning down: scripts/destroy_container.sh

Running commands: scripts/run_in_container.sh <...>

Using bazel using a wrapper script: scripts/bin/bazel <...> (add to your local $PATH for convenience)

IntelliJ

This repository is compatible with the IntelliJ Bazel plugin. All commands run inside the container, and necessary paths are mapped into the container.

We check the entire .ijwb project directory into the repository, which requires everyone to use the latest version of both IntelliJ and the Bazel plugin, but eliminates manual setup steps.

The following steps are necessary:

  • Install Google's official Bazel plugin in IntelliJ.

  • Add the absolute path to your ~/.cache/bazel-nxt folder to your idea64.vmoptions (Help → Edit Custom VM Options) and restart IntelliJ:

    -Dbazel.bep.path=/home/leopold/.cache/bazel-nxt

  • Set "Bazel Binary Location" in Other Settings → Bazel Settings to the absolute path of scripts/bin/bazel. This is a wrapper that will execute Bazel inside the container.

  • Open the .ijwb folder as IntelliJ project.

  • Disable Vgo support for the project.

  • Run a non-incremental sync in IntelliJ

The plugin will automatically resolve paths for generated files.

If you do not use IntelliJ, you need to use the scripts/bazel_copy_generated_for_ide.sh script to copy files locally.