Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolchain: Add config settings for debug info and opt level #1925

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ted-logan
Copy link
Contributor

Add two build flags:

  • //rust/settings:opt_level
  • //rust/settings:debug_info

Each of these flags takes a string list that allows the rustc
optimization level (--codegen=opt-level=x) and debug info
(--codegen=debuginfo=x) to be changed.

If either flag has one value, it will be used for all three compilation
modes (dbg, fastbuild, opt). If the flag has three values (separated by
commas) each value will be used in sequence for dbg, fastbuild, and opt.

Note that if one is changing the opt-level, one should consider changing
debug-assertions (via a separate extra rustc flag). By default, in
rustc, debug-assertions are enabled only if opt-level is 0.

Add tests to verify that the expected codegen flags are provided on the
rustc command line.

… level

Check that the rustc command line includes the expected codegen
arguments for debug info (`--codegen=debuginfo=x`) and opt level
(`--codegen=opt-level=x`), depending on the command-line flag specifying
compilation mode.
Add two build flags:

- //rust/settings:opt_level
- //rust/settings:debug_info

Each of these flags takes a string list that allows the rustc
optimization level (`--codegen=opt-level=x`) and debug info
(`--codegen=debuginfo=x`) to be changed.

If either flag has one value, it will be used for all three compilation
modes (dbg, fastbuild, opt). If the flag has three values (separated by
commas) each value will be used in sequence for dbg, fastbuild, and opt.

Note that if one is changing the opt-level, one should consider changing
debug-assertions (via a separate extra rustc flag). By default, in
rustc, debug-assertions are enabled only if opt-level is 0.

Add tests to verify that the expected codegen flags are provided on the
rustc command line.
@ted-logan ted-logan force-pushed the dev/tedlogan/rustc-debug-info-opt-level branch from e9e7cf4 to 5f90b9a Compare April 18, 2023 20:25
@scentini
Copy link
Collaborator

Could this PR be replaced by a
.bazelrc

build:opt -Copt-level=X
build:opt -Cdebuginfo=Y

build:dbg -Copt-level=X
build:dbg -Copt-level=Y

...

?

This PR seems to tie in to wanting easier way to customize flags, which was requested in #515. I would rather look at a more general mechanism than individual flags.

@UebelAndre
Copy link
Collaborator

Could this PR be replaced by a .bazelrc

build:opt -Copt-level=X
build:opt -Cdebuginfo=Y

build:dbg -Copt-level=X
build:dbg -Copt-level=Y

...

?

This PR seems to tie in to wanting easier way to customize flags, which was requested in #515. I would rather look at a more general mechanism than individual flags.

Is build:dbg and build:opt automatically picked up with the --compilation_mode flag? Or follow transitions? It'd be pretty sweet if it did!

@scentini
Copy link
Collaborator

Not really; but the other way around works, eg one could have a --config=opt and put build:opt -c opt. As for following transitions - there is no difference whether --@rules_rust//rust:extra_rustc_flags=-Copt-level=X is set on the command line or via the .bazelrc with build:opt --@rules_rust//rust:extra_rustc_flags=-Copt-level=X.

@ted-logan
Copy link
Contributor Author

I can use --@rules_rust//:extra_rustc_flags= to add flags to the rustc command line, but they get appended at the end of argv and don't replace the --codegen=opt-level=x added by rust/private/rustc.bzl. I don't see clear documentation from rustc about how it handles multiple instances of the same argument with different values.

This does seem to work in practice, so I'll probably use it instead, though it's still undocumented so it feels like undefined behavior in the complier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants