> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Presets for bazelrc

> Discover how Bazel presets can help configure sensible default options, improve efficiency, and avoid common bugs in new repositories.

export const BlogPost = ({title, date, authors, tags, image, children}) => {
  const tagList = tags ? tags.split(", ").filter(Boolean) : [];
  const tagSlug = t => t.toLowerCase().replace(/&/g, "").replace(/\+/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
  const formattedDate = date ? new Date(date + "T00:00:00").toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric"
  }) : "";
  return <section className="w-full flex justify-center px-4 py-12 md:py-16">
      <div style={{
    maxWidth: "800px",
    width: "100%"
  }}>
        {image && (typeof image === "string" ? <img noZoom src={image} alt={title} className="w-full rounded-xl mb-8" style={{
    maxHeight: "400px",
    objectFit: "cover"
  }} /> : <div className="blog-post-hero-image">{image}</div>)}
        <h1 className="text-3xl md:text-4xl font-bold text-zinc-900 dark:text-white">
          {title}
        </h1>
        <div className="flex flex-wrap items-center gap-3 mt-4 text-sm text-zinc-500 dark:text-zinc-400">
          {authors && <span>{authors}</span>}
          {authors && formattedDate && <span>·</span>}
          {formattedDate && <span>{formattedDate}</span>}
        </div>
        {tagList.length > 0 && <div className="flex flex-wrap gap-2 mt-3">
            {tagList.map(tag => <a key={tag} href={"/blog/tags/" + tagSlug(tag)} className="px-2 py-0.5 rounded-full text-xs bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 hover:bg-blue-100 dark:hover:bg-blue-900/40 hover:text-blue-700 dark:hover:text-blue-300 transition">
                {tag}
              </a>)}
          </div>}
        <hr className="my-8 border-zinc-200 dark:border-zinc-700" />
        <div className="prose dark:prose-invert max-w-none">{children}</div>
      </div>
    </section>;
};

export const MarketingPage = () => <div className="marketing-page-marker" style={{
  display: "none"
}} />;

export const Section = ({children, className = "", gray = false, dark = false, id}) => <section id={id} className={`w-full flex justify-center px-4 py-16 md:py-24 ${gray ? "bg-gray-50 dark:bg-zinc-900" : dark ? "bg-zinc-900 dark:bg-zinc-950" : ""} ${className}`}>
    <div className="w-full" style={{
  maxWidth: "1140px"
}}>
      {children}
    </div>
  </section>;

<BlogPost title="Presets for bazelrc" date="2023-02-27" authors="Alex Eagle" tags="Bazel, Aspect CLI">
  <img noZoom src="https://mintcdn.com/aspectbuild/x1L7Iep716jCyJVo/images/blog/hashnode/hn-d0f296e46e.jpeg?fit=max&auto=format&n=x1L7Iep716jCyJVo&q=85&s=0326b7bdf1127ce560fab3311664806c" alt="" className="blog-post-cover" width="1600" height="1020" data-path="images/blog/hashnode/hn-d0f296e46e.jpeg" />

  Bazel has a TON of options - over 1500 of them! \[1] It has so many obscure options that even experts like myself are often surprised to learn about a new one.

  Many of the options have the wrong default value for new repositories. This means new users re-experience some bug only to find that they just never "enabled the bugfix".

  There's now an easy way for users to avoid learning about so many flags and get more sensible values by default: presets.

  ### What is a preset?

  A preset is just a named `.bazelrc` file with a collection of flags set, and a bunch of comments explaining the behavior change and links to documentation or issues filed.

  An example preset entry looks like

  ```python theme={null}
  # Allow exclusive tests to run in the sandbox. Fixes a bug where Bazel doesn't enable sandboxing for
  # tests with `tags=["exclusive"]`.
  # Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed
  test --incompatible_exclusive_test_sandboxed
  ```

  We group them into preset files. The flag above appears in `correctness.bazelrc` .

  ### Using presets

  If you don't have a dependency on bazel-lib yet, add it. This module provides a ton of carefully curated starlark libraries, rules, and other utilities that are helpful across languages. Install instructions appear on each release: [https://github.com/aspect-build/bazel-lib/releases](https://github.com/aspect-build/bazel-lib/releases)

  Next, copy the presets into your repository. The easiest way to do this is with our macro:

  ```python theme={null}
  load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")

  write_aspect_bazelrc_presets(name = "update_aspect_bazelrc_presets")
  ```

  This creates a test target checking that the copies are up-to-date, so as you upgrade bazel-lib, it will print a `bazel run` command to update your copy. Since the presets can't be guaranteed to work with every Bazel setup, it's important for you to code review the changes. This is why the presets get copied to your source repo.

  Finally, update the `/.bazelrc` file in your repo to import the presets you use. Add an `import` statement like

  ```python theme={null}
  import %workspace%/.aspect/bazelrc/correctness.bazelrc

  <MarketingPage />
  ```

  Complete documentation and the contents of the preset files are all on [https://github.com/bazel-contrib/bazelrc-presets](https://github.com/bazel-contrib/bazelrc-presets).

  ### Improving the presets

  The presets live in an Apache 2 licensed open-source repo: [https://github.com/aspect-build/bazel-lib/tree/main/.aspect/bazelrc](https://github.com/aspect-build/bazel-lib/tree/main/.aspect/bazelrc) where the community can suggest more improvements. Bazel is always adding flags, so we expect this to grow over time.

  ### Why not fix the wrong defaults?

  We have been working on this! The rules authors SIG has put up bug bounties asking for community help to flip some Bazel flags: [https://github.com/bazel-contrib/SIG-rules-authors/issues?q=is%3Aissue+is%3Aopen+label%3Abounty-1000USD](https://github.com/bazel-contrib/SIG-rules-authors/issues?q=is%3Aissue+is%3Aopen+label%3Abounty-1000USD)

  However, so far only one volunteer has stepped up to work on flipping one of them.

  \[1] `bazel% git checkout 6.0.0; find . -name '\*.java' -type f -exec fgrep "@Option(" {} ; | wc -l  ` -> 1537
</BlogPost>
