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

Allow named debuginfo options in Cargo.toml #11958

Merged
merged 5 commits into from Apr 22, 2023

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 11, 2023

What does this PR try to resolve?

Rustc supports these since rust-lang/rust#109808. It's technically possible to set a named debuginfo level through RUSTFLAGS, but in practice cargo always passes its own opinion of what the debuginfo level is, so allow it to be configured through cargo too so the options don't conflict.

Note that this also adds support for "none", "limited", and "full" as aliases for 0, 1, and 2 respectively. The motivation is not just to match rustc, but also to make it easier for us to change the default for 1 over an edition to mean "line-tables-only" instead of "limited". If we allow limited as an alias for 1, people will be able to use it before and after the change in defaults to mean the same thing; if we disallow it and only allow it in the new edition, it will be impossible to have the same code work with both new and old versions of cargo.

How should we test and review this PR?

All modified tests are normal tests that can be run with cargo test. You can also build cargo from source and verify that CARGO_PROFILE_DEV_DEBUG=line-tables-only cargo build on a hello world project correctly passes -C debuginfo=line-tables-only through to rustc.

I recommend viewing this with whitespace changes hidden.

Additional information

Enabling these flags in cargo is required before bootstrap can start passing them through to rustc (which I'd like to do so we can reduce the size of the generated artifacts: rust-lang/rust#104968 (comment)).

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2023

r? @weihanglo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-console-output Area: Terminal output, colors, progress bar, etc. A-manifest Area: Cargo.toml issues A-profiles Area: profiles S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2023
tests/testsuite/unit_graph.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Muscraft Muscraft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

src/cargo/util/toml/mod.rs Outdated Show resolved Hide resolved
src/cargo/util/toml/mod.rs Outdated Show resolved Hide resolved
@Muscraft
Copy link
Contributor

This is slightly more lenient than it needs to be for that use-case; it will allow things like debug = "true" and debug = "1" that were disallowed before (treating them the same as debug = true and debug = 1 respectively). I can make cargo's parsing more restrictive here if you like.

I don't know anywhere (currently) that "true" is parsed to true and I am unsure if this is something that cargo should support.

Rustc supports these since rust-lang/rust#109808. It's technically
possible to set a named debuginfo level through `RUSTFLAGS`, but in
practice cargo always passes its own opinion of what the debuginfo level
is, so allow it to be configured through cargo too.
@jyn514
Copy link
Member Author

jyn514 commented Apr 11, 2023

Thanks for the feedback! I ended up redoing the main data structure from an arbitrary InternedString to an enum, which hopefully is both easier to read and avoids mistakes from doing string comparisons. I also changed the parsing to be more targeted and disallow "1" and "true".

Copy link
Contributor

@Muscraft Muscraft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docs for debug in profile?

Comment on lines +513 to +515
"none" => TomlDebugInfo::None,
"limited" => TomlDebugInfo::Limited,
"full" => TomlDebugInfo::Full,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this PR is about adding "line-tables-only" and "line-directives-only". If this PR is trying to get cargo to match rustc, do you mind updating the PR description with the rational for this

Copy link
Member Author

@jyn514 jyn514 Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR description. The main reason is that I want to change 1 to mean line-tables-only in the next edition.

Copy link
Member Author

@jyn514 jyn514 Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened an MCP for that change: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/2024.3A.20Decrease.20debuginfo.20generated.20by.20.20.60-.E2.80.A6.20compiler-team.23613. I think allowing these aliases won't be too much of a maintenance burden for cargo even if it ends up not happening, though.

src/cargo/util/toml/mod.rs Outdated Show resolved Hide resolved
src/cargo/core/profiles.rs Outdated Show resolved Hide resolved
@rustbot rustbot added the A-documenting-cargo-itself Area: Cargo's documentation label Apr 12, 2023
- Update the documentation and doc-comments
- Improve the error message for parsing Cargo.toml
@Muscraft
Copy link
Contributor

Muscraft commented Apr 14, 2023

Just a heads up, I will be bringing this up in the next Cargo team meeting because I am unsure of how stabilization will look.

If we were to put this behind a nightly flag, it would mean this is stable in rustc and unstable for cargo. If we make this insta-stable, we would have to live with the (minimal) Toml changes. No matter what, we will be at least a version behind rustc as this probably won't make it in the 1.70.0 merge window.

@Muscraft Muscraft added the I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting label Apr 14, 2023
@weihanglo weihanglo removed the I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting label Apr 18, 2023
@Muscraft
Copy link
Contributor

This was discussed in the recent Cargo team meeting, and there were no particular objections to instant stabilization since it is already stabilized in rustc. That being said, we would like a few more tests for the new options (nightly only for now) and to clarify the documentation, particularly so users have the context for deciding what value they should use.

@jyn514
Copy link
Member Author

jyn514 commented Apr 20, 2023

I've pushed some more tests.

@Muscraft can you clarify what you're looking for in the documentation? Right now this matches the documentation for rustc, is there something specific you're looking for?

If it helps, here's an example backtrace with each of the new options, compared to limited:

none (missing line numbers, missing frames)
; CARGO_PROFILE_RELEASE_DEBUG=none RUST_BACKTRACE=1 ${CARGO_TARGET_DIR}/debug/cargo run --release -q
thread 'main' panicked at 'explicit panic', src/main.rs:6:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:117:5
   3: example::foo
   4: example::main
line-directives-only (same as none)
; CARGO_PROFILE_RELEASE_DEBUG=line-directives-only RUST_BACKTRACE=1 ${CARGO_TARGET_DIR}/debug/cargo run --release -q
thread 'main' panicked at 'explicit panic', src/main.rs:6:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:117:5
   3: example::foo
   4: example::main
line-tables-only (missing module qualifiers for some functions)
; CARGO_PROFILE_RELEASE_DEBUG=line-tables-only RUST_BACKTRACE=1 ${CARGO_TARGET_DIR}/debug/cargo run --release -q
thread 'main' panicked at 'explicit panic', src/main.rs:6:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:117:5
   3: example::foo
             at ./src/main.rs:6:5
   4: bar
             at ./src/main.rs:11:9
   5: main
             at ./src/main.rs:2:5
   6: call_once<fn(), ()>
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/ops/function.rs:250:5
limited
; CARGO_PROFILE_RELEASE_DEBUG=limited RUST_BACKTRACE=1 ${CARGO_TARGET_DIR}/debug/cargo run --release -q
thread 'main' panicked at 'explicit panic', src/main.rs:6:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/panicking.rs:117:5
   3: example::foo
             at ./src/main.rs:6:5
   4: example::inner::bar
             at ./src/main.rs:11:9
   5: example::main
             at ./src/main.rs:2:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/7908a1d65496b88626e4b7c193c81d777005d6f3/library/core/src/ops/function.rs:250:5

but I'm not sure how to condense that into a short sentence. The backtraces at levels lower than limited also vary between debug and release mode: when optimizations are disabled line-tables-only behaves the same as limited and none has the same frames as limited but is missing the file/column info.

Copy link
Contributor

@Muscraft Muscraft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyn514 and I discussed this and concluded that Cargo's docs should be kept relatively simple and link to Rust's docs on debuginfo if more information is needed.

src/doc/src/reference/profiles.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Muscraft Muscraft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good!

@Muscraft
Copy link
Contributor

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 22, 2023

📌 Commit dbab134 has been approved by Muscraft

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2023
@bors
Copy link
Collaborator

bors commented Apr 22, 2023

⌛ Testing commit dbab134 with merge 77069b4...

@ehuss
Copy link
Contributor

ehuss commented Apr 22, 2023

Would it be possible to add some tests that actually use the new options? Since it isn't stable on rustc, yet, they will need to be marked with #[cargo_test(nightly, reason = "debug options stabilized in 1.70")].

@bors
Copy link
Collaborator

bors commented Apr 22, 2023

☀️ Test successful - checks-actions
Approved by: Muscraft
Pushing 77069b4 to master...

@bors bors merged commit 77069b4 into rust-lang:master Apr 22, 2023
17 checks passed
@jyn514 jyn514 deleted the named-debuginfo branch April 23, 2023 22:18
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 26, 2023
Update cargo

17 commits in de80432f04da61d98dcbbc1572598071718ccfd2..9e586fbd8b931494067144623b76c37d213b1ab6
2023-04-21 13:18:32 +0000 to 2023-04-25 22:09:11 +0000
- Update home dependency (rust-lang/cargo#12037)
- Warn instead of error in `cargo package` on empty `readme` or `license-file` in manifest (rust-lang/cargo#12036)
- Clarify documentation around test target setting. (rust-lang/cargo#12032)
- fix: apply `[env]` to target info discovery rustc (rust-lang/cargo#12029)
- CI: ensure intra links for all members are checked (rust-lang/cargo#12025)
- chore: make credential dependencies platform-specific (rust-lang/cargo#12027)
- CI: use `-p` to specify workspace members instead of `--manifest-path` (rust-lang/cargo#12024)
- ci: requires `test_gitoxide` and `lockfile` for both bors success and failure (rust-lang/cargo#12026)
- Update windows-sys (rust-lang/cargo#12021)
- Bump libc to 0.2.142 (rust-lang/cargo#12014)
- Update openssl-src to 111.25.3+1.1.1t (rust-lang/cargo#12005)
- Improve error message for empty dep (rust-lang/cargo#12001)
- Remove wrong url in benchsuite manifest. (rust-lang/cargo#12020)
- Bump versions of local crates (rust-lang/cargo#12019)
- Add the Win32_System_Console feature since it is used (rust-lang/cargo#12016)
- Update outdated crates.io URLs in publishing guide (rust-lang/cargo#12018)
- Allow named debuginfo options in Cargo.toml (rust-lang/cargo#11958)

r? `@ghost`
@ehuss ehuss added this to the 1.71.0 milestone May 5, 2023
bors added a commit that referenced this pull request May 24, 2023
Test that the new `debuginfo` options match between cargo and rustc

As requested in #11958 (comment).

r? `@ehuss`
bors added a commit that referenced this pull request Jul 19, 2023
Update docs for artifact JSON debuginfo levels.

String-based debuginfo levels were added in #11958, but the documentation wasn't updated to reflect that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-console-output Area: Terminal output, colors, progress bar, etc. A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants