Skip to content

Commit

Permalink
Add support for optimized and debug builds (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter McEvoy <[email protected]>
(cherry picked from commit 90cc9ca)
  • Loading branch information
Peter McEvoy authored and mcevoypeter committed Jan 12, 2023
1 parent b60871c commit 4f4b01b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ build --incompatible_enable_cc_toolchain_resolution
build --@io_bazel_rules_docker//transitions:enable=false

# Add aliases for compiler version build settings.
build --flag_alias=aarch64_linux_gnu_gcc_version=//:aarch64_linux_gnu_gcc_version
build --flag_alias=clang_version=//:clang_version
build --flag_alias=gcc_version=//:gcc_version

# Add alias for Docker image tag.
build --flag_alias=image_tag=//:image_tag
# Always include source-level debug info.
build --copt='-g'
build --strip=never

# Use -O3 as the default optimization level.
build --copt='-O3'

# Any personal configuration should go in .user.bazelrc.
try-import %workspace%/.user.bazelrc
26 changes: 26 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ platform in the build command:
$ bazel build --platforms=//:<target-platform> //pkg/...
```

The default optimization level is `-O3`, but if you want to specify a different
optimization level, use [`--copt`][copt]:
```console
$ bazel build --copt='-O0' :urbit
```

Note [`--copt`][copt] can be used to specify any C compiler options, not just
optimization levels.

## Test Commands

You can build and run unit tests only on native builds. If you have a native
Expand All @@ -78,6 +87,21 @@ If you want to run a specific test, say
$ bazel test //pkg/noun:hashtable_tests
```

## Build Configuration File

Any options you specify at the command line can instead be specified in
`.user.bazelrc` if you find yourself using the same options over and over. This
file is not tracked by `git`, so whatever you add to it will not affect anyone
else. As an example, if you want to change the optimization level but don't want
type `--copt='-O0'` each time, you can do the following:
```console
$ echo "build --copt='-O0'" >> .user.bazelrc
$ bazel build :urbit
```

For more information on Bazel configuration files, consult the
[Bazel docs][bazel-config].

## Common Issues

If `bazel build` or `bazel test` generates an `undeclared inclusion(s) in rule`
Expand All @@ -91,5 +115,7 @@ pass `--clang_version="<version_string>"` to the failing command.
`BUILD.bazel` files in [`pkg/`](pkg).

[bazel]: https://bazel.build
[bazel-config]: https://bazel.build/run/bazelrc
[copt]: https://bazel.build/docs/user-manual#copt
[glibc]: https://www.gnu.org/software/libc
[musl libc]: https://musl.libc.org

0 comments on commit 4f4b01b

Please sign in to comment.