How to configure .bazelrc with platform

There are certain needs to configure the .bazelrc file with platform tags like build:macos. You can simply add OS-specific configurations with --enable_platform_specific_config1 like below.

build --enable_platform_specific_config

# for macOS-specific configurations
build:macos --action_env=CC
...

# for linux-specific configurations
build:linux --action_env=CXX
...

Also, you can find the exact platform names by OS in these lines (ConfigExpander.java#L38-L53).

  private static String getPlatformName() {
    switch (OS.getCurrent()) {
      case LINUX:
        return "linux";
      case DARWIN:
        return "macos";
      case WINDOWS:
        return "windows";
      case FREEBSD:
        return "freebsd";
      case OPENBSD:
        return "openbsd";
      default:
        return OS.getCurrent().getCanonicalName();
    }
  }
December 13, 2021
Tags: bazel