From 4f4b01b56cd1e666f2499422b31941c193cf1c9f Mon Sep 17 00:00:00 2001 From: Peter McEvoy Date: Thu, 12 Jan 2023 13:57:44 -0500 Subject: [PATCH] Add support for optimized and debug builds (#103) Co-authored-by: Peter McEvoy (cherry picked from commit 90cc9ca05cc2d3547ea7a8ed83a6a6236e251392) --- .bazelrc | 9 ++++++--- INSTALL.md | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.bazelrc b/.bazelrc index badb362810..38426e3a63 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/INSTALL.md b/INSTALL.md index 940dfd45fe..a326aaa9ee 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -64,6 +64,15 @@ platform in the build command: $ bazel build --platforms=//: //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 @@ -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` @@ -91,5 +115,7 @@ pass `--clang_version=""` 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